From 23d77288040ca113dbc797aa2eaff6ba2a32f324 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sun, 14 Apr 2024 15:30:44 +0200 Subject: Move site author configuration to params --- CHANGELOG.md | 18 ++++++++ exampleSite/config/_default/config.yaml | 7 --- exampleSite/config/_default/params.yaml | 11 ++++- layouts/_default/home.humanstxt.txt | 12 +++--- layouts/_default/list.atom.xml | 5 ++- layouts/_default/list.feed.xml | 3 +- layouts/_default/list.jsonfeed.json | 6 ++- layouts/partials/author.html | 6 ++- layouts/partials/schema.org/article.html | 6 ++- layouts/partials/site-author.html | 34 +++++++++++++++ tests/feed-atom.spec.js | 74 ++++++++++++++++++++++++++++++++ tests/feed-rss.spec.js | 58 +++++++++++++++++++++++++ tests/feeds.spec.js | 58 ------------------------- tests/humans.spec.js | 39 +++++++++++++++++ 14 files changed, 256 insertions(+), 81 deletions(-) create mode 100644 layouts/partials/site-author.html create mode 100644 tests/feed-atom.spec.js create mode 100644 tests/feed-rss.spec.js delete mode 100644 tests/feeds.spec.js create mode 100644 tests/humans.spec.js diff --git a/CHANGELOG.md b/CHANGELOG.md index b3e4913..085f44b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ``` {{ $siteLastMod := partial "site-last-mod.html" . }} ``` +- Introduced a new partial template `site-author.html` to handle site author + information more consistently across Hugo versions. This change accommodates + the deprecation of `site.Author` in favour of `site.Params.author` for Hugo + versions equal to or greater than 0.124.0. Usage: + ``` + {{ $siteAuthor := partial "site-author.html" . }} + + {{ with $siteAuthor.name }} {{ . }} {{ end }} + {{ with $siteAuthor.email }} {{ . }} {{ end }} + {{ with $siteAuthor.github }} {{ . }} {{ end }} + {{ with $siteAuthor.twitter }} {{ . }} {{ end }} + {{ with $siteAuthor.location }} {{ . }} {{ end }} + ``` ### Changed @@ -37,6 +50,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `` tag. - In `list.feed.xml`, replaced `site.LastChange` with `$siteLastMod` in the `` tag. +- Updated `humans.txt`, Atom feed, RSS feed, JSON feed, author partial, and + schema.org Article template to use the `site-author.html` partial for + retrieving site author information. +- Moved site author configuration from `config.yaml` to `params.yaml` to align + with the recommended usage of `site.Params.author`. ### Fixed diff --git a/exampleSite/config/_default/config.yaml b/exampleSite/config/_default/config.yaml index 3941f28..eda82ea 100644 --- a/exampleSite/config/_default/config.yaml +++ b/exampleSite/config/_default/config.yaml @@ -133,13 +133,6 @@ sitemap: filename: sitemap.xml priority: 0.5 -author: - name: John Doe - email: john@example.com - github: john_doe - twitter: john_doe - location: 'Kyiv, Ukraine' - # For more see https://gohugo.io/getting-started/configuration-markup/ markup: defaultMarkdownHandler: goldmark diff --git a/exampleSite/config/_default/params.yaml b/exampleSite/config/_default/params.yaml index bf6c79a..12a00b0 100644 --- a/exampleSite/config/_default/params.yaml +++ b/exampleSite/config/_default/params.yaml @@ -15,7 +15,7 @@ keywords: # A "copyright"-line to be added to RSS/Atom files. # "©" and "{year}" will be replaced by © and the current year. -copyright: 'Copyright © 2019-{year} John Doe' +copyright: 'Copyright © 2019-{year} Serghei Iakovlev' # Colour scheme. Options: red, orange, magenta, cyan, blue, brown colorScheme: '' @@ -88,6 +88,13 @@ seo: # you have to set `googleAnalytics` param in config.yaml file. anonymizeIp: true +author: + name: Serghei Iakovlev + email: egrep@protonmail.ch + github: sergeyklay + twitter: egreps + location: 'Wrocław, Poland' + social: # Array of Facebook Page Admin IDs for Domain Insights facebookAdminIds: [] @@ -96,7 +103,7 @@ social: facebookId: '' # Twitter username for the website - twitter: john_doe + twitter: egreps # Configure search engine search: diff --git a/layouts/_default/home.humanstxt.txt b/layouts/_default/home.humanstxt.txt index 0d3efe9..23286fe 100644 --- a/layouts/_default/home.humanstxt.txt +++ b/layouts/_default/home.humanstxt.txt @@ -1,11 +1,12 @@ -{{- with site.Author.name }} +{{- $siteAuthor := partial "site-author.html" . -}} +{{- with $siteAuthor.name }} /* TEAM */ Author: {{ . }} -{{- with site.Author.email }}{{ printf "\n Contact: %s" . }}{{ end }} -{{- with site.Author.github }}{{ printf "\n GitHub: @%s" . }}{{ end }} -{{- with site.Author.twitter }}{{ printf "\n Twitter: @%s" . }}{{ end }} -{{- with site.Author.location }}{{ printf "\n From: %s" . }}{{ end }} +{{- with $siteAuthor.email }}{{ printf "\n Contact: %s" . }}{{ end }} +{{- with $siteAuthor.github }}{{ printf "\n GitHub: @%s" . }}{{ end }} +{{- with $siteAuthor.twitter }}{{ printf "\n Twitter: @%s" . }}{{ end }} +{{- with $siteAuthor.location }}{{ printf "\n From: %s" . }}{{ end }} {{- end }} /* SITE */ @@ -15,3 +16,4 @@ Doctype: HTML5 Standards: HTML5, CSS3, Open Graph protocol, Schema.org Components: Hugo, Ed Theme, Lunr.js + Hugo version: {{ site.Hugo.Version }} diff --git a/layouts/_default/list.atom.xml b/layouts/_default/list.atom.xml index 67ff79b..edc133b 100644 --- a/layouts/_default/list.atom.xml +++ b/layouts/_default/list.atom.xml @@ -15,6 +15,7 @@ {{- $pages = $pages | first $limit -}} {{- $siteLastMod := partial "site-last-mod.html" . -}} +{{- $siteAuthor := partial "site-author.html" . -}} {{- safeHTML "" }} @@ -28,10 +29,10 @@ {{- end -}} {{- end }} {{ $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png") }}{{ $logo = $logo.Resize "96x96" }}{{ $logo.Permalink | absURL }} - {{ $logo.Permalink | absURL }}{{ with site.Author.name }} + {{ $logo.Permalink | absURL }}{{ with $siteAuthor.name }} {{ printf `` . | safeHTML }} - {{ with site.Author.email }}{{ . | html }}{{ end }} + {{ with $siteAuthor.email }}{{ . | html }}{{ end }} {{ end }}{{ with site.Params.Copyright }}{{ $copyright := replace . "{year}" now.Year }}{{ $copyright = replace $copyright "©" "©" }} {{ $copyright | plainify }}{{ end }} Hugo{{ if ne $siteLastMod "" }} diff --git a/layouts/_default/list.feed.xml b/layouts/_default/list.feed.xml index 2bc3cb7..ae4366b 100644 --- a/layouts/_default/list.feed.xml +++ b/layouts/_default/list.feed.xml @@ -15,6 +15,7 @@ {{- $pages = $pages | first $limit -}} {{- $siteLastMod := partial "site-last-mod.html" . -}} +{{- $siteAuthor := partial "site-author.html" . -}} {{- printf "" | safeHTML }} ` . | safeHTML }}{{ end }} - Hugo {{ hugo.Version }}{{ with site.Author.name }} + Hugo {{ hugo.Version }}{{ with $siteAuthor.name }} {{ printf `` . | safeHTML }}{{ end }}{{ with site.LanguageCode }} {{ . }}{{ end }}{{ with site.Params.Copyright }}{{ $copyright := replace . "{year}" now.Year }}{{ $copyright = replace $copyright "©" "©" }} {{ $copyright | plainify }}{{ end }}{{ if ne $siteLastMod "" }} diff --git a/layouts/_default/list.jsonfeed.json b/layouts/_default/list.jsonfeed.json index f6b89cc..29c9bf4 100644 --- a/layouts/_default/list.jsonfeed.json +++ b/layouts/_default/list.jsonfeed.json @@ -14,6 +14,8 @@ {{- $limit := site.Params.feedSize | default 25 -}} {{- $pages = $pages | first $limit -}} +{{- $siteAuthor := partial "site-author.html" . -}} + { "version": "https://jsonfeed.org/version/1.1", "title": {{ (partial "title.html" .) | htmlUnescape | jsonify }}, @@ -23,9 +25,9 @@ {{- $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png") }}{{ $logo = $logo.Resize "96x96" }} "icon": {{ $logo.Permalink | jsonify }}, "favicon": {{ $logo.Permalink | jsonify }}, - {{ with site.Author.name }}"authors": [ + {{ with $siteAuthor.name }}"authors": [ { - "name": {{ . | jsonify }}{{ with site.Author.twitter }}, + "name": {{ . | jsonify }}{{ with $siteAuthor.twitter }}, "url": {{ (printf "https://twitter.com/%s" . ) | jsonify }}{{ end }} } ],{{ end }} diff --git a/layouts/partials/author.html b/layouts/partials/author.html index 2bfddb3..4ca1209 100644 --- a/layouts/partials/author.html +++ b/layouts/partials/author.html @@ -1,3 +1,5 @@ +{{- $siteAuthor := partial "site-author.html" . -}} + {{- /* First, check for current page author(s) */}} {{- if .Params.author }} {{- $author_type := (printf "%T" .Params.author) }} @@ -7,6 +9,6 @@ {{- .Params.author }} {{- end }} {{- /* Otherwise, get site authors */}} -{{- else if site.Author.name }} - {{- site.Author.name }} +{{- else if $siteAuthor.name }} + {{- $siteAuthor.name }} {{- end -}} diff --git a/layouts/partials/schema.org/article.html b/layouts/partials/schema.org/article.html index fcec66b..f4112b6 100644 --- a/layouts/partials/schema.org/article.html +++ b/layouts/partials/schema.org/article.html @@ -13,6 +13,8 @@ {{- $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png") -}} {{- $logo = $logo.Resize "96x96" }} +{{- $siteAuthor := partial "site-author.html" . }} +