From 6122059d8454cf9bf3dc7f277a26ffc26dc5284d Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 16 May 2022 03:12:57 +0200 Subject: Add Atom support --- exampleSite/config.toml | 66 ++++++++++++++++++--------------------- layouts/_default/home.atom.xml | 51 ++++++++++++++++++++++++++++++ layouts/partials/description.html | 2 +- 3 files changed, 82 insertions(+), 37 deletions(-) create mode 100644 layouts/_default/home.atom.xml diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 306b995..dc392bc 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -7,46 +7,37 @@ theme = ['github.com/sergeyklay/gohugo-theme-ed'] resourceDir = '../resources' enableRobotsTXT = true +# kick out RSS, we'll use Atom +disableKinds = ['RSS'] + [outputs] # TODO: - # home = [ "HTML", "RSS", "Atom", "JSON", "humanstxt" ] - # section = [ "HTML", "RSS", "Atom" ] - home = [ 'HTML', 'humanstxt' ] + # home = [ "HTML", "Atom", "JSON", "humanstxt" ] + # section = [ "HTML", "Atom" ] + home = [ 'HTML', 'Atom', 'humanstxt' ] [outputFormats.humanstxt] + mediaType = 'text/plain' baseName = 'humans' isPlainText = true - mediaType = 'text/plain' -# TODO: -# [outputFormats.Atom] -# mediaType = "application/atom" -# baseName = "feed" -# isPlainText = false - -# Possible 'Author' formats are: -# -# [author] -# name = 'John Doe' -# email = 'john@example.com' -# github = '@john_doe' -# location = 'Kyiv, Ukraine' -# -# OR -# -# [author] -# [author.john_doe] -# name = 'John Doe' -# email = 'john@example.com' -# github = '@john_doe' -# location = 'Kyiv, Ukraine' -# [author.jane_doe] -# name = 'Jane Doe' -# email = 'jane@example.com' -# github = '@jane_doe' -# location = 'Lviv, Ukraine' -# -# TODO: Mention format in docs +# Atom feed. +# For more see: https://validator.w3.org/feed/docs/atom.html#whatIsAtom +[outputFormats.Atom] + name = 'Atom' + mediaType = 'application/atom+xml' + # generated file = . = feeds/feed.atom.xml + baseName = 'feeds/feed.atom' + rel = 'alternate' + isPlainText = false + isHTML = false + noUgly = true + permalinkable = false + +[mediaTypes] + [mediaTypes.'application/atom+xml'] + suffixes = ['xml'] + [author] name = 'John Doe' email = 'john@example.com' @@ -60,24 +51,27 @@ enableRobotsTXT = true languageName = 'English' [params] - # Site author name. For multiple authors use: ['Me', 'You'] - author = 'John Doe' # Site description. Used in meta description description = 'Ed is a Hugo theme designed for textual editors based on minimal computing principles, and focused on legibility and flexibility.' + # Copyright string + copyright = 'Copyright (c) 2019 John Doe' # Color scheme. Options: red, orange, magenta, cyan, blue, brown colorScheme = '' # Used in site header tagline = 'a Hugo theme for minimal editions' # Custom footer text footer = '' - # Sections to be displayed in the main page + # Sections to be displayed in the main page, as well as RSS/Atom feeds mainSections = ['posts', 'dramas', 'narratives', 'poems'] # Order of post meta information postMeta = ['date'] # Posts date format, for example: 2006-01-02 dateformat = 'January 02, 2006' + dateFormatFeed = '2006-01-02T15:04:05Z07:00' # Show "Read more" button in list if true readmore = true + # RSS/Atom feed size + feedSize = 25 [params.assets] # Site icons, relative to ./static diff --git a/layouts/_default/home.atom.xml b/layouts/_default/home.atom.xml new file mode 100644 index 0000000..ad20269 --- /dev/null +++ b/layouts/_default/home.atom.xml @@ -0,0 +1,51 @@ +{{ print ""| safeHTML }} + + {{ site.Title }} + {{ with site.Params.description }}{{ . }}{{ end }} + {{ with site.Home.OutputFormats.Get "Atom" }}{{ end }} + {{ with site.Author.name }} + {{.}} + {{ with site.Author.email }}{{.}}{{end}} + {{end}} + {{ with site.Params.Copyright }}{{ .}}{{end}} + Hugo + {{ if not site.LastChange.IsZero }}{{ site.LastChange.UTC.Format site.Params.dateFormatFeed }}{{ end }} + {{ $uuid := sha1 (site.BaseURL | absURL)}}urn:uuid:{{ substr $uuid 0 8 }}-{{ substr $uuid 8 4 }}-5{{ substr $uuid 13 3 }}-{{ substr $uuid 16 1 }}9{{ substr $uuid 17 2 }}-{{ substr $uuid 21 12 }} + {{ $feedsize := site.Params.feedSize | default 25 }} + {{- range first $feedsize (where site.RegularPages.ByDate.Reverse "Type" "in" site.Params.mainSections) }} + + {{- $url := .RelPermalink }}{{ $uuid := sha1 (.Permalink | absURL)}}{{ $page := .}} + + {{ range (.GetTerms "tags") }} + + {{ end }} + + {{ .Title | plainify}} + {{ (.PublishDate.Format site.Params.dateFormatFeed) | html }} + {{ if ne .Date .Lastmod }}{{ .Lastmod.UTC.Format site.Params.dateFormatFeed }}{{ end }} + urn:uuid:{{ substr $uuid 0 8 }}-{{ substr $uuid 8 4 }}-5{{ substr $uuid 13 3 }}-{{ substr $uuid 16 1 }}9{{ substr $uuid 17 2 }}-{{ substr $uuid 21 12 }} + {{ if .Params.author }} + {{- $author_type := (printf "%T" .Params.author) }} + {{- if eq $author_type "string" }} + + {{ .Params.author }} + + {{- else if eq $author_type "[]string" }} + {{ range .Params.author }} + + {{ .Name }} + + {{ end }} + {{- end }} + {{ end }} + +
+

{{ replaceRE "\n" " " (.Summary | plainify | safeHTML | chomp) }}

+
+
+
+ {{- end }} +
diff --git a/layouts/partials/description.html b/layouts/partials/description.html index e63c0d9..ff3b697 100644 --- a/layouts/partials/description.html +++ b/layouts/partials/description.html @@ -12,4 +12,4 @@ {{- end -}} {{- end -}} -{{- $description | plainify | safeHTML | chomp | truncate 180 -}} +{{- replaceRE "\n" " " ($description | plainify | safeHTML | chomp | truncate 180) -}} -- cgit v1.2.3