dot

packages and services management
Log | Files | Refs | README

commit 7e6eaad4562a0a134a57db79bd08674b77b88360
parent fc25501e35d77e4e77f457621e9da9114f68f96f
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Mon, 29 May 2017 22:32:27 +0200

www is back

Diffstat:
Abin/www | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+), 0 deletions(-)

diff --git a/bin/www b/bin/www @@ -0,0 +1,51 @@ +# static website generator + + +LAYOUT=$(cat layout.html) || exit 1 +ROOT=$PWD + + +#1 content of the layout to parse + +parse() +{ + # print the input up to the next keyword, and shift position in input + printf %s "${1%%{{*}" + + # check for remaining keywords + [ "${1##*{{*}" ] && return 0 + + # take the separator out of the keyword + set -- "${1#*{{}" + + # execute the keyword action and print its output + case "${1%%\}\}*}" in + ( *content* ) printf %s "$(sed 1d index.txt)" ;; + ( *title* ) printf %s "$(sed 1q index.txt)" ;; + ( *root* ) printf %s "$(root )" ;; + ( *nav* ) printf %s "$(nav )" ;; + esac + + parse "${1#*\}\}}" +} + + +root() +{ + printf '%s\n' "${PWD#$ROOT}" | + sed 's|[^/]||g; s|.|../|g; s|/$||; s|^$|.|' +} + + +nav() +{ + find . -mindepth 2 -maxdepth 2 -name index.txt | sort | + while IFS='' read -r path + do printf '<a href="%s">%s</a>\n' "${path%.txt}.html" "$(sed 1q "$path")" + done +} + + +find . -name 'index.txt' | sort | while IFS='' read -r file +do (cd "${file%/*}" && (parse "$LAYOUT" > index.html)) +done