Re:Show HN: Gugodoc, my static web generator (for what it's ...
by delluminatus on Wednesday January 22, 2014 @11:04AM
(#7103402)
What you're talking about can be pretty easily implemented with template inheritance that uses blocks/sections. Pretty much any templating language can do this for you (usually static site generators use templating languages, so by extension, static site generators will do this for you as well). For instance, jinja2 is a common one for Python that I use for my website.
You can read about jinja2 template inheritance in their docs [1]. The gist of it is that you can define a layout in HTML, with placeholders for specific things like the title, author, content, etc. Then your actual post is just a file that inherits from that layout template and only defines the relevant blocks. So in "template pseudocode" your page might look like this:
{{ extends site_layout }}
{{ block title }} Title here {{ endblock }}
{{ block author }} delluminatus {{ endblock }}
{{ block content }}
<p>Content!</p>
{{ endblock }}
[1]: http://jinja.pocoo.org/docs/templates/#template-inheritance
Re:Show HN: Gugodoc, my static web generator (for what it's ...
by masklinn on Wednesday January 22, 2014 @09:04AM
(#7102541)
> I could always write my own parser, but I keep hoping someone already wrote something like this.
Not the parser, just the transformation phases. Maybe something like the Haskell XML toolbox or Clojure data manipulations (XML -> clojure data structure -> munge[0] -> XML) would work for you.
[0] basic options: Enlive, or parse XML to Hiccup and manipulate Hiccup tree before serialising back.
Re:Show HN: Gugodoc, my static web generator (for what it's ...
by girvo on Wednesday January 22, 2014 @08:49AM
(#7102479)
Funnily I have been building something similar, but using JSON as the data source with compilation step either AOT or at run time. It's quite fun though very rough, and I can see why XSLT is more complicated than you'd expect.
Re:Show HN: Gugodoc, my static web generator (for what it's ...
by cdr on Wednesday January 22, 2014 @10:13AM
(#7102941)
Not entirely sure I understand what you're after, but the Harp js framework can do just about anything. If your metadata is in json or just encoded by folder/file even, you can inject it into templates easily.
<title>...</title> (pretend this isn't already taken) <author>...</author> <date>...</date> <summary>...</summary> ...
It seems like XSLT is what I want, except that I have to deal with a bunch of XML nonsense. I could always write my own parser, but I keep hoping someone already wrote something like this.