Skip to content

Add support for RSS Feed#258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 26, 2024
23 changes: 21 additions & 2 deletions config/_default/hugo.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,9 @@
# An overview of hugo configuration files can be found at:
# https://gohugo.io/getting-started/configuration/#configure-server
#
# title: The title that appears in the navbar of every page. We have
# edited navbar.html to not show the title in the navbar of the home page.
title: "The Medley Interlisp Project"

# relativeURLs: Enable to force all relative URLs to be relative to content root
relativeURLs: false
Expand All@@ -21,7 +24,7 @@ enableRobotsTXT: false
assetDir: static

# Enable .GitInfo object for each page. This will give values to .Lastmod etc.
enableGitInfo: false
enableGitInfo: true

# Top Level Language defaults
# See languages.yaml for language specific values
Expand All@@ -35,7 +38,23 @@ enableMissingTranslationPlaceholders: true
disableKinds:
- taxonomy
- term
- RSS

outputs:
home:
- HTML
section:
- HTML

frontmatter:
date:
- date
- pubdate
- :git
- :default

outputFormats:
rss:
baseName: rss

# Code Highlighting configuration
# Not Used. Code highlighting is controlled using the highlighting
Expand Down
4 changes: 4 additions & 0 deletions config/_default/params.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,6 +79,10 @@ links:
url: "https://bsky.app/profile/interlisp.org"
icon: "fa-brands fa-bluesky"
desc: "We're on Bluesky too!"
- name: "RSS Feed"
url: "project/status/rss.xml"
icon: "fa fa-rss"
desc: "Subscribe to our feed for the latest updates"
# - name: "Stack Overflow"
# url: "https://stackoverflow.com/questions/tagged/graphviz"
# icon: "fab fa-stack-overflow"
Expand Down
3 changes: 3 additions & 0 deletions content/en/project/status/_index.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,9 @@
title: News and Status Reports
type: docs
weight: 2
outputs:
- html
- rss
aliases:
- /hugo/news/
- /medley/project/news/
Expand Down
64 changes: 64 additions & 0 deletions layouts/_default/rss.xml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, Hugo makes you do to a lot of work to produce an RSS feed for a given page.
Two questions:

  • If we want additional RSS feeds, will we need to copy-paste this code in all of them? Or can we place it in a central spot and include or import it where needed?
  • Can we change the name of the feed file from "index.xml" to just plain "rss" or "rss.xml"? For example, the feed URL is now "../project/status/index.xml". If Hugo permits it, could it instead be "../project/status/rss" or "../project/status/rss.xml"?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the feed's title and description are kind of phrased oddly.

Title:
News and Status Reports on The Medley Interlisp Project

Description:
Recent content in News and Status Reports on The Medley Interlisp Project

Looking at the Hugo configuration, I couldn't figure out a way to override these. They're not directly derived from the page title, which is News and Status Reports | The Medley Interlisp Project.

I'd love it if the RSS feed's title and description were both Updates from the Medley Interlisp Project, or maybe Medley Interlisp Project: Latest News, or something like that.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding additional RSS Feeds is straight forward.  It only requires an addition to the front matter of the page where we want to add it.  See content/en/project/status/_index.md  the following lines turn rss on for that page:

outputs: - html - rss

Any page whose front matter has those lines, will generate an rss feed.

One thing we should then consider, do we want the feed in the footer to reflect the root of our site?  Or, do we want it to remain the /project/status/rss.xml feed?  And, if that is the case, how do we make users aware of other potential locations where feeds are available? 

Making the footer feed vary by page would be confusing to users, that link should be stable.  Adding another RSS Feed link on pages that supports feed might also be confusing.  Identical icons in different places on the page that have different behaviors, one whose behavior varies by page.

The answer to your second question is yes, I'll push an update to this PR that supports renaming the feed from index.xml to rss.xml.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Page Title and Description are generated in layouts/_default/rss.xml

<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>

I can modify the phrasing to be more in line with your ask.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding additional RSS Feeds is straight forward. It only requires an addition to the front matter of the page where we want to add it. See content/en/project/status/_index.md the following lines turn rss on for that page:

outputs: - html - rss

Any page whose front matter has those lines, will generate an rss feed.

One thing we should then consider, do we want the feed in the footer to reflect the root of our site? Or, do we want it to remain the /project/status/rss.xml feed? And, if that is the case, how do we make users aware of other potential locations where feeds are available?

Making the footer feed vary by page would be confusing to users, that link should be stable. Adding another RSS Feed link on pages that supports feed might also be confusing. Identical icons in different places on the page that have different behaviors, one whose behavior varies by page.

I agree. We need to get in the practice of updating the project/status page whenever we make a substantive change to the site, so having project/statusgenerate the site-wide RSS feed would be fine, at least for now.

If we want individual per-page feeds in the future, we can figure out a place for those icons on the specific pages.

Let's start out with a single feed, visible site-wide, that contains updates to the project/status page.

The answer to your second question is yes, I'll push an update to this PR that supports renaming the feed from index.xml to rss.xml.

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
{{- $authorName := "" }}
{{- with .Site.Params.author }}
{{- if reflect.IsMap . }}
{{- with .name }}
{{- $authorName = . }}
{{- end }}
{{- else }}
{{- $authorName = . }}
{{- end }}
{{- end }}

{{- $pctx := . }}
{{- if .IsHome }}{{ $pctx = .Site }}{{ end }}

<!-- Iterate through all sections and include both sections and
pages in the rss feed. The default rss.xml only includes
pages. -->
{{- $pages := slice }}
{{- $mainPages := where .Pages "Kind" "in" (slice "page" "section") }}
{{- $pages = $pages | union $mainPages }}

{{- range .Sections }}
{{- $sectionPages := where .Pages "Kind" "in" (slice "page" "section") }}
{{- $pages = $pages | union $sectionPages }}
{{- range .Sections }}
{{- $subSectionPages := where .Pages "Kind" "in" (slice "page" "section") }}
{{- $pages = $pages | union $subSectionPages }}
{{- end }}
{{- end }}

{{- $limit := .Site.Config.Services.RSS.Limit }}
{{- if ge $limit 1 }}
{{- $pages = $pages | first $limit }}
{{- end }}

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Updates from the Medley Interlisp Project</title>
<link>{{ .Permalink }}</link>
<description>Updates from the Medley Interlisp Project</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 $pages }}
<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>
{{ range .Params.tags }}
<category>{{ . }}</category>
{{ end }}
</item>
{{ end }}
</channel>
</rss>
17 changes: 17 additions & 0 deletions layouts/partials/footer/links.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
<ul class="td-footer__links-list">
{{ range . }}
{{ if eq .name "RSS Feed" }}
<li class="td-footer__links-item" data-bs-toggle="tooltip" title="RSS" aria-label="RSS">
<a target="_blank" rel="noopener" href="{{ absURL .url }}" aria-label="RSS">
<i class="fas fa-rss"></i>
</a>
</li>
{{ else }}
<li class="td-footer__links-item" data-bs-toggle="tooltip" title="{{ .name }}" aria-label="{{ .name }}">
<a target="_blank" rel="noopener" href="{{ .url }}" aria-label="{{ .name }}">
<i class="{{ .icon }}"></i>
</a>
{{ end }}
{{ end }}

</ul>
75 changes: 75 additions & 0 deletions layouts/partials/navbar.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
{{ $cover := and
(.HasShortcode "blocks/cover")
(not .Site.Params.ui.navbar_translucent_over_cover_disable)
-}}
{{ $baseURL := urls.Parse $.Site.Params.Baseurl -}}

<nav class="td-navbar js-navbar-scroll
{{- if $cover }} td-navbar-cover {{- end }}" data-bs-theme="dark">
<div class="container-fluid flex-column flex-md-row">
<a class="navbar-brand" href="{{ .Site.Home.RelPermalink }}">
{{- /**/ -}}
<span class="navbar-brand__logo navbar-logo">
{{- if ne .Site.Params.ui.navbar_logo false -}}
{{ with resources.Get "icons/logo.svg" -}}
{{ ( . | minify).Content | safeHTML -}}
{{ end -}}
{{ end -}}
</span>
{{- /**/ -}}
<span class="navbar-brand__name">
<!-- Place the site title on every page header, except the home page -->
{{ if not .IsHome }}
{{ .Site.Title }}
{{ end }}

</span>
{{- /**/ -}}
</a>
<div class="td-navbar-nav-scroll ms-md-auto" id="main_navbar">
<ul class="navbar-nav">
{{ $p := . -}}
{{ range .Site.Menus.main -}}
<li class="nav-item">
{{ $active := or ($p.IsMenuCurrent "main" .) ($p.HasMenuCurrent "main" .) -}}
{{ $href := "" -}}
{{ with .Page -}}
{{ $active = or $active ( $.IsDescendant .) -}}
{{ $href = .RelPermalink -}}
{{ else -}}
{{ $href = .URL | relLangURL -}}
{{ end -}}
{{ $isExternal := ne $baseURL.Host (urls.Parse .URL).Host -}}
<a {{/**/ -}}
class="nav-link {{- if $active }} active {{- end }}" {{/**/ -}}
href="{{ $href }}"
{{- if $isExternal }} target="_blank" rel="noopener" {{- end -}}
>
{{- .Pre -}}
<span>{{ .Name }}</span>
{{- .Post -}}
</a>
</li>
{{ end -}}
{{ if .Site.Params.versions -}}
<li class="nav-item dropdown d-none d-lg-block">
{{ partial "navbar-version-selector.html" . -}}
</li>
{{ end -}}
{{ if (gt (len .Site.Home.Translations) 0) -}}
<li class="nav-item dropdown d-none d-lg-block">
{{ partial "navbar-lang-selector.html" . -}}
</li>
{{ end -}}
{{ if .Site.Params.ui.showLightDarkModeMenu -}}
<li class="td-light-dark-menu nav-item dropdown">
{{ partial "theme-toggler" . }}
</li>
{{ end -}}
</ul>
</div>
<div class="d-none d-lg-block">
{{ partial "search-input.html" . }}
</div>
</div>
</nav>
13 changes: 13 additions & 0 deletions layouts/partials/page-meta-lastmod.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
{{ if and .GitInfo .Site.Params.github_repo -}}
<div class="td-page-meta__lastmod">
<!--
Disable showing of Git Commit info in the footer
{{ T "post_last_mod" }} {{ .Lastmod.Format .Site.Params.time_format_default -}}
{{ with .GitInfo }}: {{/* Trim WS */ -}}
<a data-proofer-ignore href="{{ $.Site.Params.github_repo }}/commit/{{ .Hash }}">
{{- .Subject }} ({{ .AbbreviatedHash }}) {{- /* Trim WS */ -}}
</a>
{{- end }}
-->
</div>
{{ end -}}
close