RSS feed with individual post images


#1

Hello, I did a search for this topic but wasn’t able to find an answer that worked for me. I’m trying to create a basic RSS template that supports images per blog post (5 images for 5 items in the list). I have a template being found and loaded properly (copied from the Hugo documentation site). My front-matter blog posts are looking for images = ["/img/image.jpg"]

Any help would be very appreciated.


#2

range for front matter parameters is very tricky and you seem to have your imgs in an array.

The order will always be random (Go templates do this)


#3

In the array, I only have 1 image per blog post.

I just want:

image1.jpg   |    blog title 1
                  description


image2.jpg   |    blog title 2
                  description

#4

In that case I think you can fetch and render these parameters using with


#5

Thanks but I’m having no luck unfortunately. If you have a code snippet that I can try out, that would be super helpful.


#6

Here is my custom RSS template. Obviously you need to customize it to reference the front matter parameters that are used in your project and change the range since you want to render 5 posts.

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>{{ .Site.Title }}</title>
    <link>{{ .Permalink }}</link>
    <description>{{ .Site.Title }}</description>
    <generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }}
    <language>{{.}}</language>{{end}}{{ with .Site.Author.email }}
    <managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }}
    <webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .Site.Copyright }}
    <copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }}
    <lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
    <atom:link href="{{.URL}}" rel="self" type="application/rss+xml" />
    {{ range first 15 (where .Data.Pages "Section" "blog") }}
    <item>
      <title>{{ .Title }}</title>
      <link>{{ .Permalink }}</link>
      <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
      {{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
      <guid>{{ .Permalink }}</guid>
      <description>{{ .Content }}</description>
    </item>
    {{ end }}
  </channel>
</rss>

#7

Thank you! That’s getting me somewhere!