Skip to content

Commit

Permalink
✨ Feat: menu link support empty url
Browse files Browse the repository at this point in the history
Close #531
  • Loading branch information
Lruihao committed Oct 31, 2024
1 parent 894c512 commit 8d10880
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 50 deletions.
4 changes: 4 additions & 0 deletions assets/css/_core/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ header {
}
}

.menu-link[href="javascript:void(0);"] {
color: inherit;
}

.menu-link i {
@include transform(perspective(1rem));
@include transition(transform 0.4s ease);
Expand Down
95 changes: 46 additions & 49 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@
<nav>
<ul class="menu">
{{- range .Site.Menus.main -}}
{{- $url := .URL | relLangURL -}}
{{- $url := .URL -}}
{{- with $url -}}
{{- $url = . | relLangURL -}}
{{- end -}}
{{- with .Page -}}
{{- $url = .RelPermalink -}}
{{- end -}}
{{- if (ne .Params.Draft true) | or $buildDrafts | and (ne .Params.Type "mobile") -}}
<li class="menu-item{{ if $.IsMenuCurrent `main` . | or ($.HasMenuCurrent `main` .) | or (eq $.RelPermalink $url) }} active{{ end }}{{ with .Params.Class }} {{ . }}{{ end }}{{ if .HasChildren }} has-children{{ end }}">
<a
class="menu-link"
href="{{ $url }}"
{{ with .Title }}title="{{ . }}"{{ end }}
{{ if (urls.Parse $url).Host }}rel="noopener noreferrer" target="_blank"{{ end }}
<a class="menu-link"
{{- with $url }} href="{{ $url }}"{{ else }} href="javascript:void(0);"{{ end }}
{{- with .Title }} title="{{ . }}"{{ end }}
{{- if (urls.Parse $url).Host }} rel="noopener noreferrer" target="_blank"{{ end -}}
>
{{- with .Pre -}}{{- . | safeHTML }} {{ end }}
{{- with .Params.Icon -}}{{ dict "Class" (printf "%v fa-fw fa-sm" .) | partial "plugin/icon.html" }} {{ end }}
Expand All @@ -59,22 +61,22 @@
{{ dict "Class" "dropdown-icon fa-solid fa-chevron-down" | partial "plugin/icon.html" }}
<ul class="sub-menu">
{{- range $k, $v := .Children -}}
{{- $url := $v.URL | relLangURL -}}
{{- $url := $v.URL -}}
{{- with $url -}}
{{- $url = . | relLangURL -}}
{{- end -}}
{{- with $v.Page -}}
{{- $url = .RelPermalink -}}
{{- end -}}
{{- if (ne $v.Params.Draft true) | or $buildDrafts | and (ne $v.Params.Type "mobile") -}}
{{- if $k | and $v.Params.Divided -}}
<li class="menu-item-divider" aria-hidden="true"></li>
{{- end -}}
<li
class="menu-item{{ if $.IsMenuCurrent `main` $v | or ($.HasMenuCurrent `main` $v) | or (eq $.RelPermalink $url) }} active{{ end }}{{ with $v.Params.Class }} {{ . }}{{ end }}"
>
<a
class="menu-link"
href="{{ $url }}"
{{ with $v.Title }}title="{{ . }}"{{ end }}
{{ if (urls.Parse $url).Host }}rel="noopener noreferrer" target="_blank"{{ end }}
<li class="menu-item{{ if $.IsMenuCurrent `main` $v | or ($.HasMenuCurrent `main` $v) | or (eq $.RelPermalink $url) }} active{{ end }}{{ with $v.Params.Class }} {{ . }}{{ end }}">
<a class="menu-link"
{{- with $url }} href="{{ $url }}"{{ else }} href="javascript:void(0);"{{ end }}
{{- with $v.Title }} title="{{ . }}"{{ end }}
{{- if (urls.Parse $url).Host }} rel="noopener noreferrer" target="_blank"{{ end -}}
>
{{- with $v.Pre -}}{{- . | safeHTML }} {{ end }}
{{- with $v.Params.Icon -}}{{ dict "Class" (printf "%v fa-fw fa-sm" .) | partial "plugin/icon.html" }} {{ end }}
Expand Down Expand Up @@ -128,17 +130,13 @@
{{- end -}}
{{- else if .IsTranslated -}}
{{- range .AllTranslations -}}
{{- if ne .Lang $.Lang -}}
<li class="menu-item">
<a href="{{ .RelPermalink }}" class="menu-link" title="{{ .Language.LanguageName }}">
{{- .Language.LanguageName -}}
</a>
</li>
{{- else -}}
<li class="menu-item">
<span class="menu-link text-secondary" title="{{ .Language.LanguageName }}">{{ .Language.LanguageName }}</span>
</li>
{{- end -}}
<li class="menu-item">
{{- if ne .Lang $.Lang -}}
<a href="{{ .RelPermalink }}" class="menu-link" title="{{ .Language.LanguageName }}">{{ .Language.LanguageName }}</a>
{{- else -}}
<span class="text-secondary" title="{{ .Language.LanguageName }}">{{ .Language.LanguageName }}</span>
{{- end -}}
</li>
{{- end -}}
{{- else -}}
<li class="menu-item">{{- T "header.noMoretTranslations" -}}</li>
Expand Down Expand Up @@ -213,21 +211,21 @@
{{- end -}}
{{- $currentPage := . -}}
{{- range .Site.Menus.main -}}
{{- $url := .URL | relLangURL -}}
{{- $url := .URL -}}
{{- with $url -}}
{{- $url = . | relLangURL -}}
{{- end -}}
{{- with .Page -}}
{{- $url = .RelPermalink -}}
{{- end -}}
{{- if (ne .Params.Draft true) | or $buildDrafts | and (ne .Params.Type "desktop") -}}
<li
class="menu-item{{ if $.IsMenuCurrent `main` . | or ($.HasMenuCurrent `main` .) | or (eq $.RelPermalink $url) }} active{{ end }}{{ with .Params.Class }} {{ . }}{{ end }}"
>
<li class="menu-item{{ if $.IsMenuCurrent `main` . | or ($.HasMenuCurrent `main` .) | or (eq $.RelPermalink $url) }} active{{ end }}{{ with .Params.Class }} {{ . }}{{ end }}">
{{- if .HasChildren -}}
<span class="nested-item">
<a
class="menu-link"
href="{{ $url }}"
{{ with .Title }}title="{{ . }}"{{ end }}
{{ if (urls.Parse $url).Host }}rel="noopener noreferrer" target="_blank"{{ end }}
<a class="menu-link"
{{- with $url }} href="{{ $url }}"{{ else }} href="javascript:void(0);"{{ end }}
{{- with .Title }} title="{{ . }}"{{ end }}
{{- if (urls.Parse $url).Host }} rel="noopener noreferrer" target="_blank"{{ end -}}
>
{{- with .Pre -}}{{- . | safeHTML }} {{ end }}
{{- with .Params.Icon -}}{{ dict "Class" (printf "%v fa-fw fa-sm" .) | partial "plugin/icon.html" }} {{ end }}
Expand All @@ -238,22 +236,22 @@
</span>
<ul class="sub-menu">
{{- range $k, $v := .Children -}}
{{- $url := $v.URL | relLangURL -}}
{{- $url := $v.URL -}}
{{- with $url -}}
{{- $url = . | relLangURL -}}
{{- end -}}
{{- with $v.Page -}}
{{- $url = .RelPermalink -}}
{{- end -}}
{{- if (ne $v.Params.Draft true) | or $buildDrafts | and (ne $v.Params.Type "desktop") -}}
{{- if $k | and $v.Params.Divided -}}
<li class="menu-item menu-item-divider" aria-hidden="true"></li>
{{- end -}}
<li
class="menu-item{{ if $.IsMenuCurrent `main` $v | or ($.HasMenuCurrent `main` $v) | or (eq $.RelPermalink $url) }} active{{ end }}{{ with $v.Params.Class }} {{ . }}{{ end }}"
>
<a
class="menu-link"
href="{{ $url }}"
{{ with $v.Title }}title="{{ . }}"{{ end }}
{{ if (urls.Parse $url).Host }}rel="noopener noreferrer" target="_blank"{{ end }}
<li class="menu-item{{ if $.IsMenuCurrent `main` $v | or ($.HasMenuCurrent `main` $v) | or (eq $.RelPermalink $url) }} active{{ end }}{{ with $v.Params.Class }} {{ . }}{{ end }}">
<a class="menu-link"
{{- with $url }} href="{{ $url }}"{{ else }} href="javascript:void(0);"{{ end }}
{{- with $v.Title }} title="{{ . }}"{{ end }}
{{- if (urls.Parse $url).Host }}rel="noopener noreferrer" target="_blank"{{ end -}}
>
{{- with $v.Pre -}}{{- . | safeHTML }} {{ end }}
{{- with $v.Params.Icon -}}{{ dict "Class" (printf "%v fa-fw fa-sm" .) | partial "plugin/icon.html" }} {{ end }}
Expand All @@ -265,11 +263,10 @@
{{- end -}}
</ul>
{{- else -}}
<a
class="menu-link"
href="{{ $url }}"
{{ with .Title }}title="{{ . }}"{{ end }}
{{ if (urls.Parse $url).Host }}rel="noopener noreferrer" target="_blank"{{ end }}
<a class="menu-link"
{{- with $url }} href="{{ $url }}"{{ else }} href="javascript:void(0);"{{ end }}
{{- with .Title }} title="{{ . }}"{{ end }}
{{- if (urls.Parse $url).Host }} rel="noopener noreferrer" target="_blank"{{ end -}}
>
{{- with .Pre -}}{{- . | safeHTML }} {{ end }}
{{- with .Params.Icon -}}{{ dict "Class" (printf "%v fa-fw fa-sm" .) | partial "plugin/icon.html" }} {{ end }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/init/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- .Scratch.Set "version" "v0.3.14-35221731" -}}
{{- .Scratch.Set "version" "v0.3.14-894c512b" -}}
{{- .Scratch.Set "this" dict -}}

{{- partial "init/detection-env.html" . -}}
Expand Down

0 comments on commit 8d10880

Please sign in to comment.