From 5520ed119f1e587cf51727de2360da9252512967 Mon Sep 17 00:00:00 2001 From: Charles Brunet Date: Thu, 21 Apr 2022 13:15:53 -0400 Subject: [PATCH] use time.Format to format dates. It allows dates to be localized. (#537) * use time.Format to format dates. It allows dates to be localized. * Keep old default format, to remain compatible with older versions of hugo --- README.md | 3 ++- layouts/_default/single.html | 2 +- layouts/post/summary.html | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9c087e1..e47cac4 100644 --- a/README.md +++ b/README.md @@ -288,7 +288,8 @@ Dates of blog posts and single pages are rendered with the default date format c date_format = "2. January 2006" ``` -See hugo's documentation of the [`dateFormat` function](https://gohugo.io/functions/dateformat/) for more details. +With hugo 0.87.0 and above, you can also use predefined layout, like `:date_full`, and it will output localized dates or times. +See hugo's documentation of the [`time.Format` function](https://gohugo.io/functions/dateformat/) for more details. ### Nearly finished diff --git a/layouts/_default/single.html b/layouts/_default/single.html index a40a4c5..a8978ed 100755 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -32,7 +32,7 @@ {{/* Hugo uses Go's date formatting is set by example. Here are two formats */}} {{ if not .Date.IsZero }} {{end}} diff --git a/layouts/post/summary.html b/layouts/post/summary.html index aa92cc7..05653f5 100644 --- a/layouts/post/summary.html +++ b/layouts/post/summary.html @@ -1,7 +1,7 @@
{{ if .Date }}
- {{ .Date.Format (default "January 2, 2006" .Site.Params.date_format) }} + {{ .Date | time.Format (default "January 2, 2006" .Site.Params.date_format) }}
{{ end }}