docs-v2/layouts/shortcodes/children.html

116 lines
4.6 KiB
HTML

{{ $type := .Get "type" | default "articles" }}
{{ $show := .Get "show" | default "all" }}
{{ $hlevel := .Get "hlevel" | default "h3"}}
{{ $readMore := .Get "readmore" | default false }}
{{ $hr := .Get "hr" | default false }}
{{ $doNotList := .Get "filterOut" | default "" }}
{{ if eq $show "all" }}
{{ .Scratch.Set "pages" (union .Page.Pages .Page.Sections) }}
{{ else if (eq $show "sections") }}
{{ .Scratch.Set "pages" .Page.Sections }}
{{ else if (eq $show "pages") }}
{{ .Scratch.Set "pages" .Page.RegularPages }}
{{ end }}
{{ $pages := where (.Scratch.Get "pages") "Title" "not in" (split $doNotList ", ") }}
{{ if eq $type "articles" }}
<div class="children-links">
{{ range $pages.ByWeight }}
{{ $title := cond ( isset .Params "list_title" ) .Params.list_title .Title }}
{{ $url := cond ( isset .Params "external_url" ) .Params.external_url .RelPermalink }}
{{ $target := cond ( isset .Params "external_url" ) "_blank" "" }}
{{ 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 "h4"}} <h4 id="{{ anchorize $title }}"><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a></h4>
{{end}}
<p>
{{- if .Description }}{{- .Description | markdownify -}}
{{ else }}{{- .Summary | markdownify -}}
{{ end -}}
</p>
{{ if .Params.list_image }}
{{ $img := .Params.list_image }}
{{ if (fileExists ( print "/static" $img )) }}
{{ with (imageConfig ( print "/static" $img )) }}
{{ $imageWidth := div .Width 3 }}
<img src='{{ $img }}' width='{{ $imageWidth }}' />
{{ end }}
{{ else }}
<img src='{{ $img }}'/>
{{ end }}
{{ end }}
{{ if .Params.list_code_example }}
{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
{{- $currentVersion := index $productPathData 1 -}}
{{- $isOSS := ne (len (findRE `^v[0-9]` $currentVersion)) 0 -}}
{{- $productKey := cond $isOSS "oss" $currentVersion -}}
{{- $productAliases := dict "oss" "influxdb" "cloud" "influxdb_cloud" "cloud-tsm" "influxdb_cloud" "cloud-serverless" "influxdb_cloud_serverless" "serverless" "influxdb_cloud_serverless" "cloud-dedicated" "influxdb_cloud_dedicated" "dedicated" "influxdb_cloud_dedicated" "clustered" "influxdb_clustered" -}}
{{- $productRef := index $productAliases $productKey -}}
{{- $productData := index .Site.Data.products $productRef -}}
{{- $placeholderHost := $productData.placeholder_host }}
{{ .Params.list_code_example | replaceRE `\{\{[<\%] influxdb/host [>%]\}\}` $placeholderHost | markdownify }}
{{ end }}
{{ if .Params.list_query_example }}
{{ range (index .Site.Data.query_examples .Params.list_query_example) }}
{{ .code | markdownify }}
<div class="flex-wrapper">
<div class="flex-container half">
<h6>Input:</h6>
{{ .input | markdownify }}
</div>
<div class="flex-container half">
<h6>Output:</h6>
{{ .output | markdownify }}
</div>
</div>
{{ end }}
{{ end }}
{{ if and (eq $readMore true) ( or (isset .Params "list_query_example") (isset .Params "list_code_example") ) }}
<p class="read-more"><a href="{{ $url }}" target="{{ $target }}">Read more <span class="icon-chevron-right"></span></a></p>
{{ end }}
{{ if eq $hr true }}
<hr />
{{ end }}
{{ end }}
</div>
{{ else if (eq $type "functions") }}
<div class="children-links">
<ul>
{{ range $pages.ByWeight }}
{{ $title := replaceRE `\ function` "" .Title }}
<li><a href="{{ .RelPermalink }}">{{ if .Params.list_title }}{{ .Params.list_title }}{{ else }}{{ $title }}{{ end }}</a></li>
{{ end }}
</ul>
</div>
{{ else if (eq $type "list") }}
<div class="children-links">
<ul>
{{ range $pages.ByWeight }}
{{ $title := cond ( isset .Params "list_title" ) .Params.list_title .Title }}
{{ $url := cond ( isset .Params "external_url" ) .Params.external_url .RelPermalink }}
{{ $target := cond ( isset .Params "external_url" ) "_blank" "" }}
{{ $note := cond ( isset .Params "list_note" ) (print "<span class='list-note'>" .Params.list_note "</span>") "" }}
<li><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a> {{ $note | markdownify }}</li>
{{ end }}
</ul>
</div>
{{ else if (eq $type "anchored-list") }}
<ul>
{{ range $pages.ByWeight }}
{{ $title := cond ( isset .Params "list_title" ) .Params.list_title .Title }}
<li><a href="#{{ anchorize $title }}">{{ $title }}</a></li>
{{ end }}
</ul>
{{ end }}