ensure menu item url has / suffix

This commit is contained in:
Reorx 2022-05-29 21:50:06 +08:00
parent 3398b4c6ab
commit 3b964af770
1 changed files with 3 additions and 3 deletions

View File

@ -117,11 +117,11 @@ window.addEventListener('toggle-theme', function() {
{{- $currentPage := . }}
<ul id="menu">
{{- range site.Menus.main }}
{{- $menu_item_url := (cond (strings.HasSuffix .URL "/") .URL (printf "%s/" .URL) ) | absURL }}
{{- $page_url:= $currentPage.Permalink | absURL }}
{{- $menu_item_url := (cond (strings.HasSuffix .URL "/") .URL (printf "%s/" .URL)) | absURL }}
{{- $page_url:= $currentPage.Permalink }}
{{- $is_search := eq (site.GetPage .KeyName).Layout `search` }}
<li>
<a href="{{ .URL | absURL }}" title="{{ .Title | default .Name }} {{- cond $is_search (" (Alt + /)" | safeHTMLAttr) ("" | safeHTMLAttr ) }}"
<a href="{{ $menu_item_url }}" title="{{ .Title | default .Name }} {{- cond $is_search (" (Alt + /)" | safeHTMLAttr) ("" | safeHTMLAttr ) }}"
{{- if $is_search -}}data-no-instant{{- end -}}
{{- cond $is_search (" accesskey=/" | safeHTMLAttr) ("" | safeHTMLAttr ) }}
{{- if eq $menu_item_url $page_url }} class="active" {{- end }}