Skip to content

Instantly share code, notes, and snippets.

@rascul
Created January 26, 2015 20:18
Show Gist options
  • Save rascul/74c1a9f167d380baa639 to your computer and use it in GitHub Desktop.
Save rascul/74c1a9f167d380baa639 to your computer and use it in GitHub Desktop.
Simple static site generator
#!/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