From b0bf3ccca1a431feb7b788b2ec1210aa903bed97 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Fri, 1 Oct 2021 19:45:22 +0200 Subject: [PATCH] Allow override of date format (#291) Previously the default date format (`January 2, 2006` ) was used for blog and single page date visualizations. The new parameter `date_format` can be used to override this format. This allows the visualization of localized dates or a changed precision (down to the minute or up to the month or year of publication). Co-authored-by: Regis Philibert --- README.md | 12 ++++++++++++ layouts/_default/single.html | 2 +- layouts/post/summary.html | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9f88248..b8da506 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,18 @@ You can replace the title of your site in the top left corner of each page with ``` +### Localize date format + +Dates of blog posts and single pages are rendered with the default date format commonly used in the USA and Canada. It is possible to specify a different format. + +``` +[params] + date_format = "2. January 2006" +``` + +See hugo's documentation of the [`dateFormat` function](https://gohugo.io/functions/dateformat/) for more details. + + ### Nearly finished In order to see your site in action, run Hugo's built-in local server. diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 0c7b97b..fe2c3b3 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 b2779cf..5856b4a 100644 --- a/layouts/post/summary.html +++ b/layouts/post/summary.html @@ -1,7 +1,7 @@
{{ if .Date }}
- {{ .Date.Format "January 2, 2006" }} + {{ .Date.Format (default "January 2, 2006" .Site.Params.date_format) }}
{{ end }}