From 6c6b1bd1035ae68a18bd83faf7ff1297ead60e8c Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 3 Jun 2022 12:51:52 +0200 Subject: Do not allow modification of date formats that are required by spec --- CHANGELOG.md | 5 +++-- exampleSite/config.toml | 4 +--- layouts/_default/list.atom.xml | 6 +++--- layouts/_default/list.feed.xml | 6 +++--- layouts/_default/list.json.json | 4 ++-- layouts/_default/sitemap.xml | 4 +--- layouts/partials/post-meta/date.html | 4 ++-- 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf92297..f6ffd40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,8 +18,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Minor reformatting of posts layout -- Allow manually override lastmod date of a post +- Allow manually override `lastmod` for posts - Check that `lastmod` exists and is greater than `date` before printing it +- Do not allow modification of date formats that are required by spec ## [v0.2.0](https://github.com/sergeyklay/gohugo-theme-ed/compare/v0.1.0...v0.2.0) @@ -27,7 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add multilanguage support - Add Russian translation -- Provide an ability to use hreflang attribute in `link` shortcode +- Provide an ability to use `hreflang` attribute in `link` shortcode - Add `{{< mini-toc >}}` shortcode - Provide ability to use `keywords` meta tag - Provide ability to render feeds menu diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 242049d..1141174 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -152,10 +152,8 @@ disableKinds = ['RSS'] # Order of post meta information. Order is important. postMeta = ['author', 'date'] # Posts date format, for example: 2006-01-02 - dateformat = ':date_long' + dateFormat = ':date_long' dateFormatToc = '2006.01.02' - dateFormatFeed = '2006-01-02T15:04:05Z07:00' - dateFormatRFC822Z = '02 Jan 2006 15:04:05 UT' # Show "Read more" button in list if true readmore = true # RSS/Atom feed size diff --git a/layouts/_default/list.atom.xml b/layouts/_default/list.atom.xml index 75892fd..5da5f25 100644 --- a/layouts/_default/list.atom.xml +++ b/layouts/_default/list.atom.xml @@ -33,7 +33,7 @@ {{ end }}{{ with site.Params.Copyright }}{{ $copyright := replace . "{year}" now.Year }}{{ $copyright = replace $copyright "©" "©" }} {{ $copyright | plainify }}{{ end }} Hugo{{ if not site.LastChange.IsZero }} - {{ site.LastChange.UTC.Format site.Params.dateFormatFeed }}{{ end }}{{ $uuid := sha1 (site.BaseURL | absURL) }} + {{ site.LastChange.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}{{ 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 }}{{- range $pages }} {{- $url := .Permalink | absURL }}{{ $uuid := sha1 (.Permalink | absURL) }}{{ $page := . }} @@ -42,8 +42,8 @@ {{ printf `<![CDATA[%s]]>` .Title | safeHTML }}{{ range first 5 (site.RegularPages.Related .) }} {{ end }} - {{ (.PublishDate.Format site.Params.dateFormatFeed) | html }}{{ if ne .Date .Lastmod }} - {{ .Lastmod.UTC.Format site.Params.dateFormatFeed }}{{ end }} + {{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}{{ if ne .Date .Lastmod }} + {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}{{ 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) }} diff --git a/layouts/_default/list.feed.xml b/layouts/_default/list.feed.xml index ae16aca..d66688b 100644 --- a/layouts/_default/list.feed.xml +++ b/layouts/_default/list.feed.xml @@ -14,7 +14,7 @@ {{- $limit := site.Params.feedSize | default 25 -}} {{- $pages = $pages | first $limit -}} -{{- safeHTML "" }} +{{- printf "" | safeHTML }} ` . | safeHTML }}{{ end }}{{ with site.LanguageCode }} {{ . }}{{ end }}{{ with site.Params.Copyright }}{{ $copyright := replace . "{year}" now.Year }}{{ $copyright = replace $copyright "©" "©" }} {{ $copyright | plainify }}{{ end }}{{ if not site.LastChange.IsZero }} - {{ site.LastChange.UTC.Format site.Params.dateFormatRFC822Z | html }}{{ end }}{{- range $pages }} + {{ site.LastChange.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}{{ end }}{{- range $pages }} {{ printf `<![CDATA[%s]]>` .Title | safeHTML }} {{ .Permalink | absURL }}?utm_source=rss_feed - {{ .PublishDate.UTC.Format site.Params.dateFormatRFC822Z | html }} + {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }} {{ .Section }}{{ range (.GetTerms "tags") }} {{ .LinkTitle }}{{end}} {{ md5 .Permalink }} diff --git a/layouts/_default/list.json.json b/layouts/_default/list.json.json index b912df0..70ea7a4 100644 --- a/layouts/_default/list.json.json +++ b/layouts/_default/list.json.json @@ -36,8 +36,8 @@ "url": {{ printf "%s?utm_source=json_feed" .Permalink | jsonify }}, "title": {{ .Title | plainify | chomp | jsonify }}, "summary": {{ .Summary | plainify | chomp | jsonify }}, - "date_published": {{ .PublishDate.UTC.Format site.Params.dateFormatFeed | jsonify }}{{ if ne .Date .Lastmod }}, - "date_modified" : {{ .Lastmod.UTC.Format site.Params.dateFormatFeed | jsonify }}{{ end }} + "date_published": {{ .PublishDate.Format "2006-01-02T15:04:05Z07:00" | jsonify }}{{ if ne .Date .Lastmod }}, + "date_modified" : {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | jsonify }}{{ end }} } {{- end}} ] diff --git a/layouts/_default/sitemap.xml b/layouts/_default/sitemap.xml index 3745dc5..939dcac 100644 --- a/layouts/_default/sitemap.xml +++ b/layouts/_default/sitemap.xml @@ -1,12 +1,10 @@ -{{- $dateFormat := site.Params.dateFormatFeed | default "2006-01-02T15:04:05-07:00" -}} - {{- printf "" | safeHTML }} {{ range .Data.Pages }}{{ if ne .Params.private true }} {{ .Permalink }}{{ if not .Lastmod.IsZero }} - {{ safeHTML ( .Lastmod.Format $dateFormat | html ) }}{{ end }}{{ with .Sitemap.ChangeFreq }} + {{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05Z07:00" | jsonify ) }}{{ end }}{{ with .Sitemap.ChangeFreq }} {{ . }}{{ end }}{{ if ge .Sitemap.Priority 0.0 }} {{ .Sitemap.Priority }}{{ end }}{{ if .IsTranslated }}{{ range .Translations }} {{ $date }} -- cgit v1.2.3