summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerghei Iakovlev <egrep@protonmail.ch>2022-06-03 12:51:52 +0200
committerSerghei Iakovlev <egrep@protonmail.ch>2022-06-03 12:52:23 +0200
commit6c6b1bd1035ae68a18bd83faf7ff1297ead60e8c (patch)
tree0a9b6c3388af549cd7d59b6e680837d31d9dc3b2
parent1283f3d31243d1ac63ce718c4039ba6b85f5d721 (diff)
downloadgohugo-theme-ed-6c6b1bd1035ae68a18bd83faf7ff1297ead60e8c.tar.gz
Do not allow modification of date formats that are required by spec
-rw-r--r--CHANGELOG.md5
-rw-r--r--exampleSite/config.toml4
-rw-r--r--layouts/_default/list.atom.xml6
-rw-r--r--layouts/_default/list.feed.xml6
-rw-r--r--layouts/_default/list.json.json4
-rw-r--r--layouts/_default/sitemap.xml4
-rw-r--r--layouts/partials/post-meta/date.html4
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 @@
</author>{{ end }}{{ with site.Params.Copyright }}{{ $copyright := replace . "{year}" now.Year }}{{ $copyright = replace $copyright "&copy;" "©" }}
<rights>{{ $copyright | plainify }}</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) }}
+ <updated>{{ site.LastChange.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}</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>{{- range $pages }}
<entry>
{{- $url := .Permalink | absURL }}{{ $uuid := sha1 (.Permalink | absURL) }}{{ $page := . }}
@@ -42,8 +42,8 @@
<link rel="alternate" type="type/html" href="{{ $url }}?utm_source=atom_feed" />
{{ printf `<title type="html"><![CDATA[%s]]></title>` .Title | safeHTML }}{{ range first 5 (site.RegularPages.Related .) }}
<link href="{{ .Permalink }}?utm_source=atom_feed" rel="related" type="text/html" title="{{ .Title }}" />{{ end }}
- <published>{{ (.PublishDate.Format site.Params.dateFormatFeed) | html }}</published>{{ if ne .Date .Lastmod }}
- <updated>{{ .Lastmod.UTC.Format site.Params.dateFormatFeed }}</updated>{{ end }}
+ <published>{{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}</published>{{ if ne .Date .Lastmod }}
+ <updated>{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}</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) }}
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 "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" }}
+{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }}
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
@@ -49,11 +49,11 @@
{{ printf `<dc:creator type="html"><![CDATA[%s]]></dc:creator>` . | safeHTML }}{{ end }}{{ with site.LanguageCode }}
<language>{{ . }}</language>{{ end }}{{ with site.Params.Copyright }}{{ $copyright := replace . "{year}" now.Year }}{{ $copyright = replace $copyright "&copy;" "©" }}
<copyright>{{ $copyright | plainify }}</copyright>{{ end }}{{ if not site.LastChange.IsZero }}
- <lastBuildDate>{{ site.LastChange.UTC.Format site.Params.dateFormatRFC822Z | html }}</lastBuildDate>{{ end }}{{- range $pages }}
+ <lastBuildDate>{{ site.LastChange.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}{{- range $pages }}
<item>
{{ printf `<title type="html"><![CDATA[%s]]></title>` .Title | safeHTML }}
<link>{{ .Permalink | absURL }}?utm_source=rss_feed</link>
- <pubDate>{{ .PublishDate.UTC.Format site.Params.dateFormatRFC822Z | html }}</pubDate>
+ <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
<category>{{ .Section }}</category>{{ range (.GetTerms "tags") }}
<category>{{ .LinkTitle }}</category>{{end}}
<guid isPermaLink="false">{{ md5 .Permalink }}</guid>
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 "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
{{ range .Data.Pages }}{{ if ne .Params.private true }}
<url>
<loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
- <lastmod>{{ safeHTML ( .Lastmod.Format $dateFormat | html ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
+ <lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05Z07:00" | jsonify ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
<changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
<priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ if .IsTranslated }}{{ range .Translations }}
<xhtml:link
diff --git a/layouts/partials/post-meta/date.html b/layouts/partials/post-meta/date.html
index e5626cf..42747f2 100644
--- a/layouts/partials/post-meta/date.html
+++ b/layouts/partials/post-meta/date.html
@@ -1,5 +1,5 @@
-{{ $date := .Date | time.Format (site.Params.dateformat | default "January 02, 2006") }}
-{{ $lastmod := .Lastmod | time.Format (site.Params.dateformat | default "January 02, 2006") }}
+{{ $date := .Date | time.Format (site.Params.dateFormat | default "January 02, 2006") }}
+{{ $lastmod := .Lastmod | time.Format (site.Params.dateFormat | default "January 02, 2006") }}
<time datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}">
{{ $date }}