render_file: allow page elements to be customised
The header, footer and <head> 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.
This commit is contained in:
parent
e78f2866d8
commit
2ef8fe251d
|
@ -0,0 +1,2 @@
|
|||
gentemplate/*
|
||||
template/*
|
31
render_file
31
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 <head>...' >&2
|
||||
title="$title" gentemplate/htmlhead
|
||||
fi
|
||||
# cmark doesn't create the <head>, 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 '<!doctype html>\n'
|
||||
printf '<html>\n'
|
||||
printf '<head>\n'
|
||||
printf "<title>%s | cren's webspace</title>\n" "$title"
|
||||
printf '<link rel="icon" href="favicon.ico" type="image/x-icon">\n'
|
||||
printf '<link rel="stylesheet" href="cren.css">\n'
|
||||
printf '<meta charset="utf8">\n'
|
||||
printf '<meta name="viewport" content="width=device-wdith, initial-scale=1">\n'
|
||||
# At this point, insert the <head>
|
||||
printf "%s\n" "$(cat template/htmlhead)"
|
||||
printf '</head>\n'
|
||||
printf '<body>\n'
|
||||
printf '<header>\n'
|
||||
printf "<h1>cren's webspace</h1>\n"
|
||||
printf '<h2>%s</h2>\n' "$title"
|
||||
printf '<date datetime=%s>%s</date>' "$date" "$date"
|
||||
# Now insert the header
|
||||
printf "%s\n" "$(cat template/header)"
|
||||
printf '</header>\n'
|
||||
printf '<main>\n'
|
||||
# Now we insert the main content of the page
|
||||
|
@ -34,7 +47,7 @@ printf '%s' "$(echo "$docbody" | cmark)"
|
|||
printf '</main>\n'
|
||||
# Finally, the footer
|
||||
printf '<footer>\n'
|
||||
printf '<p>Content on this webspace is made available under the <a href="https://creativecommons.org/publicdomain/zero/1.0/legalcode">CC0 licence</a>. You have the right to copy.</p>\n'
|
||||
printf '%s\n' "$(cat template/footer)"
|
||||
printf '</footer>\n'
|
||||
printf '</body>\n'
|
||||
printf '</html>\n'
|
||||
|
|
Loading…
Reference in New Issue