Created
January 26, 2015 20:18
-
-
Save rascul/74c1a9f167d380baa639 to your computer and use it in GitHub Desktop.
Simple static site generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
start_stamp=$(date +%s) | |
file_count=0 | |
skeldir="${PWD}/skel" | |
function generate { | |
infile="$1" | |
outfile="$2" | |
cat "${skeldir}/head.html" "$f" "${skeldir}/tail.html" > "$outfile" | |
} | |
function readdir { | |
local dir=${PWD##*/} | |
for f in *; do | |
if [[ -d "$f" ]] && [[ "$f" != "skel" ]]; then | |
cd "$f" | |
readdir | |
cd .. | |
elif [[ -f "$f" ]] && [[ "${f: -2:2}" = "in" ]]; then | |
export file_count=$((file_count+1)) | |
outfile="${f:0: -3}.html" | |
echo "${dir}" | |
if [[ "${f:0: -3}" = "$dir" ]]; then | |
outfile="index.html" | |
echo "outfile: $outfile" | |
fi | |
generate "$f" "$outfile" | |
fi | |
done | |
} | |
readdir | |
stop_stamp=$(date +%s) | |
echo "Generated ${file_count} files in $(( stop_stamp - start_stamp )) seconds." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment