diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2024-07-06 01:19:16 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2024-07-06 01:19:16 -0400 |
| commit | bd51b97e6953d5df4124ada7e29def41b2f7b09b (patch) | |
| tree | b65e40a7bca84c810c53efb63172c622444d6ccb | |
| parent | 37f4840e9c1e4dd3ac092c4a69535be3e77f0d0e (diff) | |
add rss to templates
| -rw-r--r-- | layouts/_default/baseof.html | 3 | ||||
| -rw-r--r-- | layouts/_default/rss.xml | 41 |
2 files changed, 44 insertions, 0 deletions
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index f1f63a1..2159326 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -10,6 +10,9 @@ <link rel="icon" type="image/png" sizes="32x32" href="/favicons/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="16x16" href="/favicons/favicon-16x16.png"> <link rel="manifest" href="/site.webmanifest"> + {{ with .OutputFormats.Get "rss" -}} + {{ printf `<link rel=%q type=%q href=%q title=%q>` .Rel .MediaType.Type .Permalink site.Title | safeHTML }} + {{ end }} {{ if .Params.math }} {{- partial "katex.html" . -}} {{ end }} diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml new file mode 100644 index 0000000..24e182e --- /dev/null +++ b/layouts/_default/rss.xml @@ -0,0 +1,41 @@ +{{- $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 }} +{{- 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>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{ . }} | {{ 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</generator> + <language>{{ site.Language.LanguageCode }}</language> + <copyright>Copyright {{ now.Format "2006" }}, JP Appel</copyright> + {{ if not .Date.IsZero }} + <lastBuildDate>{{ (index $pages.ByLastmod.Reverse 0).Lastmod.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>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate> + {{ with .Params.author }} + <author>{{ . }}</author> + {{ end }} + <guid>{{ .Permalink }}</guid> + <description>{{ .Summary | transform.XMLEscape | safeHTML }}</description> + </item> + {{- end }} + </channel> +</rss> |
