fix navbar fragment and allow parent link

fragment as `url: "#about"` are now associated to home page and menu main with children can also have link
This commit is contained in:
CravateRouge 2025-03-28 15:09:57 +08:00 committed by GitHub
commit 49f51cf633
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -57,6 +57,17 @@
{{ $menuURL := .URL | absLangURL }} {{ $menuURL := .URL | absLangURL }}
{{ $pageURL:= $currentPage.Permalink | absLangURL }} {{ $pageURL:= $currentPage.Permalink | absLangURL }}
{{ $active := eq $menuURL $pageURL }} {{ $active := eq $menuURL $pageURL }}
{{ $url := "" }}
{{ if .URL }}
{{- if findRE `^#` .URL -}}
{{- if not $.IsHome -}}
{{- $url = site.Home.RelPermalink -}}
{{- end }}
{{- $url = printf "%s%s" $url .URL -}}
{{- else -}}
{{- $url = .URL | relLangURL -}}
{{- end -}}
{{ end }}
{{ if .HasChildren }} {{ if .HasChildren }}
<li class="nav-item nav-dropdown group relative"> <li class="nav-item nav-dropdown group relative">
<span <span
@ -65,7 +76,11 @@
{{ $active := eq $childURL $pageURL }} {{ $active := eq $childURL $pageURL }}
{{ if $active }}active{{ end }} {{ if $active }}active{{ end }}
{{ end }} inline-flex items-center"> {{ end }} inline-flex items-center">
{{- if $url -}}<a class="{{ if $active }}active{{- end -}}"
{{ if findRE `^http` .URL }}target="_blank" rel="noopener"{{ end }} href="{{$url}}">
{{- end -}}
{{ .Name }} {{ .Name }}
{{ if $url }}</a>{{ end }}
<svg class="h-4 w-4 fill-current inline-block" viewBox="0 0 20 20"> <svg class="h-4 w-4 fill-current inline-block" viewBox="0 0 20 20">
<path <path
d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" /> d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
@ -77,14 +92,16 @@
{{ $childURL := .URL | absLangURL }} {{ $childURL := .URL | absLangURL }}
{{ $active := eq $childURL $pageURL }} {{ $active := eq $childURL $pageURL }}
{{ $url := "" }} {{ $url := "" }}
{{- if findRE `^#` .URL -}} {{ if .URL }}
{{- if not $.IsHome -}} {{- if findRE `^#` .URL -}}
{{- $url = site.Home.RelPermalink -}} {{- if not $.IsHome -}}
{{- end }} {{- $url = site.Home.RelPermalink -}}
{{- $url = .URL -}} {{- end }}
{{- else -}} {{- $url = printf "%s%s" $url .URL -}}
{{- $url = .URL | relLangURL -}} {{- else -}}
{{- end -}} {{- $url = .URL | relLangURL -}}
{{- end -}}
{{ end }}
<li class="nav-dropdown-item"> <li class="nav-dropdown-item">
<a <a
class="nav-dropdown-link {{ if $active }}active{{- end -}}" class="nav-dropdown-link {{ if $active }}active{{- end -}}"
@ -99,15 +116,6 @@
</ul> </ul>
</li> </li>
{{ else }} {{ else }}
{{ $url := "" }}
{{- if findRE `^#` .URL -}}
{{- if not $.IsHome -}}
{{- $url = site.Home.RelPermalink -}}
{{- end }}
{{- $url = .URL -}}
{{- else -}}
{{- $url = .URL | relLangURL -}}
{{- end -}}
<li class="nav-item"> <li class="nav-item">
<a <a
class="nav-link {{ if $active }}active{{- end -}}" class="nav-link {{ if $active }}active{{- end -}}"