🐛 fix(feed): styling now works in all website paths

The feed's stylesheet now uses the base URL from Zola's configuration,
ensuring correct stylesheet loading in all contexts (root path,
subdirectories, and subdomains).

Previously, the stylesheet URLs could break when feeds were in
subdirectories.
This commit is contained in:
welpo 2025-02-16 09:28:57 +01:00
parent 402965786b
commit 45fe170467
No known key found for this signature in database
GPG key ID: A2F978CF4EC1F5A6
2 changed files with 3 additions and 7 deletions

View file

@ -14,13 +14,8 @@
<meta charset="utf-8"/>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<!-- The base URL is assumed to be the first URL in the sitemap. -->
<xsl:variable name="baseUrl" select="(sitemap:urlset/sitemap:url)[1]/sitemap:loc"/>
<!-- Remove http[s]:// -->
<xsl:variable name="baseUrlWithoutProtocol" select="substring-after($baseUrl, '://')"/>
<!-- Remove trailing slash -->
<xsl:variable name="clean_base_url" select="substring-before($baseUrlWithoutProtocol, '/')"/>
<link rel="stylesheet" href="{$baseUrl}main.css"/>
<xsl:variable name="baseUrl" select="/atom:feed/tabi:metadata/tabi:base_url"/>
<link rel="stylesheet" href="{$baseUrl}/main.css"/>
<link rel="stylesheet" href="{/atom:feed/atom:link[@rel='extra-stylesheet']/@href}" />
</head>

View file

@ -9,6 +9,7 @@
<?xml-stylesheet href="{{ get_url(path='/feed_style.xsl', trailing_slash=false) | safe }}" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{{ lang }}">
<tabi:metadata xmlns:tabi="https://github.com/welpo/tabi">
<tabi:base_url>{{ config.base_url }}</tabi:base_url>
<tabi:separator>
{{ config.extra.separator | default(value="•") }}
</tabi:separator>