MunifTanjim / minimo

Minimo - Minimalist theme for Hugo
https://minimo.netlify.app
MIT License
546 stars 220 forks source link

RSS template #69

Closed Fastidious closed 6 years ago

Fastidious commented 6 years ago

Since I couldn't find the RSS template, I am assuming the theme is using Hugo's default, correct? It seems to be including the blog, and everything else (all pages) for me. No good.

MunifTanjim commented 6 years ago

Hugo's default RSS adheres to the RSS 2.0 Specification and is sufficient for most use cases.

If you need a customized RSS feed, you'll need to modify it yourself.

Hugo's documentation about RSS Templates is a good place to start researching.

Fastidious commented 6 years ago

@MunifTanjim I tried, yet, I couldn't make it so only the content of a specific section shows on RSS. I have:

content/
        blog/
        pages/

And used:

{{ range first 45 (where .Data.Pages "Section" "blog") }}

On the RSS, and still things under pages show on the feed. I am about to disable feeds all together. :-(

My full index.xml template, under /layouts/_default/ is:

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>{{ if eq  .Title  .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
    <link>{{ .Permalink }}</link>
    <description>Recent content {{ if ne  .Title  .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .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 }}
    {{ with .OutputFormats.Get "RSS" }}
        {{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
    {{ end }}
    {{ range first 45 (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>{{ .Summary | html }}</description>
    </item>
    {{ end }}
  </channel>
</rss>

I have tried replacing .Data.Pages for .Site.RegularPages and get same results.

MunifTanjim commented 6 years ago

You can conditionally include the RSSLink in the <head> (using something like this):

{{ if ( and .RSSLink ( eq .Section "blog" ) ) }}
  <link href="{{ .RSSLink }}" rel="alternate" type="application/rss+xml" title="{{ .Site.Title }}" />
{{ end }}

And delete the unwanted .xml rss feeds inside the public directory after generating the site with hugo.

Fastidious commented 6 years ago

That works if I go to /blog/, but doesn't when going to / (which still shows the unwanted entries). I do not manually generate the site, it happens upon commit (post-receive hook). So annoying! I will continue researching and trying to see if I can find a solution. If I do, I will come back to post it.

Fastidious commented 6 years ago

OK, I got it to work by removing the date on the pages I did not want to be shown on RSS. Since they are not blog entries, they really didn't need date/time. Yay!

Fastidious commented 6 years ago

Happy on how it is looking now: https://collantes.us/ :-)