From 26b401631cc563d267cce23d48b4dcdc78118628 Mon Sep 17 00:00:00 2001 From: fundor333 Date: Thu, 29 May 2025 03:12:31 +0200 Subject: [PATCH] Adds Atom feed generation Implements Atom feed generation for blog posts, photos, and the main site feed. This allows users to subscribe to content using Atom-compatible feed readers. Includes an XSLT stylesheet for rendering Atom feeds in a human-readable format in browsers. --- config/_default/hugo.yaml | 14 ++++++ config/_default/params.yaml | 5 ++ content/feeds.md | 8 ++-- layouts/_default/list.atom.xml | 60 ++++++++++++++++++++++++ layouts/partials/custom-head.html | 4 ++ static/atom.xsl | 77 +++++++++++++++++++++++++++++++ static/rss.xsl | 4 +- 7 files changed, 165 insertions(+), 7 deletions(-) create mode 100644 layouts/_default/list.atom.xml create mode 100644 static/atom.xsl diff --git a/config/_default/hugo.yaml b/config/_default/hugo.yaml index 2bb8234d..5d1ff87c 100644 --- a/config/_default/hugo.yaml +++ b/config/_default/hugo.yaml @@ -32,10 +32,18 @@ related: - name: date weight: 10 +mediaTypes: + application/atom+xml: + suffixes: + - xml + outputFormats: SearchIndex: baseName: search mediaType: application/json + Atom: + mediaType: "application/atom+xml" + baseName: atom outputs: home: @@ -43,6 +51,12 @@ outputs: - rss - SearchIndex - json + - Atom + section: + - html + - rss + - json + - Atom services: rss: diff --git a/config/_default/params.yaml b/config/_default/params.yaml index 8fb76b42..74ed812d 100644 --- a/config/_default/params.yaml +++ b/config/_default/params.yaml @@ -6,6 +6,7 @@ images: - /img/Opengraph.png favicon: "apple-touch-icon.png" icon: "apple-touch-icon.png" +icon96: "favicon-96x96.png" defaultColor: "dark" # set color mode: dark, light, auto # Setting it to 'auto' applies the color scheme based on the visitor's device color preference.If you don't specify anything, ignore this parameter, or leave it blank, @@ -71,3 +72,7 @@ Hcard: bridgy: - "mastodon" - "bluesky" + +dateFormatAtomFeed: "2006-01-02T15:04:05-07:00" +dateFormatTag: "2006" +feedUUID: "43c22089-5c06-4cc4-8fd2-5b3563d5d257" diff --git a/content/feeds.md b/content/feeds.md index 7a9b92f2..938b68e1 100644 --- a/content/feeds.md +++ b/content/feeds.md @@ -13,7 +13,7 @@ This page collects content I'm producing in some way or the other, and is consum You can follow me here: -* [All stuff from my blog](/index.xml) -* [All my post from my blog](/post/index.xml) -* [All my photo from my blog](/photos/index.xml) -* [My personal Newsletter](https://newsletter.digitaltearoom.com/index.xml) +* All stuff from my blog [Atom](/atom.xml) [RSS](/index.xml) [Json](/index.json) +* All my post from my blog [Atom](/post/atom.xml) [RSS](/post/index.xml) [Json](/post/index.json) +* All my photo from my blog [Atom](/photos/atom.xml) [RSS](/photos/index.xml) [Json](/photos/index.json) +* My personal Newsletter [RSS](https://newsletter.digitaltearoom.com/index.xml) diff --git a/layouts/_default/list.atom.xml b/layouts/_default/list.atom.xml new file mode 100644 index 00000000..dfe8b33b --- /dev/null +++ b/layouts/_default/list.atom.xml @@ -0,0 +1,60 @@ +{{- $pctx := . }} +{{- if .IsHome }}{{ $pctx = .Site }}{{ end }} +{{- $pages := slice }} +{{- if or $.IsHome $.IsSection }} +{{- $pages = $pctx.RegularPages }} +{{- else }} +{{- $pages = $pctx.Pages }} +{{- end }} +{{- $limit := .Site.Config.Services.RSS.Limit }} +{{- if ge $limit 1 }} +{{- $pages = $pages | first $limit }} +{{- end }} +{{- with .Site.Config.Services.RSS.Limit -}} + {{- if ge . 1 -}} + {{- $pages = $pages | first . -}} + {{- end -}} +{{- end -}} +{{ print "" | safeHTML }} +{{- printf "" | safeHTML }} + +{{ with .Site.Author.name }} + + {{ . }} + {{ $.Site.BaseURL }} + + {{ end }} + Hugo {{ .Site.Hugo.Version }} + {{ if .Site.Params.feedUUID }}urn:uuid:{{.Site.Params.feedUUID }}{{ else }}{{ .Permalink }}{{ end }} + {{ with .OutputFormats.Get "atom" }} + {{ printf `` .MediaType.Type .Permalink $.Site.LanguageCode | safeHTML }} + {{ end }} + {{ range .AlternativeOutputFormats }} + {{ printf `` .MediaType.Type .Permalink $.Site.LanguageCode | safeHTML }} + {{ end }} + {{ with .Site.Params.icon }}{{ . | absURL }}{{ end }} + {{ with .Site.Params.logo }}{{ . | absURL }}{{ end }} + {{ with .Site.Copyright }}{{ replace . "{year}" now.Year }}{{ end }} + {{ with .Site.Params.Description }}{{ . }}{{ end }} + {{ .Site.Title }} + {{ now.Format .Site.Params.dateFormatAtomFeed | safeHTML }} + {{ with .Site.Params.icon96 }}{{ . | absURL }}{{ end }} + {{ range $pages }} + + {{ with .Params.Author }} + + {{ . }} + + {{ end }} + tag:{{ $u := urls.Parse .Permalink }}{{ $u.Hostname }},{{ .Date.Format .Site.Params.dateFormatTag }}:{{ replace $u.Path "#" "_" }} + + {{ .Title }} + {{ .Date.Format .Site.Params.dateFormatAtomFeed | safeHTML }} + {{ .Lastmod.Format .Site.Params.dateFormatAtomFeed | safeHTML }} + {{ with .Description }}{{ . }}{{ end }} + + {{ printf "" .Content | safeHTML }} + + + {{ end }} + diff --git a/layouts/partials/custom-head.html b/layouts/partials/custom-head.html index 5e8844f5..119c76ff 100644 --- a/layouts/partials/custom-head.html +++ b/layouts/partials/custom-head.html @@ -8,3 +8,7 @@ {{- $style := resources.Get "sass/add.scss" | resources.ExecuteAsTemplate "add.scss" . | toCSS (dict "targetPath" "add.css") | minify | fingerprint }} + +{{ with .OutputFormats.Get "atom" }} + +{{ end }} diff --git a/static/atom.xsl b/static/atom.xsl new file mode 100644 index 00000000..13059a96 --- /dev/null +++ b/static/atom.xsl @@ -0,0 +1,77 @@ + + + + + + + + Web Feed • <xsl:value-of select="atom:feed/atom:title"/> + + + +
+
+

This is a web feed, also known as an RSS feed. Subscribe by copying the URL from the address bar into your newsreader app.

+
+
+
+ +
+
+

Recent Items

+ +
+ + +
+ + +

's Web Feed Preview

+

This RSS feed provides the latest posts from 's blog. + + + + + + Visit Website → + + +

+ +

What is an RSS feed?

+

An RSS feed is a data format that contains the latest content from a website, blog, or podcast. You can use feeds to subscribe to websites and get the latest content in one place.

+
    +
  • Feeds put you in control. Unlike social media apps, there is no algorithm deciding what you see or read. You always get the latest content from the creators you care about.
  • +
  • Feed are private by design. No one owns web feeds, so no one is harvesting your personal information and profiting by selling it to advertisers.
  • +
  • Feeds are spam-proof. Had enough? Easy, just unsubscribe from the feed.
  • +
+

All you need to do to get started is to add the URL (web address) for this feed to a special app called a newsreader. Visit About Feeds to get started with newsreaders and subscribing. It’s free.

+
+ + +
+

+ + + + + + +

+

+ +

+ + Published: + +
+
+ +
diff --git a/static/rss.xsl b/static/rss.xsl index 6d74d1f9..446205fa 100644 --- a/static/rss.xsl +++ b/static/rss.xsl @@ -7,9 +7,7 @@ <xsl:value-of select="/rss/channel/title"/> RSS Feed - - - + =