#!/bin/bash
rootDir='./tmp/'
targetDir=''
[[ -z $rootDir/post/ ]] && mkdir -p $rootDir/post
post() {
# First get the body of the document
tmp=".swap"
base=$(basename $1)
# cat the files together
pandoc $1 | cat 'templates/post-header.html' - 'templates/post-footer.html' >> $tmp
sed -i "5i
${base%.*}" $tmp
sed -i "s///g' $tmp
# finally move this post to its proper location in the _rootDir
mv $tmp "$rootDir/$targetDir/${base%.*}.html"
rm -f $tmp
}
if [[ $1 == "r" ]]
then
targetDir=''
shift
else
targetDir='post/'
fi
for file in $@;do
post $file
done
if [ -z $@ ]
then
while read line
do
post $line
done < "${1:-/dev/stdin}"
fi