summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-05-09 09:15:54 +0800
committerEltrac <hi@guhub.cn>2025-05-09 09:15:54 +0800
commit60c6db24926a85339f9d18f321c71715e851927b (patch)
treef32b75318e5a404ae4e70d91dcf53c9a7c955746
parentba64ff3fe7e8429e47d158a60a2160773a687906 (diff)
refactor: language switch link with dict
also add umami event data Former-commit-id: b886b28609133f2d10f278a1dfaa8e01f3eb43ec
-rw-r--r--layouts/partials/header.html13
1 files changed, 8 insertions, 5 deletions
diff --git a/layouts/partials/header.html b/layouts/partials/header.html
index 9f6d4f78..8dcf770d 100644
--- a/layouts/partials/header.html
+++ b/layouts/partials/header.html
@@ -18,10 +18,13 @@
</div>
{{ end }}
</nav>
- {{ if eq .Site.Language.Lang "en" }}
- <a href="/zh/" class="no-swup" title="切换至中文">{{ partial "snippets/globe-icon" . }}</a>
- {{ else if eq .Site.Language.Lang "zh" }}
- <a href="/en/" class="no-swup" title="Switch to English">{{ partial "snippets/globe-icon" . }}</a>
- {{ end }}
+
+ {{- $lang := .Site.Language.Lang -}}
+ {{- $switch := dict "en" (dict "url" "/zh/" "label" "切换至中文") "zh" (dict "url" "/en/" "label" "Switch to English") -}}
+ {{- $entry := index $switch $lang -}}
+ <a href="{{ $entry.url }}" data-umami-event="Switch Language"
+ class="no-swup" title="{{ $entry.label }}">
+ {{ partial "snippets/globe-icon" . }}
+ </a>
</div>
</header>