Skip to content

Commit 94392b7

Browse files
authored
Merge pull request #6077 from influxdata/fix-isset-called-on-nil-values
chore(hugo): Update shortcodes and templates to avoid calling isset o…
2 parents 6f87073 + 30f7495 commit 94392b7

File tree

9 files changed

+44
-37
lines changed

9 files changed

+44
-37
lines changed

layouts/_default/page-list.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,49 @@
88
{{- if $index -}},{{- end }}
99
{
1010
"name": {{ .Name | jsonify }},
11-
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }},
11+
"url": {{ absURL (default .URL .Params.url) | jsonify }},
1212
"children": [
1313
{{- range $index, $entry := .Children -}}
1414
{{- if $index -}},{{- end }}
1515
{
1616
"name": {{ .Name | jsonify }},
17-
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }},
17+
"url": {{ absURL (default .URL .Params.url) | jsonify }},
1818
"children": [
1919
{{- range $index, $entry := .Children -}}
2020
{{- if $index -}},{{- end }}
2121
{
2222
"name": {{ .Name | jsonify }},
23-
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }},
23+
"url": {{ absURL (default .URL .Params.url) | jsonify }},
2424
"children": [
2525
{{- range $index, $entry := .Children -}}
2626
{{- if $index -}},{{- end }}
2727
{
2828
"name": {{ .Name | jsonify }},
29-
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }},
29+
"url": {{ absURL (default .URL .Params.url) | jsonify }},
3030
"children": [
3131
{{- range $index, $entry := .Children -}}
3232
{{- if $index -}},{{- end }}
3333
{
3434
"name": {{ .Name | jsonify }},
35-
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }},
35+
"url": {{ absURL (default .URL .Params.url) | jsonify }},
3636
"children": [
3737
{{- range $index, $entry := .Children -}}
3838
{{- if $index -}},{{- end }}
3939
{
4040
"name": {{ .Name | jsonify }},
41-
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }},
41+
"url": {{ absURL (default .URL .Params.url) | jsonify }},
4242
"children": [
4343
{{- range $index, $entry := .Children -}}
4444
{{- if $index -}},{{- end }}
4545
{
4646
"name": {{ .Name | jsonify }},
47-
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }},
47+
"url": {{ absURL (default .URL .Params.url) | jsonify }},
4848
"children": [
4949
{{- range $index, $entry := .Children -}}
5050
{{- if $index -}},{{- end }}
5151
{
5252
"name": {{ .Name | jsonify }},
53-
"url": {{ absURL (cond (isset .Params "url") .Params.url .URL) | jsonify }},
53+
"url": {{ absURL (default .URL .Params.url) | jsonify }},
5454
"children": [
5555
{{ range .Children }}
5656
{{ end }}

layouts/partials/article/flux-contrib.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</div>
1414
{{ else if eq .Kind "section" }}
1515
<div class="important block">
16-
{{ $packageTitle := cond (isset .Params "list_title") $.Params.list_title .Title }}
16+
{{ $packageTitle := default .Title .Params.list_title }}
1717
{{ $packageName := replaceRE `^(.*)( package)` "<code>$1</code>$2" $packageTitle }}
1818
<p>
1919
The {{ $packageName | safeHTML }} is a user-contributed package

layouts/partials/article/flux-experimental.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</div>
1414
{{ else if eq .Kind "section" }}
1515
<div class="important block">
16-
{{ $packageTitle := cond (isset .Params "list_title") $.Params.list_title .Title }}
16+
{{ $packageTitle := default .Title .Params.list_title }}
1717
{{ $packageName := replaceRE `^(.*)( package)` "<code>$1</code>$2" $packageTitle }}
1818
<p>
1919
The {{ $packageName | safeHTML }} is experimental and <a href="{{ $expRiskURL }}">subject to change at any time</a>.

layouts/partials/article/tags.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
{{ $product := index $productPathData 0 }}
33
{{ $version := index $productPathData 1 }}
44
{{ $tagSet := print $product "/" $version "/tags" }}
5-
{{ if isset .Params $tagSet }}
5+
{{ with .Param $tagSet }}
66
<div class="tags">
7-
{{ range .Param $tagSet }}
7+
{{ range . }}
88
{{ $name := . }}
99
{{ with $.Site.GetPage (printf "/%s/%s" $tagSet ($name | urlize)) }}
1010
<a class="tag btn" href="{{ .RelPermalink }}">{{ $name }}</a>

layouts/partials/header/title.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
{{ else if eq $currentVersion nil}}
3636
{{ $scratch.Set "siteTitle" (print (index .Site.Data.products $product).name " Documentation") }}
3737
{{ else }}
38-
{{ if (isset (index .Site.Data.products $product) "altname" ) }}
39-
{{ $scratch.Set "siteTitle" (print (index .Site.Data.products $product).altname " Documentation") }}
38+
{{ with (index .Site.Data.products $product).altname }}
39+
{{ $scratch.Set "siteTitle" (print . " Documentation") }}
4040
{{ else }}
41-
{{ $scratch.Set "siteTitle" (print (index .Site.Data.products $product).name " Documentation") }}
41+
{{ $scratch.Set "siteTitle" (print (index $.Site.Data.products $product).name " Documentation") }}
4242
{{ end }}
4343
{{ end }}
4444

layouts/partials/sidebar/nested-menu.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,45 @@
44
{{ range $menu }}
55
<li class="nav-category {{ if eq $page.RelPermalink .URL }}active{{end}}">
66
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
7-
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a>
7+
<a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
88
{{ if .HasChildren }}
99
<ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}">
1010
{{ range .Children }}
1111
<li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}">
1212
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
13-
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a>
13+
<a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
1414
{{ if .HasChildren }}
1515
<ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}">
1616
{{ range .Children }}
1717
<li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}">
1818
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
19-
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a>
19+
<a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
2020
{{ if .HasChildren }}
2121
<ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}">
2222
{{ range .Children }}
2323
<li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}">
2424
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
25-
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a>
25+
<a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
2626
{{ if .HasChildren }}
2727
<ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}">
2828
{{ range .Children }}
2929
<li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}">
3030
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
31-
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a>
31+
<a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
3232
{{ if .HasChildren }}
3333
<ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}">
3434
{{ range .Children }}
3535
<li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}">
3636
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
37-
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a>
37+
<a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
3838

3939
<!-- Begin nested block -->
4040
{{ if .HasChildren }}
4141
<ul class="children {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}">
4242
{{ range .Children }}
4343
<li class="nav-item {{ if eq $page.RelPermalink .URL }}active{{end}}">
4444
{{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($page.IsMenuCurrent .Menu .) ($page.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
45-
<a href='{{ cond (isset .Params "url") .Params.url .URL }}'>{{ .Name }}</a>
45+
<a href='{{ default .URL .Params.url }}'>{{ .Name }}</a>
4646
<!-- To add more nested layers, copy the nested block and paste it here -->
4747
</li>
4848
{{ end }}

layouts/shortcodes/children.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
{{ if eq $type "articles" }}
1919
<div class="children-links">
2020
{{ range $pages.ByWeight }}
21-
{{ $title := cond ( isset .Params "list_title" ) (.Params.list_title | .RenderString) (.Title | .RenderString) }}
22-
{{ $url := cond ( isset .Params "external_url" ) .Params.external_url .RelPermalink }}
23-
{{ $target := cond ( isset .Params "external_url" ) "_blank" "" }}
21+
{{ $title := default .Title .Params.list_title | .RenderString }}
22+
{{ $url := default .RelPermalink .Params.external_url }}
23+
{{ $target := cond (ne .Params.external_url nil) "_blank" "" }}
2424
{{ if eq $hlevel "h2"}} <h2 id="{{ anchorize $title }}"><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a></h2>
2525
{{ else if eq $hlevel "h3"}} <h3 id="{{ anchorize $title }}"><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a></h3>
2626
{{ else if eq $hlevel "h4"}} <h4 id="{{ anchorize $title }}"><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a></h4>
@@ -69,7 +69,7 @@ <h6>Output:</h6>
6969
{{ end }}
7070
{{ end }}
7171

72-
{{ if and (eq $readMore true) ( or (isset .Params "list_query_example") (isset .Params "list_code_example") ) }}
72+
{{ if and (eq $readMore true) (or .Params.list_query_example .Params.list_code_example) }}
7373
<p class="read-more"><a href="{{ $url }}" target="{{ $target }}">Read more <span class="icon-chevron-right"></span></a></p>
7474
{{ end }}
7575
{{ if eq $hr true }}
@@ -94,10 +94,10 @@ <h6>Output:</h6>
9494
<div class="children-links">
9595
<ul>
9696
{{ range $pages.ByWeight }}
97-
{{ $title := cond ( isset .Params "list_title" ) (.Params.list_title | .RenderString) (.Title | .RenderString) }}
98-
{{ $url := cond ( isset .Params "external_url" ) .Params.external_url .RelPermalink }}
99-
{{ $target := cond ( isset .Params "external_url" ) "_blank" "" }}
100-
{{ $note := cond ( isset .Params "list_note" ) (print "<span class='list-note'>" .Params.list_note "</span>") "" }}
97+
{{ $title := default .Title .Params.list_title | .RenderString }}
98+
{{ $url := default .RelPermalink .Params.external_url }}
99+
{{ $target := cond (ne .Params.external_url nil) "_blank" "" }}
100+
{{ $note := cond (ne .Params.list_note nil) (print "<span class='list-note'>" .Params.list_note "</span>") "" }}
101101
<li><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a> {{ $note | markdownify }}</li>
102102
{{ end }}
103103
</ul>
@@ -108,10 +108,10 @@ <h6>Output:</h6>
108108
<div class="children-links">
109109
<ol>
110110
{{ range $pages.ByWeight }}
111-
{{ $title := cond ( isset .Params "list_title" ) (.Params.list_title | .RenderString) (.Title | .RenderString)}}
112-
{{ $url := cond ( isset .Params "external_url" ) .Params.external_url .RelPermalink }}
113-
{{ $target := cond ( isset .Params "external_url" ) "_blank" "" }}
114-
{{ $note := cond ( isset .Params "list_note" ) (print "<span class='list-note'>" .Params.list_note "</span>") "" }}
111+
{{ $title := default .Title .Params.list_title | .RenderString}}
112+
{{ $url := default .RelPermalink .Params.external_url }}
113+
{{ $target := cond (ne .Params.external_url nil) "_blank" "" }}
114+
{{ $note := cond (ne .Params.list_note nil) (print "<span class='list-note'>" .Params.list_note "</span>") "" }}
115115
<li><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a> {{ $note | markdownify }}</li>
116116
{{ end }}
117117
</ol>
@@ -121,7 +121,7 @@ <h6>Output:</h6>
121121

122122
<ul class="children-list">
123123
{{ range $pages.ByWeight }}
124-
{{ $title := cond ( isset .Params "list_title" ) (.Params.list_title | .RenderString) (.Title | .RenderString) }}
124+
{{ $title := default .Title .Params.list_title | .RenderString }}
125125
<li><a href="#{{ anchorize $title }}">{{ $title }}</a></li>
126126
{{ end }}
127127
</ul>

layouts/shortcodes/icon.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
44
{{- $product := index $productPathData 0 -}}
55
{{- $productVersion := index $productPathData 1 | default "v0.0" -}}
6-
{{- $defaultClockface := cond (isset (index .Site.Data.clockface $product) $productVersion) (index (index .Site.Data.clockface $product) $productVersion) (index (index .Site.Data.clockface $product) "default") }}
6+
7+
{{- $defaultClockface := "" -}}
8+
{{- with (index .Site.Data.clockface $product) -}}
9+
{{- $defaultClockface = index . (cond (isset . $productVersion) $productVersion "default") -}}
10+
{{- end -}}
711
{{- $version := .Get 1 | default $defaultClockface -}}
812

913
{{- if eq $version "v2" -}}

layouts/shortcodes/nav-icon.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
33
{{- $product := index $productPathData 0 -}}
44
{{- $productVersion := index $productPathData 1 | default "v0" -}}
5-
{{- $defaultClockface := cond (isset (index .Site.Data.clockface $product) $productVersion) (index (index .Site.Data.clockface $product) $productVersion) (index (index .Site.Data.clockface $product) "default") }}
5+
{{- $defaultClockface := "" -}}
6+
{{- with (index .Site.Data.clockface $product) -}}
7+
{{- $defaultClockface = default (index . "default") (index . $productVersion) -}}
8+
{{- end -}}
69
{{- $version := .Get 1 | default $defaultClockface -}}
710

811
{{ if eq $version "v2" }}

0 commit comments

Comments
 (0)