Skip to content

Commit ad0129a

Browse files
committed
feat: 更新日期和时间格式化,替换 medium 为 long 避免上游错误
1 parent 659995b commit ad0129a

7 files changed

Lines changed: 63 additions & 21 deletions

File tree

exampleSite/config/_default/params.yaml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,23 +233,46 @@ readingProgress:
233233
# 1) Hugo localization tokens (recommended): ":date_full" / ":date_long" / ":date_medium" / ":date_short"
234234
# Automatically localized based on the current language's locale
235235
# (e.g., en → "January 2, 2006", zh-Hans → "2006年1月2日").
236+
# NOTE: ":date_medium" currently has an upstream bug under en-GB (month is omitted except September),
237+
# so the theme uses ":date_long" for places that previously used medium.
236238
# 2) Go time layout string: reference time is "Mon Jan 2 15:04:05 MST 2006". Examples:
237239
# "2006-01-02" → 2024-05-01
238240
# "January 2, 2006" → May 1, 2024
239241
# "2006年1月2日" → 2024年5月1日
240242
# "Jan 2, 2006" → May 1, 2024
241243
# "02 Jan 2006" → 01 May 2024
242-
# Usage:
243-
# long : Article detail page, homepage hero
244-
# medium : List / card / timeline / JSON Feed
245-
# short : Archive page, previous/next article
244+
# Usage (which variants the theme actually renders):
245+
# full : reserved for opt-in custom usage
246+
# long : article detail page, homepage hero, list / card / timeline / JSON Feed,
247+
# archive page, previous/next article (i.e. all theme-rendered dates)
248+
# medium : not used by the theme by default (kept here for user customization)
249+
# short : not used by the theme by default (kept here for user customization)
246250
# Leave empty to keep the defaults below.
247251
# To configure per language, override via languages.<lang>.params.dateFormat in languages.yaml.
248252
dateFormat:
253+
full: ":date_full"
249254
long: ":date_long"
250255
medium: ":date_medium"
251256
short: ":date_short"
252257
# Custom examples:
253258
# long: "January 2, 2006"
254259
# medium: "2006-01-02"
255260
# short: "01/02"
261+
262+
# Time format (optional)
263+
#
264+
# Used by helpers/date.html when called with kind="time", e.g.:
265+
# {{ partial "helpers/date.html" (dict "date" .Date "variant" "short" "kind" "time") }}
266+
# Same value rules as dateFormat: either Hugo localization tokens
267+
# (":time_full" / ":time_long" / ":time_medium" / ":time_short") or a Go time layout
268+
# string (e.g. "15:04", "3:04 PM"). The theme does not render time values out of the
269+
# box; this block exists so users / custom partials can use it without extra config.
270+
# Per-language override is also supported via languages.<lang>.params.timeFormat.
271+
timeFormat:
272+
full: ":time_full"
273+
long: ":time_long"
274+
medium: ":time_medium"
275+
short: ":time_short"
276+
# Custom examples:
277+
# long: "15:04:05"
278+
# short: "3:04 PM"

layouts/_partials/content/card-base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<div class="flex items-center gap-1.5">
7373
{{ partial "features/icon.html" (dict "name" "calendar" "size" "sm" "ariaLabel" "") }}
7474
<time datetime="{{ $page.Date.Format `2006-01-02` }}" class="font-medium">
75-
{{ partial "helpers/date.html" (dict "date" $page.Date "variant" "medium") }}
75+
{{ partial "helpers/date.html" (dict "date" $page.Date "variant" "long") }}
7676
</time>
7777
</div>
7878

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
11
{{- /*
2-
日期格式化辅助 partial。
2+
日期 / 时间格式化辅助 partial。
33

4-
根据 site.Params.dateFormat 渲染日期,可被 languages.<lang>.params.dateFormat 覆盖。
5-
支持两种格式:
6-
- Hugo 本地化 token:":date_full" / ":date_long" / ":date_medium" / ":date_short"
7-
(依据当前语言的 locale 自动本地化输出)
8-
- Go 时间布局串:例如 "2006-01-02"、"January 2, 2006"、"2006年1月2日"
9-
(按字面输出,不本地化)
4+
根据 site.Params.dateFormat(kind=date)或 site.Params.timeFormat(kind=time)渲染输入值,
5+
可被 languages.<lang>.params.dateFormat / .timeFormat 覆盖。
6+
7+
支持两种格式串:
8+
- Hugo 本地化 token(依据当前语言的 locale 自动本地化):
9+
日期:":date_full" / ":date_long" / ":date_medium" / ":date_short"
10+
时间:":time_full" / ":time_long" / ":time_medium" / ":time_short"
11+
- Go 时间布局串(按字面输出,不本地化):
12+
例如 "2006-01-02"、"January 2, 2006"、"15:04"、"3:04 PM"
1013

1114
入参 (dict):
1215
date : time.Time,必填
13-
variant : "long" | "medium" | "short",可选,默认 "medium"
16+
variant : "full" | "long" | "medium" | "short",可选,默认 "long"
17+
kind : "date" | "time",可选,默认 "date"
1418

1519
使用示例:
1620
{{ partial "helpers/date.html" (dict "date" .Date "variant" "long") }}
21+
{{ partial "helpers/date.html" (dict "date" .Date "variant" "short" "kind" "time") }}
1722
*/ -}}
1823
{{- $date := .date -}}
19-
{{- $variant := .variant | default "medium" -}}
20-
{{- $defaults := dict "long" ":date_long" "medium" ":date_medium" "short" ":date_short" -}}
21-
{{- $configured := site.Params.dateFormat | default dict -}}
22-
{{- $format := (index $configured $variant) | default (index $defaults $variant) -}}
24+
{{- $variant := .variant | default "long" -}}
25+
{{- $kind := .kind | default "date" -}}
26+
{{- $defaults := dict
27+
"date" (dict
28+
"full" ":date_full"
29+
"long" ":date_long"
30+
"medium" ":date_medium"
31+
"short" ":date_short")
32+
"time" (dict
33+
"full" ":time_full"
34+
"long" ":time_long"
35+
"medium" ":time_medium"
36+
"short" ":time_short")
37+
-}}
38+
{{- $configKey := cond (eq $kind "time") "timeFormat" "dateFormat" -}}
39+
{{- $configured := (index site.Params $configKey) | default dict -}}
40+
{{- $kindDefaults := index $defaults $kind -}}
41+
{{- $format := (index $configured $variant) | default (index $kindDefaults $variant) -}}
2342
{{- $date | time.Format $format -}}

layouts/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"content" .Plain
1414
"permalink" .RelPermalink
1515
"section" .Section
16-
"date" (partial "helpers/date.html" (dict "date" .Date "variant" "medium"))
16+
"date" (partial "helpers/date.html" (dict "date" .Date "variant" "long"))
1717
"readingTime" .ReadingTime
1818
"tags" (.Params.tags | default (slice))
1919
"categories" (.Params.categories | default (slice))

layouts/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ <h2 class="text-foreground mb-2 text-xl font-semibold">
2929
{{ if .Date }}
3030
<div class="text-muted-foreground mb-3 text-sm">
3131
<time datetime="{{ .Date.Format ` 2006-01-02` }}">
32-
{{ partial "helpers/date.html" (dict "date" .Date "variant" "medium") }}
32+
{{ partial "helpers/date.html" (dict "date" .Date "variant" "long") }}
3333
</time>
3434
</div>
3535
{{ end }}

layouts/projects/single.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ <h1 class="text-foreground mb-4 text-3xl font-bold md:text-4xl lg:text-5xl">
5656
<div class="flex flex-wrap items-center gap-3 text-sm font-semibold">
5757
<div class="text-foreground">
5858
<time datetime="{{ .Date.Format `2006-01-02` }}">
59-
{{ partial "helpers/date.html" (dict "date" .Date "variant" "medium") }}
59+
{{ partial "helpers/date.html" (dict "date" .Date "variant" "long") }}
6060
</time>
6161
</div>
6262

layouts/timeline.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h1 class="text-foreground text-3xl font-bold">
1313
<div class="text-muted-foreground flex items-center gap-2 text-sm">
1414
{{ partial "features/icon.html" (dict "name" "calendar" "size" "sm" "ariaLabel" "") }}
1515
<time datetime="{{ .Format `2006-01-02` }}">
16-
{{ partial "helpers/date.html" (dict "date" . "variant" "medium") }}
16+
{{ partial "helpers/date.html" (dict "date" . "variant" "long") }}
1717
</time>
1818
</div>
1919
{{ end }}

0 commit comments

Comments
 (0)