Skip to content

Commit

Permalink
optimise/rearrange output formats for RSS, add RSS feed per section
Browse files Browse the repository at this point in the history
  • Loading branch information
yktoo committed Sep 13, 2024
1 parent f186efb commit 411e3a5
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 57 deletions.
12 changes: 6 additions & 6 deletions config/_default/hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,24 @@ taxonomies:
videotrack: videotracks

outputs:
# Only enable RSS generation on the home page. Also add RSS for All Languages and a redirect file
home: [HTML, RSS, RSS-ALL, REDIR]
section: [HTML]
taxonomy: [HTML]
# Only enable RSS generation on the homepage and section pages. Also add RSS for All Languages and a redirect file
home: [html, rss, rss-all, redir]
section: [html, rss]
taxonomy: [html]

mediaTypes:
text/bare:
suffixes:

outputFormats:
RSS-ALL:
rss-all:
mediaType: application/rss+xml
baseName: index-all
isHTML: false
isPlainText: false
noUgly: true
rel: alternate
REDIR:
redir:
mediatype: text/bare
baseName: _redirects
isPlainText: true
Expand Down
4 changes: 1 addition & 3 deletions cypress/e2e/site.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/// <reference types="cypress" />

import {Paths} from "../support/util";
import { Paths } from '../support/util';

context('Site', () => {

Expand Down
1 change: 1 addition & 0 deletions layouts/_default/_feed-description.rss-all.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- .Site.Params.description -}}
1 change: 1 addition & 0 deletions layouts/_default/_feed-description.rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- .Site.Params.description -}}
3 changes: 3 additions & 0 deletions layouts/_default/_feed-items.rss-all.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- range first .Site.Params.rssLimit (where (where .Site.AllPages ".IsPage" true) "Type" "post") }}
{{- .Render "_rss-item" }}
{{- end -}}
3 changes: 3 additions & 0 deletions layouts/_default/_feed-items.rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- range first .Site.Params.rssLimit (where .Site.RegularPages "Type" "post") }}
{{- .Render "_rss-item" }}
{{- end -}}
1 change: 1 addition & 0 deletions layouts/_default/_feed-title.rss-all.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- .Site.Title }} | {{ T "blog" -}}
1 change: 1 addition & 0 deletions layouts/_default/_feed-title.rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- .Site.Title }} | {{ T "postsCurLang" }} | {{ T "blog" -}}
7 changes: 6 additions & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@

<!-- RSS feed -->
{{ with .OutputFormats.Get "RSS" -}}
{{ printf "<link rel=%q type=%q href=%q title=%q/>" .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
{{ printf "<link rel=%q type=%q href=%q title=%q/>"
.Rel
.MediaType.Type
.Permalink
($.Title | default $.Site.Title)
| safeHTML }}
{{ end -}}

<!-- Google Analytics -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ .Site.Title }} | {{ T "blog" }}</title>
<title>{{ .Render "_feed-title" }}</title>
<description>{{ .Render "_feed-description" }}</description>
<link>{{ .Permalink }}</link>
<description>{{ .Site.Params.description }}</description>
<generator>Hugo {{ hugo.Version }}</generator>
<generator>Hugo</generator>
{{- with .Site.LanguageCode }}<language>{{ . }}</language>{{ end }}
{{- with .Site.Params.author }}
<managingEditor>[email protected] ({{ . }})</managingEditor>
<webMaster>[email protected] ({{ . }})</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-ALL" }}{{ printf `<atom:link href=%q rel="self" type=%q />` .Permalink .MediaType | safeHTML }}{{ end }}
{{- range first .Site.Params.rssLimit (where (where .Site.AllPages ".IsPage" true) "Type" "post") }}
{{- .Render "rss-item" }}
{{- end -}}
{{ with .OutputFormats.Get "rss-all" }}{{ printf `<atom:link href=%q rel="self" type=%q />` .Permalink .MediaType | safeHTML }}{{ end }}
{{ .Render "_feed-items" }}
</channel>
</rss>
12 changes: 5 additions & 7 deletions layouts/_default/index.rss.xml → layouts/_default/list.rss.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ .Site.Title }} | {{ T "blog" }}: {{ T "postsCurLang" }}</title>
<title>{{ .Render "_feed-title" }}</title>
<description>{{ .Render "_feed-description" }}</description>
<link>{{ .Permalink }}</link>
<description>{{ .Site.Params.description }}</description>
<generator>Hugo {{ hugo.Version }}</generator>
<generator>Hugo</generator>
{{- with .Site.LanguageCode }}<language>{{ . }}</language>{{ end }}
{{- with .Site.Params.author }}
<managingEditor>[email protected] ({{ . }})</managingEditor>
<webMaster>[email protected] ({{ . }})</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 .Site.Params.rssLimit (where .Site.RegularPages "Type" "post") }}
{{- .Render "rss-item" }}
{{- end -}}
{{ with .OutputFormats.Get "rss" }}{{ printf `<atom:link href=%q rel="self" type=%q />` .Permalink .MediaType | safeHTML }}{{ end }}
{{ .Render "_feed-items" }}
</channel>
</rss>
2 changes: 1 addition & 1 deletion layouts/blog/subscribe.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h5 class="mt-2">{{ T (print "posts_" .Language) }}</h5>
<li>
<h5 class="mt-2">{{ T "postsAllLangs" }}</h5>
<ul>
{{ with (.GetPage "/" ).OutputFormats.Get "RSS-ALL" }}
{{ with (.GetPage "/" ).OutputFormats.Get "rss-all" }}
<li><a href="https://feedly.com/i/subscription/feed%2F{{ .Permalink | querify `` | strings.TrimPrefix `=` }}">{{ T "subscribeInFeedly" }}</a></li>
<li><a href="{{ .Permalink }}">{{ T "subscribeByRSS" }}</a></li>
{{ end }}
Expand Down
27 changes: 27 additions & 0 deletions layouts/post/_rss-item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<item>
<title>{{ partial "page-title" . }}</title>
<link>{{ .Permalink }}?utm_source=rss&amp;utm_medium=feed_{{ .Language }}&amp;utm_campaign=nix</link>
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
<author>[email protected] ({{ .Params.author | default .Site.Params.author }})</author>
<guid isPermaLink="true">{{ .Permalink }}</guid>
<description>
<!-- If there's an image given -->
{{- $page := . -}}
{{- with .Params.image -}}
{{- $url := . -}}
<!-- If it isn't a URL starting with "http(s)://" or an absolute path, consider it a page resource -->
{{- if findRE "^(/|http(s?)://)" $url -}}
{{- $url = absURL $url -}}
{{- else -}}
{{- $url = ($page.Resources.GetMatch $url).Permalink -}}
{{- end -}}
<!-- Insert image tag -->
{{- printf `<img style="width: 500px; height: auto;" src=%q alt="Post image"><br><br>` $url -}}
{{- end -}}
<!-- Put post summary or description: logic borrowed from layouts/post/list-item.html -->
{{- $summary := .Params.description | .RenderString | default .Summary | replaceRE "(?s)<figure\\b.*?/figure>" "" | replaceRE "(?s)<div\\b.*/div>" "" }}
{{- if in $summary "<p>" }}{{ $summary }}{{ else }}{{ printf "<p>%s</p>" $summary | safeHTML }}{{ end }}
<!-- Read On link -->
{{- printf `<p><a href=%q style="padding: 12px; background-color: #089664; color: #ffffff; text-decoration: none;">%s</a></p>` .Permalink (T "readOn") -}}
</description>
</item>
27 changes: 0 additions & 27 deletions layouts/post/rss-item.xml

This file was deleted.

1 change: 1 addition & 0 deletions layouts/series/_feed-description.rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- T "blog" }}: {{ .Title }} — {{ .Params.description -}}
3 changes: 3 additions & 0 deletions layouts/series/_feed-items.rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- range first .Site.Params.rssLimit .Pages }}
{{- .Render "_rss-item" }}
{{- end -}}
1 change: 1 addition & 0 deletions layouts/series/_feed-title.rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- .Title }} | {{ T "blog" -}}
23 changes: 18 additions & 5 deletions layouts/series/list.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
{{ define "heading" }}<h1>{{ T "series" }}: {{ .Title }}</h1>{{ end }}
{{- define "title" }}{{ .Title | markdownify | plainify }} | {{ T "series" }} | {{ T "blog" }} | {{ .Site.Title }}{{ end }}

{{ define "secondary-navbar" }}
{{ partial "blog/navbar" . }}
{{- define "heading" }}
<h1>
<!-- Heading -->
{{- T "blog" }}: {{ .Title -}}
<!-- RSS -->
{{- with .OutputFormats.Get "RSS" }}
<a class="btn btn-link" href="{{ .Permalink }}" title="{{ T `subscribeByRSS` }}">
<i class="fas fa-rss-square colourise fa-2x"></i>
</a>
{{- end }}
</h1>
{{ end }}

{{ define "main" }}
{{- define "secondary-navbar" }}
{{- partial "blog/navbar" . }}
{{- end }}

{{- define "main" }}
<!-- Description -->
{{- with .Params.description }}
<p class="series-description">{{ . | $.RenderString }}</p>
Expand All @@ -28,4 +41,4 @@
<div class="blog-paginator">
{{ template "_internal/pagination.html" . }}
</div>
{{ end }}
{{- end }}

0 comments on commit 411e3a5

Please sign in to comment.