#!/bin/sh
# buildpage -- small markdown wrapper with frontmatter
support
set -e
die() {
echo "$*" 1>&2
exit 1
}
[ -z "$1" ] && die "usage: buildpage FILE"
# Print the header
cat <
"
# Print the title, if we find it in the frontmatter
if [ "$(head -n1 "$1")" = "---" ]; then
title="$(tail +2 "$1" | sed '/^---$/q' | grep '^title:' | sed 's/title: *//')"
nofooter="$(tail +2 "$1" | sed '/^---$/q' | grep '^nofooter:' | sed 's/nofooter: *//')"
[ -n "$title" ] && printf "$title\n"
start=$(awk '/^---$/ { c++; if (c == 2) { printf "%d\n", NR + 1; exit } }' "$1")
else
start=1
fi
printf "\n\n"
# Render the markdown starting from the end of the frontmatter!
tail +$start "$1" | cmark --unsafe
# Print a nav footer
if [ -z "$nofooter" ]; then
cat <
EOM
else
printf "