#!/bin/bash
rootDir='./tmp/'
targetDir='post/'
post() {
tmp=".swap"
base=$(basename $1)
# Glue all the things
pandoc $1 | cat 'templates/post-header.html' - 'templates/post-footer.html' >> $tmp
sed -i "5i
${base%.*}" $tmp
sed -i "s///g' $tmp
# turn the header into an actual header
sed -i '30i ' $tmp
# finally move this post to its proper location in the _rootDir
mv $tmp "$rootDir/$targetDir/${base%.*}.html"
rm -f $tmp
}
[[ -z $rootDir/post/ ]] && mkdir -p $rootDir/post
# root and style page cases where we don't want to do anything else
case $1 in
"s")
cp style.css $rootDir
cp style.css $rootDir/$targetDir
exit 0
;;
"r")
echo 'Building the root pages'
targetDir=''
post './prebuild/about.md'
post './prebuild/links.md'
post './prebuild/index.md'
exit 0
;;
esac
for file in $@;do
post $file
done
if [ -z $@ ]
then
while read line
do
post $line
done < "${1:-/dev/stdin}"
fi