You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

31 lines
833 B

#!/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