feat(navbar): enhance active link detection for multilingual section landing pages (#913)

- Added logic to normalize trailing slashes for section landing pages in multilingual sites, improving the accuracy of active link detection in the navbar.
- This enhancement ensures that the correct link is highlighted as active, providing a better user experience across different languages.
This commit is contained in:
Xin
2026-01-24 12:27:37 +00:00
committed by GitHub
parent 162f3a3fa7
commit 05e28a716d

View File

@@ -5,6 +5,14 @@
{{- $external := .external -}} {{- $external := .external -}}
{{- $active := or ($currentPage.HasMenuCurrent "main" $item) ($currentPage.IsMenuCurrent "main" $item) -}} {{- $active := or ($currentPage.HasMenuCurrent "main" $item) ($currentPage.IsMenuCurrent "main" $item) -}}
{{- /* Additional check for section landing pages in multilingual sites (normalize trailing slashes) */ -}}
{{- if and (not $active) $link -}}
{{- $currentPath := strings.TrimSuffix "/" $currentPage.RelPermalink -}}
{{- $linkPath := strings.TrimSuffix "/" $link -}}
{{- if eq $currentPath $linkPath -}}
{{- $active = true -}}
{{- end -}}
{{- end -}}
{{- $activeClass := cond $active "hx:font-medium" "hx:text-gray-600 hx:hover:text-gray-800 hx:dark:text-gray-400 hx:dark:hover:text-gray-200" -}} {{- $activeClass := cond $active "hx:font-medium" "hx:text-gray-600 hx:hover:text-gray-800 hx:dark:text-gray-400 hx:dark:hover:text-gray-200" -}}
{{- if $item.HasChildren -}} {{- if $item.HasChildren -}}