diff options
| author | Serghei Iakovlev <egrep@protonmail.ch> | 2022-05-16 03:12:57 +0200 |
|---|---|---|
| committer | Serghei Iakovlev <egrep@protonmail.ch> | 2022-05-16 03:12:57 +0200 |
| commit | 6122059d8454cf9bf3dc7f277a26ffc26dc5284d (patch) | |
| tree | 942bc3ecaba9f28f378fee0e94627c52a272231e | |
| parent | 60a0feb39d3ec975472f12377db9182789776c10 (diff) | |
| download | gohugo-theme-ed-6122059d8454cf9bf3dc7f277a26ffc26dc5284d.tar.gz | |
Add Atom support
| -rw-r--r-- | exampleSite/config.toml | 66 | ||||
| -rw-r--r-- | layouts/_default/home.atom.xml | 51 | ||||
| -rw-r--r-- | layouts/partials/description.html | 2 |
3 files changed, 82 insertions, 37 deletions
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 = <baseName>.<mediaType.'application/atom+xml'.suffixes[0]> = 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 "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>"| safeHTML }} +<feed xmlns="http://www.w3.org/2005/Atom" + xmlns:media="http://search.yahoo.com/mrss/" + xml:lang="{{ site.LanguageCode }}" + xml:base="{{site.BaseURL }}"> + <title>{{ site.Title }}</title> + {{ with site.Params.description }}<subtitle>{{ . }}</subtitle>{{ end }} + {{ with site.Home.OutputFormats.Get "Atom" }}<link href="{{ .RelPermalink }}" rel="self" type="{{ .MediaType.Type | html }}" />{{ end }} + {{ with site.Author.name }}<author> + <name>{{.}}</name> + {{ with site.Author.email }}<email>{{.}}</email>{{end}} + </author>{{end}} + {{ with site.Params.Copyright }}<rights type="text">{{ .}}</rights>{{end}} + <generator uri="https://gohugo.io" version="{{ hugo.Version }}">Hugo</generator> + {{ if not site.LastChange.IsZero }}<updated>{{ site.LastChange.UTC.Format site.Params.dateFormatFeed }}</updated>{{ end }} + {{ $uuid := sha1 (site.BaseURL | absURL)}}<id>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 }}</id> + {{ $feedsize := site.Params.feedSize | default 25 }} + {{- range first $feedsize (where site.RegularPages.ByDate.Reverse "Type" "in" site.Params.mainSections) }} + <entry> + {{- $url := .RelPermalink }}{{ $uuid := sha1 (.Permalink | absURL)}}{{ $page := .}} + <category term="{{ .Section}}" /> + {{ range (.GetTerms "tags") }} + <category term="{{ .LinkTitle }}" /> + {{ end }} + <link rel="alternate" type="type/html" href="{{ $url }}" /> + <title type="text">{{ .Title | plainify}}</title> + <published>{{ (.PublishDate.Format site.Params.dateFormatFeed) | html }}</published> + {{ if ne .Date .Lastmod }}<updated>{{ .Lastmod.UTC.Format site.Params.dateFormatFeed }}</updated>{{ end }} + <id>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 }}</id> + {{ if .Params.author }} + {{- $author_type := (printf "%T" .Params.author) }} + {{- if eq $author_type "string" }} + <author> + <name>{{ .Params.author }}</name> + </author> + {{- else if eq $author_type "[]string" }} + {{ range .Params.author }} + <author> + <name>{{ .Name }}</name> + </author> + {{ end }} + {{- end }} + {{ end }} + <summary type="xhtml"> + <div xmlns="http://www.w3.org/1999/xhtml"> + <p>{{ replaceRE "\n" " " (.Summary | plainify | safeHTML | chomp) }}</p> + </div> + </summary> + </entry> + {{- end }} +</feed> 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) -}} |
