Hacker News new | ask | show | jobs
by prewett 4527 days ago
Is there something like this that operates at a higher level? Unlike the author, I'm ok with HTML (and I can't stand markdown), except that it's too low level. I want to break things up by title, author, date, summary, content, etc. and then generate the HTML by plugging it into a template, so that title, date, and author become part of the heading at the top of the page and so on. So something like

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

4 comments

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

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