refactor templates layout
@see https://gohugo.io/templates/new-templatesystem-overview/
This commit is contained in:
parent
a83f339dc8
commit
230c46411b
102 changed files with 2 additions and 2 deletions
58
layouts/_partials/util/render_recursive_list.html
Normal file
58
layouts/_partials/util/render_recursive_list.html
Normal file
|
@ -0,0 +1,58 @@
|
|||
<!--
|
||||
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 itemtype 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 .itemtype ( not ( in .sc.Site.Data.itemtypes .itemtype ) ) ) -}}
|
||||
{{- erroridf "invalid-itemtype" "Invalid Schema.org type value %q (%q)" .itemtype .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 -->
|
||||
|
||||
{{- $itemtype := default "" .itemtype -}}
|
||||
{{- $listType := default "unordered" .listType -}}
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
{{- if ( eq $listType "unordered" ) -}}
|
||||
<ul>
|
||||
{{- else -}}
|
||||
<ol>
|
||||
{{- end -}}
|
||||
|
||||
{{- range $k, $v := .items -}}
|
||||
{{- if not ( isset $v "redact" ) -}}
|
||||
<li itemscope itemtype="https://schema.org/Place">
|
||||
{{- $k -}}
|
||||
{{- if ( not ( isset $v "lat" ) ) -}}
|
||||
{{- partial "util/render_recursive_list.html" ( dict "sc" $.sc "pc" $.pc "items" $v "itemtype" $itemtype "listType" $listType ) -}}
|
||||
{{- end -}}
|
||||
</li>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( eq $listType "unordered" ) -}}
|
||||
</ul>
|
||||
{{- else -}}
|
||||
</ol>
|
||||
{{- end -}}
|
Loading…
Add table
Add a link
Reference in a new issue