#!/usr/bin/env zsh (($#<1)) && print -- "usage: ${0:t} fic [fic ...]" curdir=$HOME/Sites/static-pandoc-template [[ ! -d static-pandoc ]] && mkdir static-pandoc [[ -w static-pandoc ]] && cp -r $curdir/*(/) static-pandoc for fic in $*; do dst="static-pandoc/${fic:r}.html" tmp=${fic:r}.$$.${fic:e} boil="$curdir/boilerplate.html" tmpboil="$curdir/tmp.html" { echo "% ${fic:r}" echo "% Yann Esposito" echo "% $(date +'%d %h %Y')" cat $fic } > $tmp if [[ ${fic:h} != '.' ]]; then reldir=$(print -- ${fic:h} |sed 's#[^/]*#..#g') else reldir='.' fi perl -pe 's#\$webprefix\$#'$reldir'#g' < $boil > $tmpboil [[ ! -d ${dst:h} ]] && mkdir -p ${dst:h} pandoc -s -S --template $tmpboil $tmp > $dst print $dst \rm -f $tmp $tmpboil done