docz/doc.sh

31 lines
738 B
Bash
Executable File

#!/bin/sh
dir="$(dirname "$(readlink -e "$0")")"
if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: doc.sh <template> <input file>"
exit 0
elif [ "$1" = "-l" ] || [ "$1" = "--list-templates" ]; then
find "$dir" -name "*.template.html" | sed -e "s!$dir/!!g" -e "s!.template.html!!g" | sort
exit 0
fi
template="$1"
input="$2"
output="$3"
if [ "$output" = "" ]; then
output=$(echo "$input" | rev | cut -d"." -f2- | rev)
output="$output.pdf"
fi
title=$(grep -m 1 "^# " "$input" | sed "s/^# //g")
pandoc --standalone\
-f gfm\
--pdf-engine weasyprint\
--metadata "title=$title"\
--template="$dir/$template.template.html"\
-o "$output"\
"$input"