sc0ttj / mdsh

A simple static site generator, using Markdown and Bash
https://sc0ttj.github.io/mdsh/
10 stars 0 forks source link

Mustache templating 1 #59

Closed sc0ttj closed 5 years ago

sc0ttj commented 5 years ago

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 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:

Render multiple formats:

Fixes in JSON-LD generation:

More robust CSS for post headers/footers:

W3C validation:

Frontend performance improvement:

Improvements to search page:

Improvements displaying page/post dates:

Fixes in page meta:

Improvements to publish.sh:

Post excerpts:

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..