From b30b876bb9d2103d259eb9cc02c5a9ba372c0397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 26 Jul 2021 18:28:57 +0200 Subject: [PATCH 1/4] Localize time.Format Fixes #8797 --- content/en/functions/dateformat.md | 44 +++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/content/en/functions/dateformat.md b/content/en/functions/dateformat.md index e5fb3608d..d56a91f02 100644 --- a/content/en/functions/dateformat.md +++ b/content/en/functions/dateformat.md @@ -1,6 +1,6 @@ --- -title: dateFormat -description: Converts the textual representation of the `datetime` into the specified format. +title: time.Format +description: Converts a date/time to a localized string. godocref: https://golang.org/pkg/time/ date: 2017-02-01 publishdate: 2017-02-01 @@ -10,23 +10,47 @@ menu: docs: parent: "functions" keywords: [dates,time,strings] -signature: ["dateFormat LAYOUT INPUT"] +signature: ["time.Format LAYOUT INPUT"] workson: [] hugoversion: relatedfuncs: [Format,now,Unix,time] deprecated: false --- -`dateFormat` converts a timestamp string `INPUT` into the format specified by the `LAYOUT` string. +`time.Format` (alias `dateFormat`) converts either a `time.Time` object (e.g. `.Date`) or a timestamp string `INPUT` into the format specified by the `LAYOUT` string. -``` -{{ dateFormat "Monday, Jan 2, 2006" "2015-01-21" }} → "Wednesday, Jan 21, 2015" +```go-html-template +{{ time.Format "Monday, Jan 2, 2006" "2015-01-21" }} → "Wednesday, Jan 21, 2015" ``` -{{% warning %}} -As of v0.19 of Hugo, the `dateFormat` function is *not* supported as part of Hugo's [multilingual feature](/content-management/multilingual/). -{{% /warning %}} +Note that since Hugo 0.87.0, `time.Format` will return a localized string for the currrent language. {{< new-in "0.87.0" >}} -See [Go’s Layout String](/functions/format/#gos-layout-string) to learn about how the `LAYOUT` string has to be formatted. There are also some useful examples. +The `LAYOUT` string can be either: + +* [Go’s Layout String](/functions/format/#gos-layout-string) to learn about how the `LAYOUT` string has to be formatted. There are also some useful examples. +* A custom Hugo layout identifier (see full list below) See the [`time` function](/functions/time/) to convert a timestamp string to a Go `time.Time` type value. + + +## Date/time formatting layouts + +{{< new-in "0.87.0" >}} + +Go's date layout strings can be hard to reason about, especially with multiple languages. Since Hugo 0.87.0 you can alternatively use some predefined layout idenfifiers that will output localized dates or times: + +```go-html-template +{{ .Date | time.Format ":date_long" }} +``` + +The full list of custom layouts with examples for English: + +* `:date_full` => `Wednesday, June 6, 2018` +* `:date_long` => `June 6, 2018` +* `:date_medium` => `Jun 6, 2018` +* `:date_short` => `6/6/18` + +* `:time_full` => `2:09:37 am UTC` +* `:time_long` => `2:09:37 am UTC` +* `:time_medium` => `2:09:37 am` +* `:time_short` => `2:09 am` From 93f986ecc8daf17d3f5a3aa2c261dbe95960ee63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 27 Jul 2021 13:45:05 +0200 Subject: [PATCH 2/4] Add timezone support for front matter dates without one Fixes #8810 --- content/en/functions/time.md | 6 ++++-- content/en/getting-started/configuration.md | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/content/en/functions/time.md b/content/en/functions/time.md index c4f74215b..6c7f5aec6 100644 --- a/content/en/functions/time.md +++ b/content/en/functions/time.md @@ -11,7 +11,7 @@ menu: docs: parent: "functions" keywords: [dates,time,location] -signature: ["time INPUT [LOCATION]"] +signature: ["time INPUT [TIMEZONE]"] workson: [] hugoversion: "v0.77.0" relatedfuncs: [] @@ -29,10 +29,12 @@ aliases: [] ## Using Locations -The optional `LOCATION` parameter is a string that sets a default location that is associated with the specified time value. If the time value has an explicit timezone or offset specified, it will take precedence over the `LOCATION` parameter. +The optional `TIMEZONE` parameter is a string that sets a default time zone (or more specific, the location, which represents the collection of time offsets in a geographical area) that is associated with the specified time value. If the time value has an explicit timezone or offset specified, it will take precedence over the `TIMEZONE` parameter. The list of valid locations may be system dependent, but should include `UTC`, `Local`, or any location in the [IANA Time Zone database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). +If no `TIMEZONE` is set, the `timeZone` from site configuration will be used. + ``` {{ time "2020-10-20" }} → 2020-10-20 00:00:00 +0000 UTC {{ time "2020-10-20" "America/Los_Angeles" }} → 2020-10-20 00:00:00 -0700 PDT diff --git a/content/en/getting-started/configuration.md b/content/en/getting-started/configuration.md index 36c8c1b50..3f236dc02 100644 --- a/content/en/getting-started/configuration.md +++ b/content/en/getting-started/configuration.md @@ -299,6 +299,9 @@ themesDir ("themes") timeout (10000) : Timeout for generating page contents, in milliseconds (defaults to 10 seconds). *Note:* this is used to bail out of recursive content generation, if your pages are slow to generate (e.g., because they require large image processing or depend on remote contents) you might need to raise this limit. +timeZone {{< new-in "0.86.0" >}} +: The time zone (or location), e.g. `Europe/Oslo`, used to parse front matter dates without such information and in the [`time` function](/functions/time/). + title ("") : Site title. From 198cdf8f04c746aae12c76362e543aafd4f1218a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 28 Jul 2021 12:28:52 +0200 Subject: [PATCH 3/4] tpl/lang: Add new localized versions of lang.FormatNumber etc. Fixes #8820 --- .../image-processing/index.md | 2 +- content/en/functions/{NumFmt.md => lang.md} | 21 ++--- content/en/functions/time.md | 1 + data/docs.json | 92 ++++++++++++++++--- layouts/template-func/page.html | 54 +++++++++++ 5 files changed, 143 insertions(+), 27 deletions(-) rename content/en/functions/{NumFmt.md => lang.md} (65%) create mode 100644 layouts/template-func/page.html diff --git a/content/en/content-management/image-processing/index.md b/content/en/content-management/image-processing/index.md index 76679717e..e2e964154 100644 --- a/content/en/content-management/image-processing/index.md +++ b/content/en/content-management/image-processing/index.md @@ -134,7 +134,7 @@ Or individually access EXIF data with dot access, e.g.: {{ end }} ``` -Some fields may need to be formatted with [`lang.NumFmt`]({{< relref "functions/numfmt" >}}) function to prevent display like `Aperture: 2.278934289` instead of `Aperture: 2.28`. +Some fields may need to be formatted with [`lang.FormatNumberCustom`]({{< relref "functions/lang" >}}) function to prevent display like `Aperture: 2.278934289` instead of `Aperture: 2.28`. #### Exif fields diff --git a/content/en/functions/NumFmt.md b/content/en/functions/lang.md similarity index 65% rename from content/en/functions/NumFmt.md rename to content/en/functions/lang.md index 9b51f597f..7b810c9be 100644 --- a/content/en/functions/NumFmt.md +++ b/content/en/functions/lang.md @@ -1,10 +1,8 @@ --- -title: lang.NumFmt -description: "Formats a number with a given precision using the requested `negative`, `decimal`, and `grouping` options. The `options` parameter is a string consisting of ` `." -godocref: "" -date: 2017-02-01 -publishdate: 2017-02-01 -lastmod: 2017-08-21 +title: lang +package: lang +description: "TODO.." +date: 2021-07-28 categories: [functions] keywords: [numbers] menu: @@ -12,18 +10,13 @@ menu: parent: "functions" toc: false signature: ["lang.NumFmt PRECISION NUMBER [OPTIONS [DELIMITER]]"] -workson: [] -hugoversion: -relatedfuncs: [] -deprecated: false -draft: false -aliases: [] -comments: +aliases: ['/functions/numfmt/'] +type: 'template-func' --- The default options value is `- . ,`. The default delimiter within the options value is a space. If you need to use a space as one of the options, set a -custom delimiter. +custom delimiter.s Numbers greater than or equal to 5 are rounded up. For example, if precision is set to `0`, `1.5` becomes `2`, and `1.4` becomes `1`. diff --git a/content/en/functions/time.md b/content/en/functions/time.md index 6c7f5aec6..e1f24a40b 100644 --- a/content/en/functions/time.md +++ b/content/en/functions/time.md @@ -19,6 +19,7 @@ deprecated: false aliases: [] --- + `time` converts a timestamp string with an optional default location into a [`time.Time`](https://godoc.org/time#Time) structure so you can access its fields: ``` diff --git a/data/docs.json b/data/docs.json index d0edcb67f..9925a57e6 100644 --- a/data/docs.json +++ b/data/docs.json @@ -1677,6 +1677,9 @@ "caches": { "_merge": "none" }, + "cascade": { + "_merge": "none" + }, "frontmatter": { "_merge": "none" }, @@ -1745,7 +1748,7 @@ "keepDocumentTags": true, "keepEndTags": true, "keepQuotes": false, - "keepWhitespace": false + "keepWhitespace": true }, "css": { "keepCSS2": true, @@ -1756,7 +1759,8 @@ "keepVarNames": false }, "json": { - "precision": 0 + "precision": 0, + "keepNumbers": false }, "svg": { "precision": 0 @@ -3898,14 +3902,52 @@ } }, "lang": { - "Merge": { - "Description": "", - "Args": null, + "FormatAccounting": { + "Description": "FormatAccounting returns the currency reprecentation of number for the given currency and precision\nfor the current language in accounting notation.", + "Args": [ + "precision", + "currency", + "number" + ], "Aliases": null, - "Examples": null + "Examples": [ + [ + "{{ 512.5032 | lang.FormatAccounting 2 \"NOK\" }}", + "NOK512.50" + ] + ] }, - "NumFmt": { - "Description": "NumFmt formats a number with the given precision using the\nnegative, decimal, and grouping options. The `options`\nparameter is a string consisting of `\u003cnegative\u003e \u003cdecimal\u003e \u003cgrouping\u003e`. The\ndefault `options` value is `- . ,`.\n\nNote that numbers are rounded up at 5 or greater.\nSo, with precision set to 0, 1.5 becomes `2`, and 1.4 becomes `1`.", + "FormatCurrency": { + "Description": "FormatCurrency returns the currency reprecentation of number for the given currency and precision\nfor the current language.", + "Args": [ + "precision", + "currency", + "number" + ], + "Aliases": null, + "Examples": [ + [ + "{{ 512.5032 | lang.FormatCurrency 2 \"USD\" }}", + "$512.50" + ] + ] + }, + "FormatNumber": { + "Description": "FormatNumber formats number with the given precision for the current language.", + "Args": [ + "precision", + "number" + ], + "Aliases": null, + "Examples": [ + [ + "{{ 512.5032 | lang.FormatNumber 2 }}", + "512.50" + ] + ] + }, + "FormatNumberCustom": { + "Description": "FormatNumberCustom formats a number with the given precision using the\nnegative, decimal, and grouping options. The `options`\nparameter is a string consisting of `\u003cnegative\u003e \u003cdecimal\u003e \u003cgrouping\u003e`. The\ndefault `options` value is `- . ,`.\n\nNote that numbers are rounded up at 5 or greater.\nSo, with precision set to 0, 1.5 becomes `2`, and 1.4 becomes `1`.\n\nFor a simpler function that adapts to the current language, see FormatNumberCustom.", "Args": [ "precision", "number", @@ -3914,19 +3956,19 @@ "Aliases": null, "Examples": [ [ - "{{ lang.NumFmt 2 12345.6789 }}", + "{{ lang.FormatNumberCustom 2 12345.6789 }}", "12,345.68" ], [ - "{{ lang.NumFmt 2 12345.6789 \"- , .\" }}", + "{{ lang.FormatNumberCustom 2 12345.6789 \"- , .\" }}", "12.345,68" ], [ - "{{ lang.NumFmt 6 -12345.6789 \"- .\" }}", + "{{ lang.FormatNumberCustom 6 -12345.6789 \"- .\" }}", "-12345.678900" ], [ - "{{ lang.NumFmt 0 -12345.6789 \"- . ,\" }}", + "{{ lang.FormatNumberCustom 0 -12345.6789 \"- . ,\" }}", "-12,346" ], [ @@ -3935,6 +3977,32 @@ ] ] }, + "FormatPercent": { + "Description": "FormatPercent formats number with the given precision for the current language.\nNote that the number is assumbed to be percent.", + "Args": [ + "precision", + "number" + ], + "Aliases": null, + "Examples": [ + [ + "{{ 512.5032 | lang.FormatPercent 2 }}", + "512.50%" + ] + ] + }, + "Merge": { + "Description": "", + "Args": null, + "Aliases": null, + "Examples": null + }, + "NumFmt": { + "Description": "", + "Args": null, + "Aliases": null, + "Examples": null + }, "Translate": { "Description": "Translate returns a translated string for id.", "Args": [ diff --git a/layouts/template-func/page.html b/layouts/template-func/page.html new file mode 100644 index 000000000..f08018e4f --- /dev/null +++ b/layouts/template-func/page.html @@ -0,0 +1,54 @@ +{{ $pkg := .Params.package}} +{{ $funcs := index site.Data.docs.tpl.funcs $pkg }} + +{{ range $k, $v := $funcs }} + {{ if $v.Description }} + {{ $func := printf "%s.%s" $pkg $k }} +

+ + + + + + + {{ $func }} +

+ {{ with $v.Description }} +

+ {{ . | $.RenderString | safeHTML }} +

+ {{ end }} +

+ Syntax +

+
+ {{ $pkg }}.{{ $k }} + {{ with $v.Args }} + + {{ delimit $v.Args ", "}} + + {{ end }} + +
+ {{ if $v.Examples }} +

+ Examples +

+ {{ end }} + {{ range $v.Examples }} + {{ $input := index . 0 }} + {{ $result := index . 1 }} + {{ $example := printf "%s ---> %s" $input $result }} + + {{ highlight $example "go-html-template" "" }} + {{ end }} + {{ with $v.Aliases }} +

+ Aliases +

+

+ {{ delimit . ", "}} +

+ {{ end }} + {{ end }} +{{ end }} From 276da91a8b685f467caa1ad58452ab37748a4e7a Mon Sep 17 00:00:00 2001 From: hugoreleaser Date: Fri, 30 Jul 2021 10:13:32 +0000 Subject: [PATCH 4/4] releaser: Add release notes to /docs for release of 0.86.1 [ci skip] --- content/en/news/0.86.1-relnotes/index.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 content/en/news/0.86.1-relnotes/index.md diff --git a/content/en/news/0.86.1-relnotes/index.md b/content/en/news/0.86.1-relnotes/index.md new file mode 100644 index 000000000..4c1926388 --- /dev/null +++ b/content/en/news/0.86.1-relnotes/index.md @@ -0,0 +1,19 @@ + +--- +date: 2021-07-30 +title: "Hugo 0.86.1: A couple of Bug Fixes" +description: "This version fixes a couple of bugs introduced in 0.86.0." +categories: ["Releases"] +images: +- images/blog/hugo-bug-poster.png + +--- + + + +This is a bug-fix release with one important fix. + +* config: Fix a potential deadlock in config reading [94b616bd](https://github.com/gohugoio/hugo/commit/94b616bdfad177daa99f5e87535943f509198f6f) [@bep](https://github.com/bep) [#8791](https://github.com/gohugoio/hugo/issues/8791) + + +