diff options
author | EuAndreh <eu@euandre.org> | 2024-11-14 13:33:55 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-11-15 20:19:20 -0300 |
commit | 873fc8c1eb41857a0043e48a7f011b62cc54b4cd (patch) | |
tree | 9ca1d13a22bf3e5ae5920a7bf26f4a2c2ea45a32 | |
parent | src/feed: Accept a combined conf file instead of 2 (diff) | |
download | mkwb-873fc8c1eb41857a0043e48a7f011b62cc54b4cd.tar.gz mkwb-873fc8c1eb41857a0043e48a7f011b62cc54b4cd.tar.xz |
src/html: Support emitting only header or footer
-rwxr-xr-x | src/html | 57 |
1 files changed, 50 insertions, 7 deletions
@@ -3,9 +3,29 @@ set -euo pipefail usage() { - echo 'Usage: html FILENAME.htmlbody' + 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')" . "$(realpath -- "${FILENAME%.*}.conf")" @@ -56,6 +76,7 @@ comments() { cat <<EOF <section> <hr /> + <!-- Use <address> here? --> <footer> <p id="comment"> <a href="$comment_url">Comment</a> @@ -99,7 +120,9 @@ EOF collection_head_prev_html= collection_head_post_html= -cat <<EOF | sed '/^$/d' + +header() { + cat <<EOF | sed '/^$/d' <!DOCTYPE html> <html lang="en"> <head> @@ -131,14 +154,18 @@ $(headlinks) <article> EOF -h1 -dates + h1 + dates +} -cat "$FILENAME" +body() { + cat "${FILENAME%.*}.htmlbody" +} -comments +footer() { + comments -cat <<EOF + cat <<EOF </article> </main> <footer> @@ -163,3 +190,19 @@ cat <<EOF </body> </html> EOF +} + + +if [ "$HEADER_ONLY" = true ]; then + header + exit +fi + +if [ "$FOOTER_ONLY" = true ]; then + footer + exit +fi + +header +body +footer |