mirror of https://github.com/theNewDynamic/gohugo-theme-ananke.git

Charles Brunet
21.15.2022 5520ed119f1e587cf51727de2360da9252512967
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
3 files modified
7 ■■■■■ changed files
README.md 3 ●●●● patch | view | raw | blame | history
layouts/_default/single.html 2 ●●● patch | view | raw | blame | history
layouts/post/summary.html 2 ●●● patch | view | raw | blame | history
README.md
@@ -288,7 +288,8 @@
  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
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 }}
      <time class="f6 mv4 dib tracked" {{ printf `datetime="%s"` (.Date.Format "2006-01-02T15:04:05Z07:00") | safeHTMLAttr }}>
        {{- .Date.Format (default "January 2, 2006" .Site.Params.date_format) -}}
        {{- .Date | time.Format (default "January 2, 2006" .Site.Params.date_format) -}}
      </time>
      {{end}}
layouts/post/summary.html
@@ -1,7 +1,7 @@
  <div class="mb3 pa4 {{ $.Param "text_color" | default "mid-gray" }} overflow-hidden">
    {{ if .Date }}
      <div class="f6">
        {{ .Date.Format (default "January 2, 2006" .Site.Params.date_format) }}
        {{ .Date | time.Format (default "January 2, 2006" .Site.Params.date_format) }}
      </div>
    {{ end }}
    <h1 class="f3 near-black">