getzola / zola

A fast static site generator in a single binary with everything built-in. https://www.getzola.org
https://www.getzola.org
MIT License
12.97k stars 919 forks source link

Zola 0.19.1 broke `get_url` #2561

Open apiraino opened 4 days ago

apiraino commented 4 days ago

Bug Report

Zola 0.19.1 broke the CI building my website.

$ zola serve
Error: Failed to serve the site
Error: Failed to render page '..../content/some-blog-post.md'
Error: Reason: Failed to render 'page.html'
Error: Reason: Function call 'get_url' failed
Error: Reason: `get_url` requires a `path` argument with a string value

Environment

Zola version: 0.19.1, Debian/trixie (current "testing" release) on Linux x86_64

Expected Behavior

get_url is supposed to keep on accepting variables, correct? I assume this is a regression because it is nowhere mentioned in the changelog (unless I am missing something).

Until Zola 0.19.0 it used to work.

Current Behavior

I use the after-dark theme where get_url is invoked with a config variable (see relevant code).

Since Zola 0.19.1 get_url only accepts strings (as the error says). If I change the template to using a string, the error disappears.

Step to reproduce

Rendering this template will emit an error:

<!DOCTYPE html>
<html lang="en">
    <head>
        <link href="{{ get_url(path=config.feed_filenames) | safe }}">
    </head>
    <body></body>
</html>
Keats commented 4 days ago

get_url only accepts strings. config.feed_filenames is an array

apiraino commented 4 days ago

Then if I read the git history correctly, this breaking change probably comes from #2477 ? If yes, why do I not get this error in zola 0.19?

I feel that this breaking change (config parameter feed_filenames) was not prominent enough. By looking at the list on linked issues and patches, this will break themes/CI, no?

LunarEclipse363 commented 3 days ago

The solution is to use a for loop:

<!DOCTYPE html>
<html lang="en">
    <head>
        {% for feed_filename in config.feed_filenames %}
        <link href="{{ get_url(path=feed_filename) | safe }}"/>
        {% endfor %}
    </head>
    <body></body>
</html>

Although in this specific case I would just write out each of the feeds manually because otherwise you have to handle type and title parameters in the loop which could get complicated (that is if you provide those, you really should for linking feeds), i.e.

<link rel="alternate" type="application/atom+xml" title="Example Blog - Atom Feed" href="{{ get_url(path="/atom.xml", trailing_slash=false) }}"/>
<link rel="alternate" type="application/rss+xml" title="Example Blog - RSS Feed" href="{{ get_url(path="/rss.xml", trailing_slash=false) }}"/>