Skip to content

Commit

Permalink
fix: ineffective activeInSection=false
Browse files Browse the repository at this point in the history
  • Loading branch information
reuixiy committed Apr 1, 2024
1 parent c12c500 commit 9cd045f
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions layouts/partials/menu.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
<nav class="nav">
<ul class="menu" id="menu">
{{ if .Site.Params.activeInSection }}
{{ .Scratch.Set "currentPage" (.Site.GetPage (printf `/%s` .Section)) }}
{{ else }}
{{ .Scratch.Set "currentPage" . }}
{{ end }}
{{ $currentPage := .Scratch.Get "currentPage" }}
{{ $ctx := . }}
{{ $currentPage := . }}

{{ range .Site.Menus.main }}
{{ if and (eq .Identifier "theme-switcher") $.Site.Params.enableDarkMode }}
{{ if eq $.Site.Params.headerLayout "flex" }}
{{ $switcher := partial "components/dark-mode.html" $ctx }}
{{ $switcher := partial "components/dark-mode.html" $currentPage }}
{{ with $switcher }}
<li class="menu-item">
{{ . }}
Expand All @@ -20,7 +15,7 @@
{{ else if eq .Identifier "lang-switcher" }}
{{ if and $.Site.IsMultiLingual $.Site.Params.enableLangToggle }}
{{ if eq $.Site.Params.headerLayout "flex" }}
{{ $switcher := partial "components/multilingual.html" $ctx }}
{{ $switcher := partial "components/multilingual.html" $currentPage }}
{{ with $switcher }}
<li class="menu-item">
{{ . }}
Expand All @@ -32,11 +27,11 @@
{{ if and (eq $.Site.Params.headerLayout "flex") (or $.Site.Params.enableLunrSearch $.Site.Params.enableAlgoliaSearch) }}
{{- $iconName := (string .Post) -}}
<li class="menu-item search-item">
{{ partial "components/search.html" (dict "$" $ctx "iconName" $iconName) }}
{{ partial "components/search.html" (dict "$" $currentPage "iconName" $iconName) }}
</li>
{{ end }}
{{ else }}
<li class="menu-item{{ if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }} active{{ end }}">
<li class="menu-item{{ if or ($currentPage.IsMenuCurrent .Menu .) (and ($currentPage.HasMenuCurrent .Menu .) $.Site.Params.activeInSection) }} active{{ end }}">
{{- $linkType := (string .Pre) -}}
<a href="{{ .URL }}"{{ if eq $linkType "external" }} target="_blank" rel="external noopener"{{ end }}>
{{- $iconName := (string .Post) -}}
Expand Down

0 comments on commit 9cd045f

Please sign in to comment.