I just finished updating this site from Zola 0.22.0 to 0.23.2. It doesn't seem like this should be a big deal, but it turns out that Zola 0.23 ported the templating engine from Tera 1 to Tera 2. The biggest change in Tera 2 is the replacement of macros by hygenic function-like "components" which, to put it lightly, fucked my shit up.
I have a bunch of templates that make this site more pleasant; for example, if I want to insert an image I used to use a Zola shortcode called "figure" that I wrote:
{% if src is starting_with("http") %}
{% set url=src %}
{% elif src is starting_with("/") %}
{% set url=src %}
{% elif page %}
{% set url=get_url(path=page.path ~ src) %}
{% else %}
{% set url=get_url(path=section.path ~ src) %}
{% endif %}
{% if self_href %}
{% set href = url %}
{% endif %}
{% if thumbnail %}
{% set resized = resize_image(path=page.colocated_path ~ src, width=800, height=800, op="fit") %}
{% set url = resized.url %}
{% endif %}
<figure>
{% if href %}
<a href="{{href | safe}}">
{% endif %}
<img src="{{url | safe}}" {% if classes %}class="{{classes}}" {% endif %}{%if alt %}alt="{{alt}}" {%endif%} />
{% if href %}
</a>
{% endif %}
<figcaption>{{caption | markdown(inline=true) | safe}}</figcaption>
</figure>
This was called like {{figure(src="foo.png", caption="Whatever", thumbnail=true)}} and would figure out the right source for the image.
The replacement component looks like
{% component blog.figure(src: string, caption: string, alt: string = "", self_href: bool = false, thumbnail: bool = false, page: map = {}, section: map = {}) %}
{% if src is starting_with(pat="http") %}
{% set url=src %}
{% elif src is starting_with(pat="/") %}
{% set url=src %}
{% elif page %}
{% set url=get_url(path=page.path ~ src) %}
{% else %}
{% set url=get_url(path=section.path ~ src) %}
{% endif %}
{% if self_href %}
{% set href = url %}
{% endif %}
{% if thumbnail %}
{% set resized = resize_image(path=page.colocated_path ~ src, width=800, height=800, op="fit") %}
{% set url = resized.url %}
{% endif %}
<figure>
{% if href %}
<a href="{{href | safe}}">
{% endif %}
<img src="{{url | safe}}" {% if classes %}class="{{classes}}" {% endif %}{%if alt %}alt="{{alt}}" {%endif%} />
{% if href %}
</a>
{% endif %}
<figcaption>{{caption | markdown(inline=true) | safe}}</figcaption>
</figure>
{% endcomponent %}
You use this as {{<blog.figure src="foo.png" caption="whatever" thumbnail={true} page />}}
A couple of important changes:
- The
page/sectionglobal needs to be passed in explicitly now because there's no way to reference globals any more (I filed getzola/zola#3223 about this) - You can't indent any more, because components run before markdown processing, so they have to output valid markdown (which means any inline HTML needs to be un-indented; I filed getzola/zola#3224 about this)
- The new fake-HTML syntax really screws up syntax highlighting and has a totally unnecessary JSX-style curly-bracket wrapping of non-text values (even though you also need to quote string values, so, again, this serves no purpose).
Another change that's in Zola 0.23 that drove me a bit mad is that the group_by filter now outputs an unsorted hash map instead of a sorted map, and the workaround is gross and requires using {% set_global %}. Hoping that upstream adds the ability to sort maps at some point (or just switches to a BTreeMap instead of a HashMap).
Anyhow, it took me about an hour to port everything over and there are almost certainly some screwy pages still on the site. Drop me a line if you notice any!
Want to comment on this? How about we talk on Mastodon instead?