From e2b2e1ce81367d9e36785afa811f8efb3fe4bfdc Mon Sep 17 00:00:00 2001 From: Danny O'Brien Date: Fri, 12 Jan 2024 11:48:02 -0800 Subject: [PATCH] Configurise pandoc output customisation --- .../integrity-new-years-backups/create.sh | 1 - assets/pandoc/metadata/frontpage.json | 3 + assets/pandoc/pandoc-default.html | 73 +++++++++++++++++++ assets/pandoc/templates/_header.html | 1 + assets/pandoc/templates/default.html5 | 72 ++++++++++++++++++ assets/templates/a-basic.html | 70 ++++++++++++++++++ assets/templates/pandoc-default.html | 73 +++++++++++++++++++ bin/a-preview.sh | 52 +++++++++++++ 8 files changed, 344 insertions(+), 1 deletion(-) delete mode 100755 assets/editorial/09final/integrity-new-years-backups/create.sh create mode 100644 assets/pandoc/metadata/frontpage.json create mode 100644 assets/pandoc/pandoc-default.html create mode 100644 assets/pandoc/templates/_header.html create mode 100644 assets/pandoc/templates/default.html5 create mode 100644 assets/templates/a-basic.html create mode 100644 assets/templates/pandoc-default.html create mode 100755 bin/a-preview.sh diff --git a/assets/editorial/09final/integrity-new-years-backups/create.sh b/assets/editorial/09final/integrity-new-years-backups/create.sh deleted file mode 100755 index df8c347..0000000 --- a/assets/editorial/09final/integrity-new-years-backups/create.sh +++ /dev/null @@ -1 +0,0 @@ -pandoc -i new-years-backups.md -B _header.html -c 'res/almanack.css' --standalone -o new-years-backups.html ; open new-years-backups.html diff --git a/assets/pandoc/metadata/frontpage.json b/assets/pandoc/metadata/frontpage.json new file mode 100644 index 0000000..55a121b --- /dev/null +++ b/assets/pandoc/metadata/frontpage.json @@ -0,0 +1,3 @@ +{ +"css" : "/res/almanack.css" +} diff --git a/assets/pandoc/pandoc-default.html b/assets/pandoc/pandoc-default.html new file mode 100644 index 0000000..dda7e8c --- /dev/null +++ b/assets/pandoc/pandoc-default.html @@ -0,0 +1,73 @@ + + + + + + +$for(author-meta)$ + +$endfor$ +$if(date-meta)$ + +$endif$ +$if(keywords)$ + +$endif$ +$if(description-meta)$ + +$endif$ + $if(title-prefix)$$title-prefix$ – $endif$$pagetitle$ + +$for(css)$ + +$endfor$ +$for(header-includes)$ + $header-includes$ +$endfor$ +$if(math)$ + $math$ +$endif$ + + + +$for(include-before)$ +$include-before$ +$endfor$ +$if(title)$ +
+

$title$

+$if(subtitle)$ +

$subtitle$

+$endif$ +$for(author)$ +

$author$

+$endfor$ +$if(date)$ +

$date$

+$endif$ +$if(abstract)$ +
+
$abstract-title$
+$abstract$ +
+$endif$ +
+$endif$ +$if(toc)$ + +$endif$ +$body$ +$for(include-after)$ +$include-after$ +$endfor$ + + diff --git a/assets/pandoc/templates/_header.html b/assets/pandoc/templates/_header.html new file mode 100644 index 0000000..b12f3a0 --- /dev/null +++ b/assets/pandoc/templates/_header.html @@ -0,0 +1 @@ +

Almanack

diff --git a/assets/pandoc/templates/default.html5 b/assets/pandoc/templates/default.html5 new file mode 100644 index 0000000..a0dcc3e --- /dev/null +++ b/assets/pandoc/templates/default.html5 @@ -0,0 +1,72 @@ + + + + + + +$for(author-meta)$ + +$endfor$ +$if(date-meta)$ + +$endif$ +$if(keywords)$ + +$endif$ +$if(description-meta)$ + +$endif$ + $if(title-prefix)$$title-prefix$ – $endif$$pagetitle$ + +$for(css)$ + +$endfor$ + +$for(header-includes)$ + $header-includes$ +$endfor$ +$if(math)$ + $math$ +$endif$ + + +$for(include-before)$ +$include-before$ +$endfor$ +

Almanack

+$if(title)$ +
+

$title$

+$if(subtitle)$ +

$subtitle$

+$endif$ +$for(author)$ +

$author$

+$endfor$ +$if(date)$ +

$date$

+$endif$ +$if(abstract)$ +
+
$abstract-title$
+$abstract$ +
+$endif$ +
+$endif$ +$if(toc)$ + +$endif$ +$body$ +$for(include-after)$ +$include-after$ +$endfor$ + + diff --git a/assets/templates/a-basic.html b/assets/templates/a-basic.html new file mode 100644 index 0000000..26740d1 --- /dev/null +++ b/assets/templates/a-basic.html @@ -0,0 +1,70 @@ + + + + + + +$for(author-meta)$ + +$endfor$ +$if(date-meta)$ + +$endif$ +$if(keywords)$ + +$endif$ +$if(description-meta)$ + +$endif$ + $if(title-prefix)$$title-prefix$ – $endif$$pagetitle$ + +$for(css)$ + +$endfor$ +$for(header-includes)$ + $header-includes$ +$endfor$ +$if(math)$ + $math$ +$endif$ + + +$for(include-before)$ +$include-before$ +$endfor$ +$if(title)$ +
+

$title$

+$if(subtitle)$ +

$subtitle$

+$endif$ +$for(author)$ +

$author$

+$endfor$ +$if(date)$ +

$date$

+$endif$ +$if(abstract)$ +
+
$abstract-title$
+$abstract$ +
+$endif$ +
+$endif$ +$if(toc)$ + +$endif$ +$body$ +$for(include-after)$ +$include-after$ +$endfor$ + + diff --git a/assets/templates/pandoc-default.html b/assets/templates/pandoc-default.html new file mode 100644 index 0000000..dda7e8c --- /dev/null +++ b/assets/templates/pandoc-default.html @@ -0,0 +1,73 @@ + + + + + + +$for(author-meta)$ + +$endfor$ +$if(date-meta)$ + +$endif$ +$if(keywords)$ + +$endif$ +$if(description-meta)$ + +$endif$ + $if(title-prefix)$$title-prefix$ – $endif$$pagetitle$ + +$for(css)$ + +$endfor$ +$for(header-includes)$ + $header-includes$ +$endfor$ +$if(math)$ + $math$ +$endif$ + + + +$for(include-before)$ +$include-before$ +$endfor$ +$if(title)$ +
+

$title$

+$if(subtitle)$ +

$subtitle$

+$endif$ +$for(author)$ +

$author$

+$endfor$ +$if(date)$ +

$date$

+$endif$ +$if(abstract)$ +
+
$abstract-title$
+$abstract$ +
+$endif$ +
+$endif$ +$if(toc)$ + +$endif$ +$body$ +$for(include-after)$ +$include-after$ +$endfor$ + + diff --git a/bin/a-preview.sh b/bin/a-preview.sh new file mode 100755 index 0000000..333a11b --- /dev/null +++ b/bin/a-preview.sh @@ -0,0 +1,52 @@ +#!/bin/zsh +### +# a-preview +### +# Previews an md file (or other) as a Almanack page +### +# +# Note: this is a clumsy hack from the very early days (pre-Django) of +# Almanack, and may well be deprecated. And I say that from the pre-Django days +# of Almanack. + + +function open_html() { + if [[ $# -eq 0 ]]; then + echo "Usage: open_html " + return 1 + fi + + local file_to_open="$1" + + case "$OSTYPE" in + linux-gnu*) + xdg-open "$file_to_open" + ;; + darwin*) + open "$file_to_open" + ;; + esac +} + +# Check if ALMANACK_ROOT is defined +if [[ -z "$ALMANACK_ROOT" ]]; then + echo "Error: ALMANACK_ROOT is not defined." + exit 1 +fi + +# Check for one command line argument +if [[ $# -ne 1 ]]; then + echo "Usage: $(basename $0) " + exit 1 +fi + +WEB_ROOT=$ALMANACK_ROOT/web/static +WEB_RESOURCES=$WEB_ROOT/res +PANDOC_ASSETS=$ALMANACK_ROOT/assets/pandoc/ + +basename=${1%.*} + +# pandoc -i $1 -B $WEB_RESOURCES/_header.html -c $WEB_RESOURCES/almanack.css --standalone -o $basename.html +pandoc --data-dir $PANDOC_ASSETS --metadata-file frontpage.json -i $1 --standalone -o $basename.html + +open_html "$basename.html"