#!/bin/sh
set -euo pipefail
usage() {
echo 'Usage: html [ -H | -F ] FILENAME.htmlbody'
}
HEADER_ONLY=false
FOOTER_ONLY=false
while getopts 'HF' flag; do
case "$flag" in
(H)
HEADER_ONLY=true
;;
(F)
FOOTER_ONLY=true
;;
(*)
usage >&2
exit 2
;;
esac
done
shift $((OPTIND - 1))
FILENAME="${1:-}"
eval "$(assert-arg -- "$FILENAME" 'FILENAME.htmlbody')"
. ./"${FILENAME%.*}.conf"
dates() {
if [ -z "$date_formatted" ]; then
return
fi
cat <
Posted on
EOF
if [ -n "$updatedat_formatted" ]; then
cat <
Updated on
EOF
fi
cat <
EOF
}
h1() {
if [ "${custombody:-}" = true ]; then
return
fi
cat <
$title_html
EOF
}
comments() {
if [ "${custombody:-}" = true ]; then
return
fi
cat <
EOF
}
head_meta_author_html=
if [ -n "${author:-}" ]; then
head_meta_author_html=" "
fi
publickey_html=
if [ -n "${publickey:-}" ] && [ -n "${publickey_url:-}" ]; then
publickey_html="$(cat <
$publickey
EOF
)"
fi
headlinks() {
echo ' '
cat "$header_links" | grep -v '^#' | grep . | while read -r line; do
link="$(printf '%s\n' "$line" | cut -d' ' -f1)"
name="$(printf '%s\n' "$line" | cut -d' ' -f2)"
cat <
$name
EOF
done
echo '
'
}
collection_head_prev_html=
collection_head_post_html=
header() {
cat <
$head_meta_author_html
$collection_head_prev_html
$collection_head_post_html
$titlefull_html
EOF
h1
dates
}
body() {
cat "${FILENAME%.*}.htmlbody"
}
footer() {
comments
cat <
EOF
}
if [ "$HEADER_ONLY" = true ]; then
header
exit
fi
if [ "$FOOTER_ONLY" = true ]; then
footer
exit
fi
header
body
footer