Omphaloskepsis-2/layouts/partials/util/render_recursive_list.html.tmpl

57 lines
1.6 KiB
Cheetah
Raw Normal View History

2024-04-02 19:36:21 +00:00
<!--
Recursively render an ordered or unordered list from a set of arbitrarily-
deeply-nested items.
@params sc Site context
@params pc Page context
@params items Set of items to render a list from.
@params schemaType Schema.org type to apply. Optional.
@params listType "unordered" or "ordered". Default "unordered".
-->
<!-- Validation -->
{{- if not .sc.Site.Data.itemtypes -}}
{{- errorf "Can't access site context in partial (%q)" .pc.File.Path -}}
{{- end -}}
{{- if not .items -}}
{{- warnf "No items passed to list partial (%q)" .pc.File.Path -}}
{{- end -}}
{{- if ( and .schemaType ( not ( in .sc.Site.Data.itemtypes .schemaType ) ) ) -}}
{{- erroridf "invalid-schemaType" "Invalid Schema.org type value %q (%q)" .schemaType .pc.File.Path -}}
{{- end -}}
{{- if ( and .listType ( not ( in ( slice "unordered" "ordered" ) .listType ) ) ) -}}
{{- erroridf "invalid-listType" "Invalid list type value %q (%q)" .listType .pc.File.Path -}}
{{- end -}}
<!-- Default Assignment -->
{{- $schemaType := default "" .schemaType -}}
{{- $listType := default "unordered" .listType -}}
<!-- Rendering -->
{{- if ( eq $listType "unordered" ) -}}
<ul>
{{- else -}}
<ol>
{{- end -}}
{{- range $k, $v := .items -}}
<li itemscope itemtype="https://schema.org/Place">
{{- $k -}}
{{- if ( not ( isset $v "lat" ) ) -}}
{{- partial "util/render_recursive_list.html.tmpl" ( dict "sc" $.sc "pc" $.pc "items" $v "schemaType" $schemaType "listType" $listType ) -}}
{{- end -}}
</li>
{{- end -}}
{{- if ( eq $listType "unordered" ) -}}
</ul>
{{- else -}}
</ol>
{{- end -}}