Backlinks for custom (automated) footnotes

I’m developing a custom, shortcode-based footnote formatting for my articles. The intent is to automate the creation and coordination of footnotes, by relying on the nth argument provided for shortcodes. Zola docs even mention it as a useful tool for creating footnotes and such.

The problem is: with the way footnote count is automated, there’s no way for me to link back to a specific note without having to manually count the notes in a finished article before publishing. The intent, may I remind you, is to avoid this part of manual work.

While there is a way to label a custom footnote element with a unique ID, there’s no way to extract the footnote’s actual, user-facing ID (which is numeric and ascending, as is common for footnotes, and – again, generated automatically). What I could have done, if it were possible, is give a footnote a unique ID (along with a user-facing one), and then link back to this particular note using its unique ID by displaying its user-facing ID.

For example:

In this book¹¹, George talks about <...>
¹¹ On Nature of Things, Kevin George, 1998, p. 11
As mentioned in the book²¹, the conversation...
²¹ same book as in note 11, pp. 182—187

…where each footnote numeral (e.g. In this book¹¹) links to said footnote’s element (e.g. ¹¹ On Nature of Things) with a <a href="#footnote{{nth}}"> element.

In the example above, getting notes 11 and 21 is easy, but getting note 21 to link to 11 – without me going back and looking up which note that is – is basically impossible.

So far, I’ve tried creating a global reference object within the article Markdown document, manually entering the unique ID (but not the user-facing one) into it as a key, and then assigning the value (i.e., the user-facing ID a backlink would display) at shortcode-assisted generation of foonotes. This isn’t possible: Zola becomes upset with me for trying to {% set %} something within a conditional {% if %} clause:

[after rendering the footnote element]

{% if unique %}
{% set_global reference[unique] = nth %}
{% endif %}

No other method comes to mind.

Is it even possible to automate something like this? Setting up the reference object via frontmatter is also possible, but I don’t believe shortcodes/templates can write to TOML from within a document.

I haven’t explored this, but: would it be possible to set up a text-based “database” in an external file, to which Zola can write and from which it can read during rendering? That could be solution, if a cumbersome one.

1 Like