diff options
| author | Eltrac <hi@guhub.cn> | 2025-05-29 16:16:33 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-05-29 16:16:33 +0800 |
| commit | 3b1d708c6d8e7eb2c46d50e7a97dbf5bf8b3bc3c (patch) | |
| tree | f3559d5e4bdf34120af4921517d0338c5588de95 /layouts | |
| parent | b7a4a3f673186e87edba9afc7048ea4977c93cb2 (diff) | |
feat(post): add fuzzy time after date
Former-commit-id: 2f6ef0c21dcf62d404a5b031e8eb39511631d667
Diffstat (limited to 'layouts')
| -rw-r--r-- | layouts/posts/single.html | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/layouts/posts/single.html b/layouts/posts/single.html index c08b7944..3fe80a84 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -20,11 +20,33 @@ <!-- Post Meta --> <div class="post-meta"> {{ if .Date }} - <time class="post-date" datetime="{{ .Date.Format "2006-01-02 15:04:05 MST" }}"> - {{ .Date.Format "2006-1-2" }} - </time> + {{ $hour := .Date.Hour }} + {{ $fuzzyTime := "" }} + {{ if lt $hour 5 }} + {{ $fuzzyTime = "凌晨" }} + {{ else if lt $hour 7 }} + {{ $fuzzyTime = "清晨" }} + {{ else if lt $hour 11 }} + {{ $fuzzyTime = "早上" }} + {{ else if lt $hour 13 }} + {{ $fuzzyTime = "中午" }} + {{ else if lt $hour 17 }} + {{ $fuzzyTime = "下午" }} + {{ else if lt $hour 19 }} + {{ $fuzzyTime = "傍晚" }} + {{ else if lt $hour 23 }} + {{ $fuzzyTime = "晚上" }} + {{ else }} + {{ $fuzzyTime = "深夜" }} + {{ end }} + + <time class="post-date" datetime="{{ .Date.Format "2006-01-02 15:04:05 MST" }}"> + {{ .Date.Format "2006年1月2日" }} {{ $fuzzyTime }} + </time> {{ end }} + {{ if or .Params.categories .Params.tags }} <span>·</span> + {{ end }} {{ if .Params.categories }} <a class="post-category" href="/categories/{{ .Params.categories | urlize }}">{{ .Params.categories }}</a> {{ end }} |
