This uses a shell implementation of Mustache templating called mo.
Bash 4.x is now required, as this PR uses Bash associative arrays.
The create_page script has been totally re-written, to remove all HTML from there, into the template files.
Structure
Templates are in .app/templates/, separated into html, json-ld and js folders.
Most functions in create_page now simply create the variables needed for the templates, put the vars into arrays or hashes, then call mo to generate the HTML.
And update_pages is now similar - set vars and arrays for each page to create, calls create_page.sh, which runs the functions that call mo to build the HTML.
The good
Cleaner code:
all data (post and page vars) now separated from layouts completely
All data (from meta info in .mdsh files, or from post_** vars passed to create_page.sh) gathered and organised into arrays, then passed to mo.
All templates separated into <renderer>/_<layout>.mustache (Example: html/_list.mustache)
Main scripts are as DRY as can be.
Render multiple formats:
templates for different output types (HTML, JS, JSON-LD) live in different folders
look in .app/templates/<format>/
where <format> can be html, json-ld, js
in future, can add more formats: css, amp, fbia, rss, etc
this makes it easy to render the site in HTML, and in other formats
Fixes in JSON-LD generation:
better breadcrumbs
fixed all URLs (should be full URLs, not relative)
fixed author info
fixed mainEntityOfPage in article info
More robust CSS for post headers/footers:
not using nth-child() anymore,
added some class names to target instead
W3C validation:
removing the Google Font URL (containing |) from <head> fixes a W3C validation error
CSS and JSON-LD also validate
Frontend performance improvement:
add Google Font CSS to main CSS file at build time
Improvements to search page:
better document/heading layout, looks nicer
Improvements displaying page/post dates:
using <time datetime="2019-06-24">
Fixes in page meta:
fixed canonical url
simpler google analytics stuff
fixed IE classes
Improvements to publish.sh:
fixed: don't publish out-of-date sitemap and RSS feeds
the solution used: commit & push the pages first, then generate the RSS feed and XML sitemaps...
(The RSS feed and XML sitemaps are generated from the online/published version of the site, hence committing & pushing the html pages first..)
Post excerpts:
add <!-- more --> to your markdown when creating posts, and only the content before it will be included in the post previews on the homepage.
The <!-- more --> marker will be replaced with a "Read more" link in the HTML output.
The bad
Rebuilding pages is now much slower (about 4x slower than without mo based templating) :/
The code is a bit more complex than it could be: in order to get around the lack of multi-dimensional arrays in Bash, we re-use various functions and the ITEMS array, and many of the template 'partials' (such as 'page header') are actually mustache variables with matching shell functions, which handle the logic and do some data processing..
Info
This uses a shell implementation of Mustache templating called mo.
Bash 4.x is now required, as this PR uses Bash associative arrays.
The
create_page
script has been totally re-written, to remove all HTML from there, into the template files.Structure
Templates are in
.app/templates/
, separated intohtml
,json-ld
andjs
folders.Most functions in
create_page
now simply create the variables needed for the templates, put the vars into arrays or hashes, then callmo
to generate the HTML.And
update_pages
is now similar - set vars and arrays for each page to create, callscreate_page.sh
, which runs the functions that callmo
to build the HTML.The good
Cleaner code:
.mdsh
files, or frompost_**
vars passed tocreate_page.sh
) gathered and organised into arrays, then passed tomo
.<renderer>/_<layout>.mustache
(Example:html/_list.mustache
)Render multiple formats:
.app/templates/<format>/
<format>
can behtml
,json-ld
,js
css
,amp
,fbia
,rss
, etcFixes in
JSON-LD
generation:mainEntityOfPage
in article infoMore robust CSS for post headers/footers:
nth-child()
anymore,W3C validation:
|
) from<head>
fixes a W3C validation errorFrontend performance improvement:
Improvements to search page:
Improvements displaying page/post dates:
<time datetime="2019-06-24">
Fixes in page meta:
Improvements to
publish.sh
:Post excerpts:
<!-- more -->
to your markdown when creating posts, and only the content before it will be included in the post previews on the homepage.<!-- more -->
marker will be replaced with a "Read more" link in the HTML output.The bad
Rebuilding pages is now much slower (about 4x slower than without
mo
based templating) :/The code is a bit more complex than it could be: in order to get around the lack of multi-dimensional arrays in Bash, we re-use various functions and the
ITEMS
array, and many of the template 'partials' (such as 'page header') are actually mustache variables with matching shell functions, which handle the logic and do some data processing..