feat: add params page.sidebar.source and page.sidebar.cache

This commit is contained in:
Xin 2024-04-14 23:53:53 +01:00
parent e444156bb9
commit a1c7acd6b5
2 changed files with 21 additions and 6 deletions

View File

@ -8,9 +8,18 @@
{{- $navRoot := cond (eq site.Home.Type "docs") site.Home $context.FirstSection -}} {{- $navRoot := cond (eq site.Home.Type "docs") site.Home $context.FirstSection -}}
{{- $pageURL := $context.RelPermalink -}} {{- $pageURL := $context.RelPermalink -}}
{{/* {{ $data := partialCached "components/sidebar/get-section-data" $context $context.Section }} */}} {{- $data := slice -}}
{{- $data := partial "components/sidebar/generate-section-data" $navRoot | unmarshal -}} {{- $dataMobile := slice -}}
{{- $dataMobile := partial "components/sidebar/generate-section-data" site.Home | unmarshal -}}
{{- if (eq site.Params.page.sidebar.source "data") -}}
{{ $data = partialCached "components/sidebar/get-section-data" $context $context.Section }}
{{- $dataMobile = $data -}}
{{- else -}}
{{- $data = (partialCached "components/sidebar/generate-section-data" $navRoot $navRoot) | unmarshal -}}
{{- $dataMobile = (partialCached "components/sidebar/generate-section-data" site.Home site.Home) | unmarshal -}}
{{- end -}}
{{- $shouldCache := site.Params.page.sidebar.cache | default false -}}
<div class="mobile-menu-overlay [transition:background-color_1.5s_ease] hx-fixed hx-inset-0 hx-z-10 hx-bg-black/80 dark:hx-bg-black/60 hx-hidden"></div> <div class="mobile-menu-overlay [transition:background-color_1.5s_ease] hx-fixed hx-inset-0 hx-z-10 hx-bg-black/80 dark:hx-bg-black/60 hx-hidden"></div>
@ -35,9 +44,13 @@
{{- else -}} {{- else -}}
<ul class="hx-flex hx-flex-col hx-gap-1 max-md:hx-hidden"> <ul class="hx-flex hx-flex-col hx-gap-1 max-md:hx-hidden">
{{- with $data -}} {{- with $data -}}
{{- if $shouldCache -}}
{{- partialCached "components/sidebar/render-data" (dict "data" . "page" $context) $navRoot -}}
{{- else -}}
{{- partial "components/sidebar/render-data" (dict "data" . "page" $context) -}} {{- partial "components/sidebar/render-data" (dict "data" . "page" $context) -}}
{{- end -}} {{- end -}}
{{- partialCached "components/sidebar/footer" $context site.Home -}} {{- end -}}
{{- partialCached "components/sidebar/bottom" $context site.Home -}}
</ul> </ul>
{{ end -}} {{ end -}}
</div> </div>
@ -59,7 +72,9 @@
{{ if or site.IsMultiLingual $displayThemeToggle }} {{ if or site.IsMultiLingual $displayThemeToggle }}
<div <div
class="{{ $switchesClass }} {{ with site.IsMultiLingual }}hx-justify-end{{ end }} hx-sticky hx-bottom-0 hx-bg-white dark:hx-bg-dark hx-mx-4 hx-py-4 hx-shadow-[0_-12px_16px_#fff] hx-flex hx-items-center hx-gap-2 dark:hx-border-neutral-800 dark:hx-shadow-[0_-12px_16px_#111] contrast-more:hx-border-neutral-400 contrast-more:hx-shadow-none contrast-more:dark:hx-shadow-none hx-border-t" class="{{ $switchesClass }} {{ with site.IsMultiLingual }}
hx-justify-end
{{ end }} hx-sticky hx-bottom-0 hx-bg-white dark:hx-bg-dark hx-mx-4 hx-py-4 hx-shadow-[0_-12px_16px_#fff] hx-flex hx-items-center hx-gap-2 dark:hx-border-neutral-800 dark:hx-shadow-[0_-12px_16px_#111] contrast-more:hx-border-neutral-400 contrast-more:hx-shadow-none contrast-more:dark:hx-shadow-none hx-border-t"
data-toggle-animation="show" data-toggle-animation="show"
> >
{{- with site.IsMultiLingual -}} {{- with site.IsMultiLingual -}}