From c097ab90ab82e257d961b4122e690d25aeb1f6ea Mon Sep 17 00:00:00 2001
From: Peter Kleiweg <kleiweg@ziggo.nl>
Date: Wed, 13 Jul 2022 11:52:19 +0000
Subject: [PATCH] feat: localized dates (#373)
---
layouts/_default/list.html | 16 ++++++++++++++--
layouts/_default/single.html | 16 ++++++++++++++--
layouts/index.html | 16 ++++++++++++++--
exampleSite/config/_default/config.toml | 5 ++++-
4 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/exampleSite/config/_default/config.toml b/exampleSite/config/_default/config.toml
index 8eaa388..f39e07e 100644
--- a/exampleSite/config/_default/config.toml
+++ b/exampleSite/config/_default/config.toml
@@ -23,6 +23,9 @@
pygmentsCodeFences = true
pygmentsCodefencesGuessSyntax = true
+# Localized dates requires Hugo version 0.87.0
+localizedDates = false
+
[markup]
[markup.goldmark]
[markup.goldmark.renderer]
@@ -42,4 +45,4 @@
weight = 100
[[related.indices]]
name = 'tags'
- weight = 80
\ No newline at end of file
+ weight = 80
diff --git a/layouts/_default/list.html b/layouts/_default/list.html
index 8e0e67b..0f985b5 100644
--- a/layouts/_default/list.html
+++ b/layouts/_default/list.html
@@ -16,11 +16,23 @@
<a class="archive__list-title" href="{{ .RelPermalink }}" title="{{ .Title }}">{{ .Title }}</a>
<div class="archive__list-date">
{{ if isset .Site.Params "listdateformat" }}
- {{ .Date.Format .Site.Params.listDateFormat }}
+ {{ if .Site.Params.localizedDates }}
+ {{ time.Format .Site.Params.listDateFormat .Date }}
+
+ {{ else }}
+ {{ .Date.Format .Site.Params.listDateFormat }}
+
+ {{ end }}
{{ else }}
- {{ .Date.Format "Jan 2" }}
+ {{ if .Site.Params.localizedDates }}
+ {{ time.Format "Jan 2" .Date }}
+
+ {{ else }}
+ {{ .Date.Format "Jan 2" }}
+
+ {{ end }}
{{ end }}
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index f9ddd5a..c2d2f86 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -22,11 +22,23 @@
<em class="fas fa-calendar-day post__meta-icon"></em>
<span class="post__meta-text"
>{{ if isset .Site.Params "singledateformat" }}
- {{ .Date.Format .Site.Params.singleDateFormat }}
+ {{ if .Site.Params.localizedDates }}
+ {{ time.Format .Site.Params.singleDateFormat .Date }}
+
+ {{ else }}
+ {{ .Date.Format .Site.Params.singleDateFormat }}
+
+ {{ end }}
{{ else }}
- {{ .Date.Format "Mon, Jan 2, 2006" }}
+ {{ if .Site.Params.localizedDates }}
+ {{ time.Format "Mon, Jan 2, 2006" .Date }}
+
+ {{ else }}
+ {{ .Date.Format "Mon, Jan 2, 2006" }}
+
+ {{ end }}
{{ end }}
diff --git a/layouts/index.html b/layouts/index.html
index 486e59f..e8650c4 100644
--- a/layouts/index.html
+++ b/layouts/index.html
@@ -77,11 +77,23 @@
<em class="fas fa-calendar-day"></em>
<span class="post__footer-date"
>{{ if isset .Site.Params "indexdateformat" }}
- {{ .Date.Format .Site.Params.indexDateFormat }}
+ {{ if .Site.Params.localizedDates }}
+ {{ time.Format .Site.Params.indexDateFormat .Date }}
+
+ {{ else }}
+ {{ .Date.Format .Site.Params.indexDateFormat }}
+
+ {{ end }}
{{ else }}
- {{ .Date.Format "Mon, Jan 2, 2006" }}
+ {{ if .Site.Params.localizedDates }}
+ {{ time.Format "Mon, Jan 2, 2006" .Date }}
+
+ {{ else }}
+ {{ .Date.Format "Mon, Jan 2, 2006" }}
+
+ {{ end }}
{{ end }}</span
--
Gitblit v1.10.0