Skip to content

Commit 05e28a7

Browse files
authored
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.
1 parent 162f3a3 commit 05e28a7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

layouts/_partials/navbar-link.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
{{- $external := .external -}}
66

77
{{- $active := or ($currentPage.HasMenuCurrent "main" $item) ($currentPage.IsMenuCurrent "main" $item) -}}
8+
{{- /* Additional check for section landing pages in multilingual sites (normalize trailing slashes) */ -}}
9+
{{- if and (not $active) $link -}}
10+
{{- $currentPath := strings.TrimSuffix "/" $currentPage.RelPermalink -}}
11+
{{- $linkPath := strings.TrimSuffix "/" $link -}}
12+
{{- if eq $currentPath $linkPath -}}
13+
{{- $active = true -}}
14+
{{- end -}}
15+
{{- end -}}
816
{{- $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" -}}
917

1018
{{- if $item.HasChildren -}}

0 commit comments

Comments
 (0)