Skip to content

Commit 9190c04

Browse files
committed
fix: Fix timezone issue
To get the correct timezone from Hugo build we need: * Layout string in theme date format must have "MST". * Date front matter must have desired timezone as UTC offset. Example: For "Asia/Kolkata" timezone to get timezone abbrevation IST (Indian Standard Time) in Hugo build provide UTC offset "+0530" in date front matter. If this is not set then it shows as UTC time. * Set TZ environment variable to match desired timezone in Hugo build. ```bash TZ=Asia/Kolkata hugo ``` If this does not match the UTC offset timezone provided in date front matter then it just shows the UTC offset instead of timezone abbrevation.
1 parent 03b856f commit 9190c04

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

exampleSite/content/posts/markdown-syntax.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title = "Markdown Syntax Guide"
33
description = """Sample article showcasing basic Markdown syntax and \
44
formatting for HTML elements."""
55
draft = false
6-
date = "2023-07-28"
6+
date = "2024-05-06T01:22:51+0530"
77
author = "Hugo Authors"
88
tags = ["markdown", "xterm", "css", "html"]
99
categories = ["themes", "syntax"]

layouts/_default/single.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ <h1 class="post-title"><a href="{{ .Permalink }}">{{ .Title | markdownify }}</a>
88
{{- if or (.Params.Date) (.Params.Author) }}
99
<div class="post-meta">
1010
{{- with .Params.Date }}
11-
<time pubdate datetime="{{ .Format "2006-01-02 15:04:05 IST" }}">
11+
<time pubdate datetime="{{ .Format "2006-01-02 15:04:05 MST" }}">
1212
Published on
13-
{{ .Format "2006-01-02 15:04:05 IST" }}
13+
{{ .Format "2006-01-02 15:04:05 MST" }}
1414
</time>
1515
{{- end }}
1616

@@ -19,7 +19,7 @@ <h1 class="post-title"><a href="{{ .Permalink }}">{{ .Title | markdownify }}</a>
1919
{{- end }}
2020

2121
{{- with .Params.LastMod }}
22-
<time pubdate datetime="{{ .Format "2006-01-02 15:04:05 IST" }}"> last modified {{ .Format "2006-01-02 15:04:05 IST" }}. </time>
22+
<time pubdate datetime="{{ .Format "2006-01-02 15:04:05 MST" }}"> last modified {{ .Format "2006-01-02 15:04:05 MST" }}. </time>
2323
{{- end }}
2424
</div>
2525
{{- end }}

layouts/partials/footer.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{- /* site build info */}}
22
<p class="buildinfo">
33
{{- /* site build timestamp */}}
4-
<time datetime="{{ now.Format "2006-01-02 15:04:05 IST" }}">Site built on: {{ now.Format "2006-01-02 15:04:05 IST" }}</time>
4+
<time datetime="{{ now.Format "2006-01-02 15:04:05 MST" }}">Site built on: {{ now.Format "2006-01-02 15:04:05 MST" }}</time>
55

66
{{- with site.Params.git.last_commit -}}
77
{{- $commitUrl := "" -}}

layouts/partials/head/base.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<meta property="article:published_time" content="{{ time .Date }}" />
5353
{{- end }}
5454
{{- with .Params.LastMod }}
55-
<meta property="article:modified_time" content="{{ .Format "2006-01-02 15:04:05 IST" }}" />
55+
<meta property="article:modified_time" content="{{ .Format "2006-01-02 15:04:05 MST" }}" />
5656
{{- end }}
5757
<meta property="article:author" content="{{ .Params.Author | default site.Title }}" />
5858
{{- if .Params.cover -}}

layouts/slides/single.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ <h1 class="post-title"><a href="{{ .Permalink }}">{{ .Title | markdownify }}</a>
1919
{{- if or (.Params.Date) (.Params.Author) }}
2020
<div class="post-meta">
2121
{{- with .Params.Date }}
22-
<time pubdate datetime="{{ .Format "2006-01-02 15:04:05 IST" }}">
22+
<time pubdate datetime="{{ .Format "2006-01-02 15:04:05 MST" }}">
2323
Published on
24-
{{ .Format "2006-01-02 15:04:05 IST" }}
24+
{{ .Format "2006-01-02 15:04:05 MST" }}
2525
</time>
2626
{{- end }}
2727

@@ -30,7 +30,7 @@ <h1 class="post-title"><a href="{{ .Permalink }}">{{ .Title | markdownify }}</a>
3030
{{- end }}
3131

3232
{{- with .Params.LastMod }}
33-
<time pubdate datetime="{{ .Format "2006-01-02 15:04:05 IST" }}"> last modified {{ .Format "2006-01-02 15:04:05 IST" }}. </time>
33+
<time pubdate datetime="{{ .Format "2006-01-02 15:04:05 MST" }}"> last modified {{ .Format "2006-01-02 15:04:05 MST" }}. </time>
3434
{{- end }}
3535
</div>
3636
{{- end }}

0 commit comments

Comments
 (0)