From aea8548930fd58d5302aa6381376adbb8a2be2d4 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Sun, 4 Nov 2018 19:27:14 +0100 Subject: [PATCH] update_html also takes individual arguments --- bin/update_html | 57 +++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/bin/update_html b/bin/update_html index f7c0ad727..126072e44 100755 --- a/bin/update_html +++ b/bin/update_html @@ -7,25 +7,40 @@ # https://stackoverflow.com/a/246128/98600 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" -find . -name '*.t2t' | while read t2t ; do - html="${t2t%.t2t}.html" - if [ "$t2t" -nt "$html" ] ; then - echo "$t2t" - relroot="$( dirname $t2t | sed -E 's/^.\///' | sed -E 's/[^/]+/../g' )" - pandoc \ - --from=t2t \ - --to=html5 \ - --standalone \ - --template="$DIR/_template.html" \ - --css="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" \ - --variable="rel-root:$relroot" \ - "$t2t" \ - --output="$html" - if [ -f "$html" ]; then - sed -i.bak "s//
/" "$html" && rm "$html.bak" - sed -i.bak -E "s/\`\`(.+)\`\`/\1<\/code>/g" "$html" && rm "$html.bak" - else - echo "Error creating $html" - fi +function render_html { + t2t=$1 + html=$2 + relroot="$( dirname $t2t | sed -E 's/^.\///' | sed -E 's/[^/]+/../g' )" + pandoc \ + --from=t2t \ + --to=html5 \ + --standalone \ + --template="$DIR/_template.html" \ + --css="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" \ + --variable="rel-root:$relroot" \ + "$t2t" \ + --output="$html" + if [ -f "$html" ] ; then + sed -i.bak "s/
/
/" "$html" && rm "$html.bak" + sed -i.bak -E "s/\`\`(.+)\`\`/\1<\/code>/g" "$html" && rm "$html.bak" + echo "$html" + else + echo "Error creating $html" fi -done +} + +if [ $# -gt 0 ] ; then + # Render spcific file(s) from args, ignoring dates + for t2t in "$@" ; do + html="${t2t%.t2t}.html" + render_html "$t2t" "$html" + done +else + # Render all files found from cwd, if source is newer + find . -name '*.t2t' | while read t2t ; do + html="${t2t%.t2t}.html" + if [ "$t2t" -nt "$html" ] ; then + render_html "$t2t" "$html" + fi + done +fi