From 6735e712ebfd0d328f440f947c4bbc82cf714d0f Mon Sep 17 00:00:00 2001 From: Atlas Cove Date: Fri, 17 Feb 2023 14:32:32 +0000 Subject: [PATCH] refactored tape ssg --- m4/main.html.m4 | 6 ++++-- render.sh | 19 ++----------------- tape.sh | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 19 deletions(-) create mode 100755 tape.sh diff --git a/m4/main.html.m4 b/m4/main.html.m4 index 325a7ef..429fadf 100644 --- a/m4/main.html.m4 +++ b/m4/main.html.m4 @@ -1,6 +1,8 @@ -dnl template.m4.html v1.4-p1 +dnl template.m4.html v2.0-p1 dnl Part of the tape-and-string suite used to construct the website ifdef(`DEBUG',`traceon')dnl +ifdef(`_INFILE',`dnl ',`errprint(`Macro _INFILE is not defined') +m4exit(1)')dnl include(`m4/lib.m4')dnl @@ -15,7 +17,7 @@ include(`m4/lib.m4')dnl Home
-include(`/dev/stdin')dnl Probably not a good idea, but whatever. +esyscmd(`./tape.sh' _INFILE)
diff --git a/render.sh b/render.sh index ba6b5fa..08570f9 100755 --- a/render.sh +++ b/render.sh @@ -9,21 +9,6 @@ declare -A title function inf { 1>&2 echo -e "\x1B[1;32mINF\x1B[0m: $*"; } function wrn { 1>&2 echo -e "\x1B[1;93mWRN\x1B[0m: $*"; } function err { 1>&2 echo -e "\x1B[1;31mERR\x1B[0m: $*"; } -function tape { - if test -d "$1"; then - err "tape: Passed directory, $1" - return 1 - fi - case $1 in - *.txti) redcloth "$1" ;; - *.org) org-ruby --translate html "$1" ;; - *.md) comrak --gfm "$1" ;; - *.html) cat $1 ;; - *.s[ac]ss) err "Told to render $1, shouldn't happen"; return 1 ;; - *.sh) (inf "Running shellscript $1, I hope you know what you're doing..."; source $1 );; - *) pandoc --columns 168 -t html "$1" || echo "Skipping $i, unknown format" ;; - esac -} function dirs { if test -d out; then wrn "Directory 'out' already exists." @@ -50,9 +35,9 @@ function docs { o="${i/in/out}" echo "$i => $o" if test -z "${title[$i]}"; then - tape $i | m4 -DCSSI=$(awk -f get_sd.awk <<< "$i") m4/main.html.m4 > ${o%.*}.html + m4 -D_INFILE="$i" -DCSSI=$(awk -f get_sd.awk <<< "$i") m4/main.html.m4 > ${o%.*}.html else - tape $i | m4 -DCSSI=$(awk -f get_sd.awk <<< "$i") -DTITLE="${title[$i]}" m4/main.html.m4 > ${o%.*}.html + m4 -D_INFILE="$i" -DCSSI=$(awk -f get_sd.awk <<< "$i") -DTITLE="${title[$i]}" m4/main.html.m4 > ${o%.*}.html fi done } diff --git a/tape.sh b/tape.sh new file mode 100755 index 0000000..757596d --- /dev/null +++ b/tape.sh @@ -0,0 +1,22 @@ +#!/bin/bash +function inf { 1>&2 echo -e "\x1B[1;32mINF\x1B[0m: $*"; } +function wrn { 1>&2 echo -e "\x1B[1;93mWRN\x1B[0m: $*"; } +function err { 1>&2 echo -e "\x1B[1;31mERR\x1B[0m: $*"; } +if test -d "$1"; then + err "tape: Passed directory, $1" + return 1 +elif test -z "$*"; then + err "No files passed." + exit 1 +fi +case $1 in + _INFILE) err "Passed raw macro."; exit 1;; + *.txti) redcloth "$1" ;; + *.org) org-ruby --translate html "$1" ;; + *.md) comrak --gfm "$1" ;; + *.html) cat $1 ;; + *.s[ac]ss) err "Told to render $1, shouldn't happen"; exit 1 ;; + *.sh) (inf "Running shellscript $1, I hope you know what you're doing..."; source $1 );; + *) pandoc --columns 168 -t html "$1" || echo "Skipping $i, unknown format" ;; +esac +