Unable to get URLs canonified in RSS feed <description> tag

I’m trying to make RSS feed <description> show hyperlinks. I made some modification to the embedded rss.xml but it seems like links are not canonified.

My modification to hugo’s embedded template

  1. hugo new site test.
  2. Download the embedded RSS template to layouts/_default/rss.xml.
  3. Replace the <description> line with:
    <description>{{ (printf "<![CDATA[%s]]>" .Content) | safeHTML }}</description>
    
  4. Add a new post file contents/post/a.md:
    +++
    title = 'First post'
    date = 2024-06-25T14:23:23-07:00
    +++
    
    Hello, link to [b](./b).
    
  5. Run hugo.

Output

In the generated public/index.xml file, the description tag looks like the following:

      <description><![CDATA[<p>Hello, link to <a href="./b">b</a>.</p>
]]></description>

Question

How can I make the output above to canonify the link ./b?

Additional Context

You need to create link and image render hooks for the rss output format that produce absolute instead of relative URLs.

You also need link and image render hooks for the html output format, and the easiest way to do that is to enable the embedded link render hook and the embedded image render hook.

Here’s a working example:

git clone --single-branch -b hugo-forum-topic-50428 https://github.com/jmooring/hugo-testing hugo-forum-topic-50428
cd hugo-forum-topic-50428
hugo server

Files of interest:

  • layouts/_default/_markup/render-link.rss.xml
  • layouts/_default/_markup/render-image.rss.xml
  • layouts/_default/rss.xml
  • hugo.toml

The files above are minimally modified copies of the embedded templates of the same name:

1 Like

Thanks! Do you think the two render hooks are worth included as embedded templates? After all, links in RSS shouldn’t be relative.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.