[SOLVED] RSS output issues: character rendering and relative urls

I have an RSS template here:

This outputs the following file here (I recommend to view-source):

This is the RSS validation of that output:

Question 1:
On Line 20 of the RSS template I have <content:encoded><![CDATA[...... The < before the ! in the template gets rendered to &lt; in the output index.xml. The same happens for the same character on Line 21. Why is this happening? I can force it to render as an < in the output xml if I use {{ "<" | safeHTML }} but that’s silly to have it there when it’s not supposed to be necessary. Why is Hugo converting it to to code form?

Question 2:
When things are working fine, the RSS validator recommends not having any relative urls in the content. The relative urls are from markdown image links in content files. I thought setting canonifyURLs = true in config.toml would force all URLs referenced to become absolute urls, but it doesn’t for those graphics. Is there a way to force that to happen? I want to keep the url in the body of the markdown file relative since that’s the best practice, but I want the output to be absoluteURL. I know I could probably do something like ![Graphic]({{ "images/graphic.jpg" | absURL }}) but is that the only way?


I know why one would use CDATA, but why are you? Do you have a special requirement for it? Because you could remove it and one of yer problems is solved. :slight_smile:

I use the default spec, modified to show full content, rather than the summary.

The second issue may be something we need to bring up as a bug.

I saw that it would work if I didn’t have CDATA but all the recommendations online seemed to say to use CDATA if you were including styled html. What is your understanding on it?

Don’t include inline styles. It is a feed, it is meant to be styled however the reader prefers.

But you ought to search the forums as well, for instance there is:

I checked, it fixes your feed issue. The same doesn’t work for summary, but you may want to remove that and make the template simpler.

I didn’t mean inline styles in the css sense. I meant html markup.

anyway, i removed the CDATA tags and added the pipe to html like you had, and it worked, not only that but also the relative urls for the graphics were fixed too. so i guess that helped!

Glad that worked. Mark as solved, if you can.

What is “styled html”? I want to know I am on the same page.

A couple quick things:

  1. RSS and ATOM are different XML namespaces, no?
  2. safeHTML may seem inconvenient, but it’s a matter of Golang template’s normal behavior to escape possibly pernicious ML, JS, etc…

I mean html with html tags, bold, italic, links, etc.

They play nice enough together on the same xml, it seems.

CDATA is one way of doing, encoding it is another (which is what we are doing, via piping to a frontmatter).

Are you referring to <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">?

That is a shortcut, so RSS will render as a valid Atom feed, for Atom readers.