chore(hugo): Update shortcodes and templates to avoid calling isset on <nil>

pull/6077/head
Jason Stirnaman 2025-05-13 16:05:42 -05:00
parent 6f8707363d
commit 30f7495a72
9 changed files with 44 additions and 37 deletions

View File

@ -8,49 +8,49 @@
{{- if $index -}},{{- end }} {{- if $index -}},{{- end }}
{ {
"name": {{ .Name | jsonify }}, "name": {{ .Name | jsonify }},
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }}, "url": {{ absURL (default .URL .Params.url) | jsonify }},
"children": [ "children": [
{{- range $index, $entry := .Children -}} {{- range $index, $entry := .Children -}}
{{- if $index -}},{{- end }} {{- if $index -}},{{- end }}
{ {
"name": {{ .Name | jsonify }}, "name": {{ .Name | jsonify }},
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }}, "url": {{ absURL (default .URL .Params.url) | jsonify }},
"children": [ "children": [
{{- range $index, $entry := .Children -}} {{- range $index, $entry := .Children -}}
{{- if $index -}},{{- end }} {{- if $index -}},{{- end }}
{ {
"name": {{ .Name | jsonify }}, "name": {{ .Name | jsonify }},
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }}, "url": {{ absURL (default .URL .Params.url) | jsonify }},
"children": [ "children": [
{{- range $index, $entry := .Children -}} {{- range $index, $entry := .Children -}}
{{- if $index -}},{{- end }} {{- if $index -}},{{- end }}
{ {
"name": {{ .Name | jsonify }}, "name": {{ .Name | jsonify }},
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }}, "url": {{ absURL (default .URL .Params.url) | jsonify }},
"children": [ "children": [
{{- range $index, $entry := .Children -}} {{- range $index, $entry := .Children -}}
{{- if $index -}},{{- end }} {{- if $index -}},{{- end }}
{ {
"name": {{ .Name | jsonify }}, "name": {{ .Name | jsonify }},
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }}, "url": {{ absURL (default .URL .Params.url) | jsonify }},
"children": [ "children": [
{{- range $index, $entry := .Children -}} {{- range $index, $entry := .Children -}}
{{- if $index -}},{{- end }} {{- if $index -}},{{- end }}
{ {
"name": {{ .Name | jsonify }}, "name": {{ .Name | jsonify }},
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }}, "url": {{ absURL (default .URL .Params.url) | jsonify }},
"children": [ "children": [
{{- range $index, $entry := .Children -}} {{- range $index, $entry := .Children -}}
{{- if $index -}},{{- end }} {{- if $index -}},{{- end }}
{ {
"name": {{ .Name | jsonify }}, "name": {{ .Name | jsonify }},
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }}, "url": {{ absURL (default .URL .Params.url) | jsonify }},
"children": [ "children": [
{{- range $index, $entry := .Children -}} {{- range $index, $entry := .Children -}}
{{- if $index -}},{{- end }} {{- if $index -}},{{- end }}
{ {
"name": {{ .Name | jsonify }}, "name": {{ .Name | jsonify }},
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }}, "url": {{ absURL (default .URL .Params.url) | jsonify }},
"children": [ "children": [
{{ range .Children }} {{ range .Children }}
{{ end }} {{ end }}

View File

@ -13,7 +13,7 @@
</div> </div>
{{ else if eq .Kind "section" }} {{ else if eq .Kind "section" }}
<div class="important block"> <div class="important block">
{{ $packageTitle := cond (isset .Params "list_title") $.Params.list_title .Title }} {{ $packageTitle := default .Title .Params.list_title }}
{{ $packageName := replaceRE `^(.*)( package)` "<code>$1</code>$2" $packageTitle }} {{ $packageName := replaceRE `^(.*)( package)` "<code>$1</code>$2" $packageTitle }}
<p> <p>
The {{ $packageName | safeHTML }} is a user-contributed package The {{ $packageName | safeHTML }} is a user-contributed package

View File

@ -13,7 +13,7 @@
</div> </div>
{{ else if eq .Kind "section" }} {{ else if eq .Kind "section" }}
<div class="important block"> <div class="important block">
{{ $packageTitle := cond (isset .Params "list_title") $.Params.list_title .Title }} {{ $packageTitle := default .Title .Params.list_title }}
{{ $packageName := replaceRE `^(.*)( package)` "<code>$1</code>$2" $packageTitle }} {{ $packageName := replaceRE `^(.*)( package)` "<code>$1</code>$2" $packageTitle }}
<p> <p>
The {{ $packageName | safeHTML }} is experimental and <a href="{{ $expRiskURL }}">subject to change at any time</a>. The {{ $packageName | safeHTML }} is experimental and <a href="{{ $expRiskURL }}">subject to change at any time</a>.

View File

@ -2,9 +2,9 @@
{{ $product := index $productPathData 0 }} {{ $product := index $productPathData 0 }}
{{ $version := index $productPathData 1 }} {{ $version := index $productPathData 1 }}
{{ $tagSet := print $product "/" $version "/tags" }} {{ $tagSet := print $product "/" $version "/tags" }}
{{ if isset .Params $tagSet }} {{ with .Param $tagSet }}
<div class="tags"> <div class="tags">
{{ range .Param $tagSet }} {{ range . }}
{{ $name := . }} {{ $name := . }}
{{ with $.Site.GetPage (printf "/%s/%s" $tagSet ($name | urlize)) }} {{ with $.Site.GetPage (printf "/%s/%s" $tagSet ($name | urlize)) }}
<a class="tag btn" href="{{ .RelPermalink }}">{{ $name }}</a> <a class="tag btn" href="{{ .RelPermalink }}">{{ $name }}</a>

View File

@ -35,10 +35,10 @@
{{ else if eq $currentVersion nil}} {{ else if eq $currentVersion nil}}
{{ $scratch.Set "siteTitle" (print (index .Site.Data.products $product).name " Documentation") }} {{ $scratch.Set "siteTitle" (print (index .Site.Data.products $product).name " Documentation") }}
{{ else }} {{ else }}
{{ if (isset (index .Site.Data.products $product) "altname" ) }} {{ with (index .Site.Data.products $product).altname }}
{{ $scratch.Set "siteTitle" (print (index .Site.Data.products $product).altname " Documentation") }} {{ $scratch.Set "siteTitle" (print . " Documentation") }}
{{ else }} {{ else }}
{{ $scratch.Set "siteTitle" (print (index .Site.Data.products $product).name " Documentation") }} {{ $scratch.Set "siteTitle" (print (index $.Site.Data.products $product).name " Documentation") }}
{{ end }} {{ end }}
{{ end }} {{ end }}

View File

@ -4,37 +4,37 @@
{{ range $menu }} {{ range $menu }}
<li class="nav-category {{ if eq $page.RelPermalink .URL }}active{{end}}"> <li class="nav-category {{ if eq $page.RelPermalink .URL }}active{{end}}">
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }} {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a> <a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
{{ if .HasChildren }} {{ if .HasChildren }}
<ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"> <ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}">
{{ range .Children }} {{ range .Children }}
<li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}"> <li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}">
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }} {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a> <a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
{{ if .HasChildren }} {{ if .HasChildren }}
<ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"> <ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}">
{{ range .Children }} {{ range .Children }}
<li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}"> <li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}">
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }} {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a> <a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
{{ if .HasChildren }} {{ if .HasChildren }}
<ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"> <ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}">
{{ range .Children }} {{ range .Children }}
<li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}"> <li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}">
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }} {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a> <a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
{{ if .HasChildren }} {{ if .HasChildren }}
<ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"> <ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}">
{{ range .Children }} {{ range .Children }}
<li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}"> <li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}">
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }} {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a> <a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
{{ if .HasChildren }} {{ if .HasChildren }}
<ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"> <ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}">
{{ range .Children }} {{ range .Children }}
<li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}"> <li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}">
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }} {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a> <a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
<!-- Begin nested block --> <!-- Begin nested block -->
{{ if .HasChildren }} {{ if .HasChildren }}
@ -42,7 +42,7 @@
{{ range .Children }} {{ range .Children }}
<li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}"> <li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}">
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }} {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a> <a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
<!-- To add more nested layers, copy the nested block and paste it here --> <!-- To add more nested layers, copy the nested block and paste it here -->
</li> </li>
{{ end }} {{ end }}

View File

@ -18,9 +18,9 @@
{{ if eq $type "articles" }} {{ if eq $type "articles" }}
<div class="children-links"> <div class="children-links">
{{ range $pages.ByWeight }} {{ range $pages.ByWeight }}
{{ $title := cond ( isset .Params "list_title" ) (.Params.list_title | .RenderString) (.Title | .RenderString) }} {{ $title := default .Title .Params.list_title | .RenderString }}
{{ $url := cond ( isset .Params "external_url" ) .Params.external_url .RelPermalink }} {{ $url := default .RelPermalink .Params.external_url }}
{{ $target := cond ( isset .Params "external_url" ) "_blank" "" }} {{ $target := cond (ne .Params.external_url nil) "_blank" "" }}
{{ if eq $hlevel "h2"}} <h2 id="{{ anchorize $title }}"><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a></h2> {{ if eq $hlevel "h2"}} <h2 id="{{ anchorize $title }}"><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a></h2>
{{ else if eq $hlevel "h3"}} <h3 id="{{ anchorize $title }}"><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a></h3> {{ else if eq $hlevel "h3"}} <h3 id="{{ anchorize $title }}"><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a></h3>
{{ else if eq $hlevel "h4"}} <h4 id="{{ anchorize $title }}"><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a></h4> {{ else if eq $hlevel "h4"}} <h4 id="{{ anchorize $title }}"><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a></h4>
@ -69,7 +69,7 @@
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ if and (eq $readMore true) ( or (isset .Params "list_query_example") (isset .Params "list_code_example") ) }} {{ if and (eq $readMore true) (or .Params.list_query_example .Params.list_code_example) }}
<p class="read-more"><a href="{{ $url }}" target="{{ $target }}">Read more <span class="icon-chevron-right"></span></a></p> <p class="read-more"><a href="{{ $url }}" target="{{ $target }}">Read more <span class="icon-chevron-right"></span></a></p>
{{ end }} {{ end }}
{{ if eq $hr true }} {{ if eq $hr true }}
@ -94,10 +94,10 @@
<div class="children-links"> <div class="children-links">
<ul> <ul>
{{ range $pages.ByWeight }} {{ range $pages.ByWeight }}
{{ $title := cond ( isset .Params "list_title" ) (.Params.list_title | .RenderString) (.Title | .RenderString) }} {{ $title := default .Title .Params.list_title | .RenderString }}
{{ $url := cond ( isset .Params "external_url" ) .Params.external_url .RelPermalink }} {{ $url := default .RelPermalink .Params.external_url }}
{{ $target := cond ( isset .Params "external_url" ) "_blank" "" }} {{ $target := cond (ne .Params.external_url nil) "_blank" "" }}
{{ $note := cond ( isset .Params "list_note" ) (print "<span class='list-note'>" .Params.list_note "</span>") "" }} {{ $note := cond (ne .Params.list_note nil) (print "<span class='list-note'>" .Params.list_note "</span>") "" }}
<li><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a> {{ $note | markdownify }}</li> <li><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a> {{ $note | markdownify }}</li>
{{ end }} {{ end }}
</ul> </ul>
@ -108,10 +108,10 @@
<div class="children-links"> <div class="children-links">
<ol> <ol>
{{ range $pages.ByWeight }} {{ range $pages.ByWeight }}
{{ $title := cond ( isset .Params "list_title" ) (.Params.list_title | .RenderString) (.Title | .RenderString)}} {{ $title := default .Title .Params.list_title | .RenderString}}
{{ $url := cond ( isset .Params "external_url" ) .Params.external_url .RelPermalink }} {{ $url := default .RelPermalink .Params.external_url }}
{{ $target := cond ( isset .Params "external_url" ) "_blank" "" }} {{ $target := cond (ne .Params.external_url nil) "_blank" "" }}
{{ $note := cond ( isset .Params "list_note" ) (print "<span class='list-note'>" .Params.list_note "</span>") "" }} {{ $note := cond (ne .Params.list_note nil) (print "<span class='list-note'>" .Params.list_note "</span>") "" }}
<li><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a> {{ $note | markdownify }}</li> <li><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a> {{ $note | markdownify }}</li>
{{ end }} {{ end }}
</ol> </ol>
@ -121,7 +121,7 @@
<ul class="children-list"> <ul class="children-list">
{{ range $pages.ByWeight }} {{ range $pages.ByWeight }}
{{ $title := cond ( isset .Params "list_title" ) (.Params.list_title | .RenderString) (.Title | .RenderString) }} {{ $title := default .Title .Params.list_title | .RenderString }}
<li><a href="#{{ anchorize $title }}">{{ $title }}</a></li> <li><a href="#{{ anchorize $title }}">{{ $title }}</a></li>
{{ end }} {{ end }}
</ul> </ul>

View File

@ -3,7 +3,11 @@
{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}} {{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
{{- $product := index $productPathData 0 -}} {{- $product := index $productPathData 0 -}}
{{- $productVersion := index $productPathData 1 | default "v0.0" -}} {{- $productVersion := index $productPathData 1 | default "v0.0" -}}
{{- $defaultClockface := cond (isset (index .Site.Data.clockface $product) $productVersion) (index (index .Site.Data.clockface $product) $productVersion) (index (index .Site.Data.clockface $product) "default") }}
{{- $defaultClockface := "" -}}
{{- with (index .Site.Data.clockface $product) -}}
{{- $defaultClockface = index . (cond (isset . $productVersion) $productVersion "default") -}}
{{- end -}}
{{- $version := .Get 1 | default $defaultClockface -}} {{- $version := .Get 1 | default $defaultClockface -}}
{{- if eq $version "v2" -}} {{- if eq $version "v2" -}}

View File

@ -2,7 +2,10 @@
{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}} {{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
{{- $product := index $productPathData 0 -}} {{- $product := index $productPathData 0 -}}
{{- $productVersion := index $productPathData 1 | default "v0" -}} {{- $productVersion := index $productPathData 1 | default "v0" -}}
{{- $defaultClockface := cond (isset (index .Site.Data.clockface $product) $productVersion) (index (index .Site.Data.clockface $product) $productVersion) (index (index .Site.Data.clockface $product) "default") }} {{- $defaultClockface := "" -}}
{{- with (index .Site.Data.clockface $product) -}}
{{- $defaultClockface = default (index . "default") (index . $productVersion) -}}
{{- end -}}
{{- $version := .Get 1 | default $defaultClockface -}} {{- $version := .Get 1 | default $defaultClockface -}}
{{ if eq $version "v2" }} {{ if eq $version "v2" }}