From 754d955e7c035574629d726b93de3df982e4022d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 22 Jun 2023 09:41:23 +0200 Subject: Set up RSS feed properly --- config.toml | 3 ++- layouts/blog/list.html | 44 ++++++++++++++++++++++++++++++++++++++++++++ layouts/blog/rss.xml | 41 +++++++++++++++++++++++++++++++++++++++++ layouts/blog/single.html | 1 - layouts/partials/head.html | 3 +++ 5 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 layouts/blog/list.html create mode 100644 layouts/blog/rss.xml diff --git a/config.toml b/config.toml index cfc2bd1..82bbefd 100644 --- a/config.toml +++ b/config.toml @@ -2,9 +2,10 @@ baseURL = 'https://writefreesoftware.org' languageCode = 'en-US' title = 'Write Free Software' theme = ["github.com/onweru/compose"] +rssLimit = 10 [outputs] - home = ["HTML", "RSS","JSON"] + home = ["HTML", "RSS", "JSON"] [languages] [languages.en] diff --git a/layouts/blog/list.html b/layouts/blog/list.html new file mode 100644 index 0000000..d1b8f3b --- /dev/null +++ b/layouts/blog/list.html @@ -0,0 +1,44 @@ +{{ define "main" }} +{{- $pages := where site.RegularPages "Section" site.Params.blogDir }} +
+ {{- $paginator := .Paginate $pages -}} + {{- $size := $paginator.PageSize }} + {{- $scratch := newScratch }} + {{- range $index, $value := $paginator.Pages }} + {{ if isset .Params "image" }} + {{ $scratch.Set "image" .Params.image }} + {{ else }} + {{ $scratch.Set "image" "thumbnail.svg" }} + {{ end }} + {{ $image := $scratch.Get "image" }} + {{ $bg := (absURL (printf "images/%s" $image)) }} + {{- if in $image "https://" }} + {{- $bg = $image }} + {{- end }} + + {{- if and (eq $index 0) (gt $size 1) }}
{{ end }} + {{- if and (eq $index (add $size -1)) (gt $size 1) }}
{{ end }} + {{- end }} +
+

+ RSS feed ยป +

+ +{{ end }} diff --git a/layouts/blog/rss.xml b/layouts/blog/rss.xml new file mode 100644 index 0000000..a917e33 --- /dev/null +++ b/layouts/blog/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 "" | safeHTML }} + + + Drew DeVault's blog + https://drewdevault.com + Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }} + Hugo -- gohugo.io{{ with .Site.LanguageCode }} + {{.}}{{end}}{{ with .Site.Author.email }} + {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Author.email }} + {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Copyright }} + {{.}}{{end}}{{ if not .Date.IsZero }} + {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}{{ end }} + {{ with .OutputFormats.Get "RSS" }} + {{ printf "" .Permalink .MediaType | safeHTML }} + {{ end }} + {{ range $pages }} + {{- if .OutputFormats.Get "HTML" -}} + + {{ .Title }} + {{ .Permalink }} + {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }} + {{ with .Site.Author.email }}{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}} + {{ .Permalink }} + {{- .Content | html -}} + + {{- end -}} + {{ end }} + + diff --git a/layouts/blog/single.html b/layouts/blog/single.html index a81ad10..d8901ef 100644 --- a/layouts/blog/single.html +++ b/layouts/blog/single.html @@ -19,7 +19,6 @@ {{ partialCached "share" . }}
- {{ template "_internal/disqus.html" . }}
diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 960fb39..02cf31a 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -6,6 +6,9 @@ {{ end }} {{ end }} +{{ range .AlternativeOutputFormats -}} +{{ printf `` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} +{{ end -}} {{- hugo.Generator }} {{- $t := .Title }} {{- $s := site.Title }} -- cgit v1.3