mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 07:18:57 +00:00
fix(layouts): replace deprecated .Site.BuildDrafts with HUGO_PARAMS_MENU_DRAFT env var
Use getenv "HUGO_PARAMS_MENU_DRAFT" to control draft menu item visibility, replacing the deprecated .Site.BuildDrafts (Hugo v0.156.0). (#702) Also refactors menu range loops to use `continue` for reduced nesting.
This commit is contained in:
@@ -10,7 +10,13 @@
|
||||
Called from: layouts/baseof.html.
|
||||
*/ -}}
|
||||
|
||||
{{- $buildDrafts := .Page.Draft -}}
|
||||
{{- /*
|
||||
Whether to show draft menu items in the navigation.
|
||||
Controlled via env var at build time: HUGO_PARAMS_MENU_DRAFT=true hugo server
|
||||
Replaces the deprecated .Site.BuildDrafts (Hugo v0.156.0).
|
||||
See: https://discourse.gohugo.io/t/deprecations-in-v0-156-0/56732/11
|
||||
*/ -}}
|
||||
{{- $menuDraft := getenv "HUGO_PARAMS_MENU_DRAFT" -}}
|
||||
{{- $relLangURL := relLangURL "" -}}
|
||||
|
||||
{{- /* Desktop header */ -}}
|
||||
@@ -57,51 +63,53 @@
|
||||
{{- 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"
|
||||
{{- 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-sm" .) | partial "plugin/icon.html" }} {{ end }}
|
||||
{{- .Name }}
|
||||
{{- with .Post }} {{ . | safeHTML -}}{{- end -}}
|
||||
</a>
|
||||
{{- if .HasChildren -}}
|
||||
{{ dict "Class" "dropdown-icon fa-solid fa-chevron-down" | partial "plugin/icon.html" }}
|
||||
<ul class="sub-menu">
|
||||
{{- range $k, $v := .Children -}}
|
||||
{{- $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"
|
||||
{{- 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-sm" .) | partial "plugin/icon.html" }} {{ end }}
|
||||
{{- $v.Name }}
|
||||
{{- with $v.Post }} {{ . | safeHTML -}}{{- end -}}
|
||||
</a>
|
||||
</li>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
</ul>
|
||||
{{- end -}}
|
||||
</li>
|
||||
{{- if (eq .Params.Type "mobile") | or (and (eq .Params.Draft true) (ne $menuDraft "true")) -}}
|
||||
{{ continue }}
|
||||
{{- end -}}
|
||||
<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"
|
||||
{{- 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-sm" .) | partial "plugin/icon.html" }} {{ end }}
|
||||
{{- .Name }}
|
||||
{{- with .Post }} {{ . | safeHTML -}}{{- end -}}
|
||||
</a>
|
||||
{{- if .HasChildren -}}
|
||||
{{ dict "Class" "dropdown-icon fa-solid fa-chevron-down" | partial "plugin/icon.html" }}
|
||||
<ul class="sub-menu">
|
||||
{{- range $k, $v := .Children -}}
|
||||
{{- $url := $v.URL -}}
|
||||
{{- with $url -}}
|
||||
{{- $url = . | relLangURL -}}
|
||||
{{- end -}}
|
||||
{{- with $v.Page -}}
|
||||
{{- $url = .RelPermalink -}}
|
||||
{{- end -}}
|
||||
{{- if (eq $v.Params.Type "mobile") | or (and (eq $v.Params.Draft true) (ne $menuDraft "true")) -}}
|
||||
{{ continue }}
|
||||
{{- end -}}
|
||||
{{- 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"
|
||||
{{- 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-sm" .) | partial "plugin/icon.html" }} {{ end }}
|
||||
{{- $v.Name }}
|
||||
{{- with $v.Post }} {{ . | safeHTML -}}{{- end -}}
|
||||
</a>
|
||||
</li>
|
||||
{{- end -}}
|
||||
</ul>
|
||||
{{- end -}}
|
||||
</li>
|
||||
{{- end -}}
|
||||
{{- if .Site.Menus.main -}}
|
||||
<li class="menu-item delimiter"></li>
|
||||
@@ -220,51 +228,12 @@
|
||||
{{- 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 }}">
|
||||
{{- if .HasChildren -}}
|
||||
<span class="nested-item">
|
||||
<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-sm" .) | partial "plugin/icon.html" }} {{ end }}
|
||||
{{- .Name }}
|
||||
{{- with .Post }} {{ . | safeHTML -}}{{- end -}}
|
||||
</a>
|
||||
{{ dict "Class" "dropdown-icon fa-solid fa-chevron-right" | partial "plugin/icon.html" }}
|
||||
</span>
|
||||
<ul class="sub-menu">
|
||||
{{- range $k, $v := .Children -}}
|
||||
{{- $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"
|
||||
{{- 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-sm" .) | partial "plugin/icon.html" }} {{ end }}
|
||||
{{- $v.Name }}
|
||||
{{- with $v.Post }} {{ . | safeHTML -}}{{- end -}}
|
||||
</a>
|
||||
</li>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
</ul>
|
||||
{{- else -}}
|
||||
{{- if (eq .Params.Type "desktop") | or (and (eq .Params.Draft true) (ne $menuDraft "true")) -}}
|
||||
{{ continue }}
|
||||
{{- 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"
|
||||
{{- with $url }} href="{{ $url }}"{{ else }} href="javascript:void(0);"{{ end }}
|
||||
{{- with .Title }} title="{{ . }}"{{ end }}
|
||||
@@ -275,9 +244,50 @@
|
||||
{{- .Name }}
|
||||
{{- with .Post }} {{ . | safeHTML -}}{{- end -}}
|
||||
</a>
|
||||
{{- end -}}
|
||||
</li>
|
||||
{{- end -}}
|
||||
{{ dict "Class" "dropdown-icon fa-solid fa-chevron-right" | partial "plugin/icon.html" }}
|
||||
</span>
|
||||
<ul class="sub-menu">
|
||||
{{- range $k, $v := .Children -}}
|
||||
{{- $url := $v.URL -}}
|
||||
{{- with $url -}}
|
||||
{{- $url = . | relLangURL -}}
|
||||
{{- end -}}
|
||||
{{- with $v.Page -}}
|
||||
{{- $url = .RelPermalink -}}
|
||||
{{- end -}}
|
||||
{{- if (eq $v.Params.Type "desktop") | or (and (eq $v.Params.Draft true) (ne $menuDraft "true")) -}}
|
||||
{{ continue }}
|
||||
{{- end -}}
|
||||
{{- 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"
|
||||
{{- 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-sm" .) | partial "plugin/icon.html" }} {{ end }}
|
||||
{{- $v.Name }}
|
||||
{{- with $v.Post }} {{ . | safeHTML -}}{{- end -}}
|
||||
</a>
|
||||
</li>
|
||||
{{- end -}}
|
||||
</ul>
|
||||
{{- else -}}
|
||||
<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-sm" .) | partial "plugin/icon.html" }} {{ end }}
|
||||
{{- .Name }}
|
||||
{{- with .Post }} {{ . | safeHTML -}}{{- end -}}
|
||||
</a>
|
||||
{{- end -}}
|
||||
</li>
|
||||
{{- end -}}
|
||||
<li class="menu-item menu-system">
|
||||
{{- if hugo.IsMultilingual -}}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
Called from: layouts/baseof.html.
|
||||
*/ -}}
|
||||
|
||||
{{- hugo.Store.Set "version" "v1.0.0-alpha-mszfs8xu" -}}
|
||||
{{- hugo.Store.Set "version" "v1.0.0-alpha-mszlegf7" -}}
|
||||
{{- .Store.Set "this" dict -}}
|
||||
|
||||
{{- partial "init/detection-env.html" . -}}
|
||||
|
||||
Reference in New Issue
Block a user