diff --git a/README.md b/README.md index baa5bf14..795e08df 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ It's a versatile canvas that serves most web needs. - Accessibility - Analytics +- Atom feed - Authors - Automatic switching between light and dark color schemes - Blog @@ -271,6 +272,10 @@ format = ":date_long" # Hugo date format [paige.feed] hide_page = false +[paige.feed.atom] +link_to_page = false # Link to the page instead of the front matter link, if present +page_link = "⏎" # If a front matter link is present, and link_to_page is false, link to the page with this text + [paige.feed.rss] managing_editor = "" web_master = "" diff --git a/exampleSite/hugo.toml b/exampleSite/hugo.toml index 63ca0078..e076f1ed 100644 --- a/exampleSite/hugo.toml +++ b/exampleSite/hugo.toml @@ -85,7 +85,9 @@ startlevel = 2 path = "github.com/willfaught/paige" [outputs] -home = ["html", "json", "rss"] +home = ["atom", "html", "json", "rss"] +section = ["atom", "html", "rss"] +taxonomy = ["atom", "html", "rss"] [params.authors.will-faught] default = true @@ -96,6 +98,11 @@ url = "https://willfaught.com/paige" [params.paige.git] commit_url = "https://github.com/willfaught/paige/commit/%s" +[[params.paige.feed.atom.authors]] +email = "will.faught@example.com" +name = "Will Faught" +url = "https://willfaught.com/paige" + [params.paige.feed.rss] managing_editor = "Will Faught" web_master = "Will Faught" diff --git a/hugo.toml b/hugo.toml index b5ac0b8b..13362b7c 100644 --- a/hugo.toml +++ b/hugo.toml @@ -1,3 +1,6 @@ +[mediatypes."application/atom+xml"] +suffixes = ["xml"] + [module.hugoversion] min = "0.111.3" extended = true @@ -84,6 +87,16 @@ source = "paige/node_modules/katex/dist" target = "assets/js/paige/katex" includeFiles = ["katex.min.js"] +[outputformats.atom] +basename = "atom" +ishtml = false +isplaintext = false +mediatype = "application/atom+xml" +name = "atom" +nougly = true +permalinkable = false +rel = "alternate" + [outputformats.rss] basename = "rss" ishtml = false diff --git a/layouts/_default/list.atom.xml b/layouts/_default/list.atom.xml new file mode 100644 index 00000000..0ab102f4 --- /dev/null +++ b/layouts/_default/list.atom.xml @@ -0,0 +1,156 @@ +{{ $page := . }} + +{{ $authors := $page.Param "paige.feed.atom.authors" }} +{{ $lang := site.LanguageCode | default site.Language.Lang }} +{{ $limit := site.Config.Services.RSS.Limit }} +{{ $pagetitle := $page.Title | markdownify }} +{{ $rights := site.Copyright }} +{{ $sitetitle := site.Title | markdownify }} +{{ $subpages := (cond $page.IsHome site $page).RegularPages }} +{{ $subtitle := $page.Description }} +{{ $title := "" }} +{{ $updated := time site.LastChange }} + +{{ if and $pagetitle $sitetitle }} + {{ if $page.IsHome }} + {{ $title = $pagetitle | safeHTML }} + {{ else }} + {{ $title = printf "%s · %s" $pagetitle $sitetitle | safeHTML }} + {{ end }} +{{ else if $pagetitle }} + {{ $title = $pagetitle | safeHTML }} +{{ else if $sitetitle }} + {{ $title = $sitetitle | safeHTML }} +{{ end }} + +{{ $subpages = where $subpages "Params.paige.feed.hide_page" "ne" true }} + +{{ if ge $limit 0 }} + {{ $subpages = $subpages | first $limit }} +{{ end }} + +{{ printf "" | safeHTML }} + + {{ range $authors }} + + {{ with .email }} + {{ . }} + {{ end }} + {{ with .name }} + {{ . }} + {{ end }} + {{ with .url }} + {{ . }} + {{ end }} + + {{ end }} + {{ $id := "" }} + {{ if .Params.id }} + {{ $id = .Params.id }} + {{ else if not $page.Date.IsZero }} + {{ $id = printf "tag:%s,%s:%s" (urls.Parse site.BaseURL).Host (.Date.Format "2006-01-02") (.Date.Format "2006-01-02T15:04:05Z07:00") }} + {{ else }} + {{ $id = .Permalink }} + {{ end }} + {{ $id }} + {{ printf `` ($page.Permalink | safeURL) | safeHTML }} + {{ range $page.AlternativeOutputFormats }} + {{ if eq .Rel "alternate" }} + {{ printf `` (.Permalink | safeURL) .MediaType | safeHTML }} + {{ end }} + {{ end }} + {{ range $t := $page.Translations }} + {{ range .OutputFormats }} + {{ if eq .Rel "alternate" }} + {{ printf `` (.Permalink | safeURL) $t.Lang .MediaType | safeHTML }} + {{ end }} + {{ end }} + {{ end }} + {{ with $rights }} + {{ printf "" (. | markdownify) | safeHTML }} + {{ end }} + {{ with $subtitle }} + {{ printf "" (. | markdownify) | safeHTML}} + {{ end }} + {{ if not $title }} + {{ warnf "layouts/_default/list.atom.xml: Page %s does not have a title" $page.RelPermalink }} + {{ end }} + {{ printf `<![CDATA[%s]]>` ($title | markdownify) | safeHTML }} + {{ $updated.Format "2006-01-02T15:04:05Z07:00" }} + {{ $ids := dict }} + {{ range $subpage := $subpages }} + + {{ with partial "paige/authors.html" . }} + {{ range . }} + + {{ with .email }} + {{ . }} + {{ end }} + {{ with .name }} + {{ . }} + {{ end }} + {{ with .url }} + {{ . }} + {{ end }} + + {{ end }} + {{ end }} + {{ $content := .Content }} + {{ if $content }} + {{ if and .Params.link (not (.Param "paige.feed.atom.link_to_page")) }} + {{ $link := or (.Param "paige.feed.atom.page_link" | markdownify) "⏎" }} + {{ $footer := printf `

%s

` .Permalink .Title $link }} + {{ $content = print $content $footer }} + {{ end }} + {{ printf "" $content | safeHTML }} + {{ end }} + {{ $id := "" }} + {{ if .Params.id }} + {{ $id = .Params.id }} + {{ else if not .Date.IsZero }} + {{ $id = printf "tag:%s,%s:%s" (urls.Parse site.BaseURL).Host (.Date.Format "2006-01-02") (.Date.Format "2006-01-02T15:04:05Z07:00") }} + {{ else }} + {{ $id = .RelPermalink }} + {{ end }} + {{ with index $ids $id }} + {{ warnf "layouts/_default/list.atom.xml: Pages %s and %s have the same ID" . $subpage.RelPermalink }} + {{ end }} + {{ $ids = merge (dict $id .RelPermalink) $ids }} + {{ $id }} + {{ range .OutputFormats }} + {{ if eq .Rel "alternate" }} + {{ printf `` (.Permalink | safeURL) .MediaType | safeHTML }} + {{ end }} + {{ end }} + {{ range $t := .Translations }} + {{ range .OutputFormats }} + {{ if eq .Rel "alternate" }} + {{ printf `` (.Permalink | safeURL) $t.Lang .MediaType | safeHTML }} + {{ end }} + {{ end }} + {{ end }} + {{ if and .Params.link (not (.Param "paige.feed.atom.link_to_page")) }} + + {{ else }} + + {{ end }} + {{ if not .PublishDate.IsZero }} + {{ .PublishDate.Format "2006-01-02T15:04:05Z07:00" }} + {{ end }} + {{ with site.Copyright }} + {{ printf "" (. | markdownify) | safeHTML }} + {{ end }} + {{ with .Description }} + {{ printf "" (. | markdownify) | safeHTML }} + {{ end }} + {{ if not .Title }} + {{ warnf "layouts/_default/list.atom.xml: %s: Page %s does not have a title" .RelPermalink }} + {{ end }} + {{ printf `<![CDATA[%s]]>` (.Title | markdownify) | safeHTML }} + {{ if .Lastmod.IsZero }} + {{ warnf "layouts/_default/list.atom.xml: Page %s does not have a modified date" .RelPermalink }} + {{ end }} + {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }} +
+ {{ end }} +