static-pandoc-template/spt

32 lines
833 B
Text
Raw Normal View History

2013-04-15 14:58:52 +00:00
#!/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}
2013-04-15 15:29:56 +00:00
boil="$curdir/boilerplate.html"
tmpboil="$curdir/tmp.html"
2013-04-15 14:58:52 +00:00
{
echo "% ${fic:r}"
echo "% Yann Esposito"
echo "% $(date +'%d %h %Y')"
cat $fic
} > $tmp
2013-04-15 15:29:56 +00:00
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
2013-04-15 14:58:52 +00:00
done