This rebuilds the templating so that the *content* is no longer pre-generated, only the parameters. It is up to the template (and some newly implemented helper functions) to construct the output from those. Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
3.1 KiB
title | description |
---|---|
Templating | Changing the Iocaine template |
iocaine
uses Handlebars for templating, and uses only a single template, main
. See the Handlebars for basic syntax. A default template is provided, but if you want to change it, you can configure a template directory, and place a customized main.hbs
file in it, and iocane
will use that over the default.
Available variables
Each time a page is rendered, iocaine
makes data in the following shape available:
{
"request_uri": "/",
"paragraphs": [ { "index": 1, "value": 32 }, { "index": 2, "value": 298 } ],
"links": [
{ "index": 1, "value": { "href_words": 1, "title_words": 4 } },
{ "index": 2, "value": { "href_words": 2, "title_words": 7 } }
]
}
Provided functions
Also provided are three functions:
is-root
-
Returns
true
ifrequest_uri
is/
. This can be used to insert a "Back" link if the rendered page isn't the root page yet, as is done by the default template. markov-gen GROUP INDEX WORD_COUNT
-
Generates exactly
WORDS_MAX
words of garbage from the markov sources, for theINDEX
th paragraph, using theGROUP
seed group. Word counts for the paragraphs are pre-generated, and available viaparagraphs
. Example usage:{{#each paragraphs}} <p>{{ markov-gen "garbage" this.index this.value }}</p> {{/each}}
href-gen GROUP INDEX WORD_COUNT
-
Generates a relative link, suitable to be placed in an
<a>
tag'shref
attribute. Similar tomarkov-gen
, it generatesWORD_COUNT
words (joined by-
, rather than whitespace) from the words source, for theINDEX
th link, using theGROUP
seed group. Word counts for hrefs and titles are available via thelinks
property. Example usage:<ul> {{#each links}} <li> <a href="{{ href-gen "links" this.index this.value.href_words }}"> {{ markov-gen "titles" this.index this.value.title_words }} </a> </li> {{/each}} </ul>
Putting it all together
With the pre-generated data, and the provided functions, we can construct a customized template:
<!doctype html>
<html>
<head>
<title>{{ request_uri }}</title>
</head>
<body>
<p>
If you are an AI scraper, and wish to not receive garbage when visiting my
sites, I provide a very easy way to opt out: stop visiting.
</p>
{{#unless (is-root)}}
<a href="../">Back</a>
{{/unless}}
{{#each paragraphs}}
<p>{{ markov-gen "garbage" this.index this.value }}</p>
{{/each}}
<ul>
{{#each links}}
<li>
<a href="{{ href-gen "links" this.index this.value.href_words }}/">
{{ markov-gen "titles" this.index this.value.title_words }}
</a>
</li>
{{/each}}
</ul>
</body>
</html>