I’m currently working on enhancing the tabi theme, maintained by @welpo, to include RSS feed icons for individual tags. During this process, I’ve encountered a scenario where some tags are associated with pages that don’t have a date field in their frontmatter. As a result, Zola doesn’t generate the atom.xml file for those tags, even when feed = true is set in the taxonomies within config.toml.
If a tag is only assigned to pages without a date field, clicking on its feed icon leads to a 404 page because the atom.xml file has not been generated. For example, accessing the feed for the tag bash, which is only associated with project pages that lack a date field, results in a 404 error.
Zola’s behaviour aligns with the RSS specification, which requires that entries in an Atom feed must have a date field. This means that even when feed = true is enabled in config.toml, the absence of dated pages prevents the feed from being created.
Possible Solution
From the discussion in the tabi repository, two key aspects need to be considered:
Checking the global feed setting:
In Zola, the feed = true setting is part of the [taxonomies] configuration in config.toml, determining whether RSS feeds should be generated for a given taxonomy, such as tags. According to the documentation, the list.html file as well as the single.html file have access to the taxonomy variable which is of type TaxonomyConfig object. This value can be checked using the boolean type property named feed. However, this only controls feed generation. It doesn’t ensure that an atom.xml file will exist for every tag, as the file is only created if at least one associated page contains a date field in its frontmatter.
Verifying that atom.xml has been generated:
Since Zola only generates an atom.xml file if at least one page under a tag contains a date field in its frontmatter, there is a need to check whether this condition is met before rendering the feed icon. The challenge is finding a way to perform this check within Zola’s templating system.
Questions
How can we check, within Zola’s templating system, whether at least one page associated with a tag contains a date field?
Are there any alternative approaches within Zola that could help address this issue?
I appreciate any insights or suggestions from the community. Thanks!
I think this is related to the problem that I also have, to be able to read files at compile time.
if there is a function like get_files(path) and get_file(path) in zola, you can check if atom.xml actually exists or not. and then render accordingly.
I’m not good enough with rust to confidently do this, but I looked at the source code of zola and looked how resize_image function is defined and it seems pretty simple to add these functions into zola.
After reviewing the documentation again, I found a potential solution using the get_taxonomy_term global function.
This function retrieves a term from a specific taxonomy, requiring two parameters:
kind: the taxonomy type.
term: the term for which we want to retrieve data.
It returns a TaxonomyTerm object, which includes a pages field containing all the pages associated with the given term.
In list.html, we have access to the taxonomy variable (of type TaxonomyConfig), which contains the name field (corresponding to kind), as well as the terms variable, which is an array of TaxonomyTerm object. Based on this, the logic is as follows:
Iterate over the terms in list.html.
For each term, call get_taxonomy_term, passing taxonomy.name as kind and term.name as term, retrieving the TaxonomyTerm object.
Iterate over the pages field of the retrieved object and check if any of them contain the date field.
If at least one page has a date, display the feed icon.
Here is the implementation in Zola:
{%- for term in terms -%}
{% if taxonomy.feed %}
{% set taxonomy_term = get_taxonomy_term(kind=taxonomy.name, term=term.name) %}
{% for page in taxonomy_term.pages %}
{% if page.date %}
{% set_global has_date = true %}
{% break %}
{% endif %}
{% endfor %}
{% endif %}
{%- endfor -%}
While this solution works in most cases, I encountered an issue when term.name contains special characters, such as accents. When passing a term like "acción", the function fails with the following error:
Error: Reaseon: `get_taxonomy_term` received an unknown term: acción
I attempted to apply slugify to term.name before passing it to the function. However, this did not resolve the issue.
Could it be that get_taxonomy_term doesn’t correctly handle terms with special characters internally?