Skip to content

Commit

Permalink
feat: localized dates (#373)
Browse files Browse the repository at this point in the history
Adds localized dates to the theme.

Requires Hugo version 0.87.0v or above.
  • Loading branch information
pebbe committed Jul 13, 2022
1 parent 2fbe51c commit c097ab9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
5 changes: 4 additions & 1 deletion exampleSite/config/_default/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pygmentsUseClasses = true
pygmentsCodeFences = true
pygmentsCodefencesGuessSyntax = true

# Localized dates requires Hugo version 0.87.0
localizedDates = false

[markup]
[markup.goldmark]
[markup.goldmark.renderer]
Expand All @@ -42,4 +45,4 @@ pygmentsCodefencesGuessSyntax = true
weight = 100
[[related.indices]]
name = 'tags'
weight = 80
weight = 80
16 changes: 14 additions & 2 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
16 changes: 14 additions & 2 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,23 @@ <h1>{{ title .Title }}</h1>
<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 }}
Expand Down
16 changes: 14 additions & 2 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,23 @@ <h3><a href="{{ .RelPermalink }}">{{ upper .Title }}</a></h3>
<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
Expand Down

0 comments on commit c097ab9

Please sign in to comment.