I did something very similar a while back except in python more as a PoC but ended up using it - http://benlowery.co.uk/blog/statomatic.html
Mine supports arbitrarily nested pages, customisable templates, metadata in YAML at the top of the file and automatic ToC etc.
Largely thanks to the insanely good PyMarkdown library.