Skip to content

Commit

Permalink
templates: add base URL for feed content (getzola#2190)
Browse files Browse the repository at this point in the history
Relative links in the entry content do not currently have a base URI, so
will be resolved relative to the feed URI:

Given an entry with the content:

    <a href="some-resource.bin">

And URIS of:

 * entry: https://example.org/blog/some-entry/
 * feed:  https://example.org/atom.xml

The link URI will end up as:

    https://example.org/some-resource.bin

rather than the URI that ends up resolved in the rendered page:

   https://example.org/blog/some-entry/some-resource.bin

The atom and RSS formats allow for an xml:base attribute (itself
specified in [1]) to provide a base URI of a subset of a document. This
change adds xml:base attributes to each entry, using the page permalink.

This gives us something equivalent to:

    <entry>
     <content xml:base="https://example.org/blog/some-entry/">
      <![CDATA[
       <a href="some-resource.bin">
      ]]>
     </content>
    </entry>

[1]: https://www.w3.org/TR/xmlbase/

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
  • Loading branch information
jk-ozlabs authored Apr 23, 2023
1 parent 6a5c241 commit c48b61a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/templates/src/builtins/atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{% if page.summary %}
<summary type="html">{{ page.summary }}</summary>
{% else %}
<content type="html">{{ page.content }}</content>
<content type="html" xml:base="{{ page.permalink | escape_xml | safe }}">{{ page.content }}</content>
{% endif %}
</entry>
{%- endfor %}
Expand Down
2 changes: 1 addition & 1 deletion components/templates/src/builtins/rss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</author>
<link>{{ page.permalink | escape_xml | safe }}</link>
<guid>{{ page.permalink | escape_xml | safe }}</guid>
<description>{% if page.summary %}{{ page.summary }}{% else %}{{ page.content }}{% endif %}</description>
<description xml:base="{{ page.permalink | escape_xml | safe }}">{% if page.summary %}{{ page.summary }}{% else %}{{ page.content }}{% endif %}</description>
</item>
{%- endfor %}
</channel>
Expand Down

0 comments on commit c48b61a

Please sign in to comment.