Skip to content

Commit 8cde290

Browse files
Merge pull request #855 from TineoC/fix/restore-rss-template
fix: own the RSS template and emit a single blog feed
2 parents 9dbe03f + 690bf43 commit 8cde290

4 files changed

Lines changed: 133 additions & 0 deletions

File tree

hugo.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ disableKinds:
1616
permalinks:
1717
blog: '/:section/:year/:month/:day/:slug/'
1818

19+
# Be explicit about the output formats. We only want an RSS feed for the home
20+
# page, rendered by layouts/index.rss.xml. Leaving RSS on `section` would emit a
21+
# feed for every section, none of which carry dates, and leaving it unset lets
22+
# Hugo's built-in template range over every page on the site.
23+
# Mirrors https://github.com/kubernetes/website/blob/main/hugo.toml#L84-L88
24+
outputs:
25+
home:
26+
- HTML
27+
- RSS
28+
page:
29+
- HTML
30+
section:
31+
- HTML
32+
1933
# Image processing configuration.
2034
imaging:
2135
resampleFilter: CatmullRom
@@ -24,6 +38,9 @@ services:
2438
googleAnalytics:
2539
# Fake ID in support of [params.ui.feedback]. The real GA ID is set in the Netlify config.
2640
id: UA-00000000-0
41+
rss:
42+
# Number of items in the feed, read by layouts/index.rss.xml.
43+
limit: 50
2744

2845
# Hugo internal caching
2946
caches:

layouts/blog/baseof.html

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{{/*
2+
Copy of node_modules/docsy/layouts/blog/baseof.html, changed in one place: the
3+
RSS button reads site.Home instead of .CurrentSection.
4+
5+
hugo.yaml sets `section: [HTML]`, so Docsy's `.CurrentSection.OutputFormats.Get
6+
"rss"` is nil and the button never renders. This site emits a single feed, from
7+
the home page, via layouts/index.rss.xml — so the button points there.
8+
9+
Mirrors kubernetes/website, which hit the same wall and solved it the same way:
10+
https://github.com/kubernetes/website/blob/main/layouts/partials/blog-meta-links.html
11+
12+
Re-diff against Docsy's copy on the next theme bump; nothing else here is ours.
13+
*/}}
14+
<!doctype html>
15+
<html itemscope itemtype="http://schema.org/WebPage" lang="{{ .Site.Language.Lang }}" class="no-js">
16+
<head>
17+
{{ partial "head.html" . }}
18+
{{ with site.Home.OutputFormats.Get "rss" -}}
19+
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}" title="{{ site.Title }}">
20+
{{ end -}}
21+
</head>
22+
<body class="td-{{ .Kind }} td-blog {{- with .Page.Params.body_class }} {{ . }}{{ end }}">
23+
<header>
24+
{{ partial "navbar.html" . }}
25+
</header>
26+
<div class="container-fluid td-outer">
27+
<div class="td-main">
28+
<div class="row flex-xl-nowrap">
29+
<aside class="col-12 col-md-3 col-xl-2 td-sidebar d-print-none">
30+
{{ partial "sidebar.html" . }}
31+
</aside>
32+
<aside class="d-none d-xl-block col-xl-2 td-sidebar-toc d-print-none">
33+
{{ partial "page-meta-links.html" . }}
34+
{{ partial "toc.html" . }}
35+
{{ partial "taxonomy_terms_clouds.html" . }}
36+
</aside>
37+
<main class="col-12 col-md-9 col-xl-8 ps-md-5 pe-md-4" role="main">
38+
{{ with site.Home.OutputFormats.Get "rss" -}}
39+
<a class="td-rss-button" title="RSS" href="{{ .Permalink | safeURL }}" target="_blank" rel="noopener">
40+
<i class="fa-solid fa-rss" aria-hidden="true"></i>
41+
</a>
42+
{{ end -}}
43+
{{ block "main" . }}{{ end }}
44+
</main>
45+
</div>
46+
</div>
47+
{{ partial "footer.html" . }}
48+
</div>
49+
{{ partial "scripts.html" . }}
50+
</body>
51+
</html>

layouts/index.rss.xml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Home-page RSS feed, inspired from kubernetes/website's layouts/index.rss.xml:
3+
https://github.com/kubernetes/website/blob/main/layouts/index.rss.xml
4+
5+
The item count is read from services.rss.limit in hugo.yaml rather than
6+
hardcoded. That key is 0 when unset and Hugo treats `first 0` as unlimited,
7+
so the fallback below keeps a missing key from restoring the whole-site feed
8+
this template exists to prevent.
9+
10+
This site owns its feed template rather than inheriting one from the theme.
11+
Docsy shipped layouts/_default/list.rss.xml through v0.9.1 and removed it in
12+
v0.10.0 (google/docsy#1948); with no local template, Hugo fell back to its
13+
built-in RSS, which ranges over every regular page with no section filter and
14+
no item cap. kubernetes/website has never been exposed to that, having owned
15+
this file since it moved to Hugo in 2018:
16+
https://github.com/kubernetes/website/commit/7f3b633a
17+
18+
Paired with the `outputs` block in hugo.yaml, which emits RSS for the home
19+
page only, mirroring:
20+
https://github.com/kubernetes/website/blob/main/hugo.toml#L84-L88
21+
Section feeds are deliberately not generated.
22+
*/}}
23+
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
24+
<channel>
25+
<title>{{ site.Title }} Blog</title>
26+
<link>{{ .Permalink }}</link>
27+
<description>The Kubernetes contributor blog is used by the project to communicate community reports, contributor news, and any updates that might be relevant to people contributing to Kubernetes.</description>
28+
<generator>Hugo -- gohugo.io</generator>{{ with site.LanguageCode }}
29+
<language>{{.}}</language>{{end}}{{ with site.Author.email }}
30+
<managingEditor>{{.}}{{ with site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with site.Author.email }}
31+
<webMaster>{{.}}{{ with site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with site.Copyright }}
32+
<copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }}
33+
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
34+
<image>
35+
<url>https://raw.githubusercontent.com/kubernetes/kubernetes/master/logo/logo.png</url>
36+
<title>The Kubernetes project logo</title>
37+
<link>{{ .Permalink }}</link>
38+
</image>
39+
{{ with .OutputFormats.Get "RSS" }}
40+
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
41+
{{ end }}
42+
{{- $limit := site.Config.Services.RSS.Limit }}
43+
{{- if lt $limit 1 }}{{ $limit = 50 }}{{ end }}
44+
{{ range first $limit (where site.RegularPages "Type" "in" (slice "blog")) }}
45+
<item>
46+
<title>{{ .Title }}</title>
47+
<link>{{ .Permalink }}</link>
48+
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
49+
{{ with site.Author.email }}<author>{{.}}{{ with site.Author.name }} ({{.}}){{end}}</author>{{end}}
50+
<guid>{{ .Permalink }}</guid>
51+
<description>
52+
{{ $img := (.Resources.ByType "image").GetMatch "*featured*" }}
53+
{{ with $img }}
54+
{{ $img := .Resize "640x" }}
55+
{{ printf "<![CDATA[<img src=\"%s\" width=\"%d\" height=\"%d\"/>]]>" $img.Permalink $img.Width $img.Height | safeHTML }}
56+
{{ end }}
57+
{{ .Content | transform.XMLEscape | safeHTML }}
58+
</description>
59+
</item>
60+
{{ end }}
61+
</channel>
62+
</rss>

static/_redirects

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@
4848
/summit/unconf /events/2024/kcsna 302
4949
/summit/notes https://drive.google.com/drive/folders/1j3i9I4a3lbmjqQNTYKxK0Gc6JgooDn14 302
5050
/summit/sched /events/2024/kcsna/schedule 302
51+
52+
# Section feeds are no longer generated; the blog feed lives at /index.xml.
53+
/blog/index.xml /index.xml 301

0 commit comments

Comments
 (0)