chore: basic rendering from data

This commit is contained in:
Xin
2024-04-14 11:12:17 +01:00
parent c62b1fd401
commit 63f153999e
4 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,15 @@
{{- $page := .page -}}
{{- $pageLink := $page.RelPermalink -}}
{{- range .data -}}
{{- $active := or (eq $pageLink .link) (eq (strings.TrimSuffix "/" $pageLink) .link) -}}
{{- $containsPage := hasPrefix $pageLink .link -}}
{{- $shouldOpen := or (.open) $containsPage $active | default true -}}
<li class="{{ if $shouldOpen }}open{{ end }}">
{{- partial "components/sidebar/item-link" (dict "active" $active "title" .title "link" .link "items" .items) -}}
{{- if .items -}}
{{- partial "components/sidebar/render-items" (dict "items" .items "link" $pageLink) -}}
{{- end -}}
</li>
{{ end }}