From 2ef8fe251d3d4d5ad6f20c5477714ba278661498 Mon Sep 17 00:00:00 2001 From: Callum Renwick Date: Sat, 4 Sep 2021 20:37:34 +0100 Subject: [PATCH] render_file: allow page elements to be customised The header, footer and can now be customised using either static or dynamic templates. This makes it possible to use Wordpusher for more than one site without modifying the source scripts. --- .gitignore | 2 ++ render_file | 31 ++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53288c3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +gentemplate/* +template/* diff --git a/render_file b/render_file index 00e9ad6..1469ce6 100755 --- a/render_file +++ b/render_file @@ -8,6 +8,23 @@ frontmatter=$(awk '/!startmeta/,/!endmeta/ {if ($0 != "!startmeta" && $0 != "!en docbody=$(awk '/!endmeta/ {p=1; next} p' "$1") title=$(echo "$frontmatter" | awk -F'=' '/title=/ {print $2}') date=$(echo "$frontmatter" | awk -F'=' '/date=/ {print $2}') +# Attempt to dynamically generate the header and footer for this page from gentemplates +# (If no script for generation exists, skip the step for that page element) +if [ -f gentemplate/header ] +then + printf 'Generating page header...' >&2 + title="$title" date="$date" gentemplate/header +fi +if [ -f gentemplate/footer ] +then + printf 'Generating page footer...' >&2 + date="$date" gentemplate/footer +fi +if [ -f gentemplate/htmlhead ] +then + printf 'Generating page ...' >&2 + title="$title" gentemplate/htmlhead +fi # cmark doesn't create the , doctype declaration or indeed most of the document # structure for us, so we'll do it ourselves. # We're going to use single quotes for the strings here too because otherwise we'll have @@ -15,17 +32,13 @@ date=$(echo "$frontmatter" | awk -F'=' '/date=/ {print $2}') printf '\n' printf '\n' printf '\n' -printf "%s | cren's webspace\n" "$title" -printf '\n' -printf '\n' -printf '\n' -printf '\n' +# At this point, insert the +printf "%s\n" "$(cat template/htmlhead)" printf '\n' printf '\n' printf '
\n' -printf "

cren's webspace

\n" -printf '

%s

\n' "$title" -printf '%s' "$date" "$date" +# Now insert the header +printf "%s\n" "$(cat template/header)" printf '
\n' printf '
\n' # Now we insert the main content of the page @@ -34,7 +47,7 @@ printf '%s' "$(echo "$docbody" | cmark)" printf '
\n' # Finally, the footer printf '\n' printf '\n' printf '\n'