From a Newsletter to Hugo: Handling the content of an RSS feed

Hi there,

I would like to display the content of a Newsletter on a website.

The newsletter is successfully converted to an RSS feed, but I can’t find the way to properly format the content of the feed, as you can see in this demo.

Here is the RSS feed: Testing Hugo

The shortcode:

{{ with resources.GetRemote "https://kill-the-newsletter.com/feeds/70nytask22i06lyc.xml" | transform.Unmarshal }}
  <ul>
    {{ range .entry }}
    <li>
      <a href="{{ .link }}">{{ .title }}</a>
    </li>
    {{ .content  }}
    {{ end }}
  </ul>
{{ end }}

The actual result, with formatting issues.

I tried to convert {{ .content }} with several functions (combining | safeHTML, plainify and unescapeHTML) but errors appear (I can give details here) and I’m lost now. Help is welcome!

Related topic: How to embed contents from external feed RSS on a page of my Hugo website (PaperMod theme)

template code
{{ $u := "https://kill-the-newsletter.com/feeds/70nytask22i06lyc.xml" }}
{{ with resources.GetRemote $u }}
  {{ with .Err }}
    {{ errorf "%s" . }}
  {{ else }}
    {{ with . | unmarshal }}
      {{ range .entry }}

        <p>Title: {{ .title }}</p>
        <p>Author: {{ .author.name }}</p>
        <p>Updated: {{ .updated | time.AsTime | time.Format ":date_long" }}</p>
        <p>Link: <a href="{{ index .link `-href` }}">Link</a></p>
        {{ index .content "#text" | safeHTML }}

      {{ end }}
    {{ end }}
  {{ end }}
{{ else }}
  {{ errorf "Unable to get remote resource %q" $u }}
{{ end }}

rendered


But the content in the feed contains html and body elements, so the resulting HTML is invalid.

1 Like

It works perfectly, thanks a lot!

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