#!/bin/bash -e # PPages static site generator - requiring: fd-find, rsync # * Template files look like $type.template.html # * Markdown files look like $name.$type.md # Using 'bang' template v # e.g. foo/_bar/baz/whizz.bang.md -> www/foo/baz/whizz.html # ^ ^ ^ # _* dirs are gone suffix gone output dir added # # * The contents of the _static/ directory are copied to www/ # * Set $HOST=me@server.xyz:/srv/www to rsync to that location # * Set $WWW=path/to/output to override the default output directory # * Pass an argument to only build paths matching that regex # WWW="${WWW:-www}" pp () { local p while read -r L;do case $L in !!*)p="$p"$'\n'"${L#!!}";;*)eval "$p";p="";echo "$L";;esac;done;eval "$p" } get_output () { sed "s!^!$WWW/!;s!/_[^/]*/!/!g;s!\.[^./]*\.[^./]*\$!.html!" <<< "$1" } build () { for template in $(fd . -e template.html); do type="$(sed 's!^.*/!!;s!\..*$!!' <<< "$template")" echo "Template '$type':" >&2 for page in $(fd -p "${1:-.}" -e "$type.md"); do echo " - processing $page" >&2 out="$(get_output "$page")" [[ "$out" -nt "$page" && "$out" -nt "$template" && "$out" -nt "$(dirname "$page")" ]] && continue mkdir -p "$(dirname "$out")" PAGE="$page" pp < "$template" > "$out" & done done } [[ $HOST ]] && rm -rf "$WWW" build "$1" rsync -aOci _static/ "$WWW"/ | sed 's!^! - static !' >&2 wait echo "rsync -aOci $WWW/ \$HOST" | if [[ $HOST ]]; then bash -; else cat; fi