feat: generate sidebar json data for rendering

This commit is contained in:
Xin
2024-04-14 11:31:13 +01:00
parent 63f153999e
commit 33f2cf653b
4 changed files with 58 additions and 4 deletions

View File

@ -1,6 +1,5 @@
{{- $items := .items -}}
{{- $pageLink := .link -}}
{{ $shouldOpen := true }}
<div class="ltr:hx-pr-0 hx-overflow-hidden">
@ -9,6 +8,10 @@
>
{{- range $items }}
{{- $active := or (eq $pageLink .link) (eq (strings.TrimSuffix "/" $pageLink) .link) -}}
{{- $containsPage := hasPrefix $pageLink .link -}}
{{- $shouldOpen := or (.open) $containsPage $active | default false -}}
<li class="hx-flex hx-flex-col {{ if $shouldOpen }}open{{ end }}">
{{- partial "components/sidebar/item-link" (dict "active" $active "title" .title "link" .link "items" .items) -}}
{{- if .items -}}