From cd491f0715f171849e0ab6e8ec7c7ad61a46be17 Mon Sep 17 00:00:00 2001 From: razonyang Date: Wed, 30 Oct 2024 12:32:40 +0800 Subject: [PATCH] feat: add the `docs_root_section` page parameter When the `docs_root_section` is set as `false` on first section, then the second section will be used as the root section for navigation on left sidebar --- layouts/docs/list.html | 3 ++- layouts/docs/single.html | 3 ++- .../hb/modules/docs/functions/root-section.html | 11 +++++++++++ layouts/partials/hb/modules/docs/functions/tree.html | 4 ++-- layouts/partials/hb/modules/docs/nav.html | 3 ++- 5 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 layouts/partials/hb/modules/docs/functions/root-section.html diff --git a/layouts/docs/list.html b/layouts/docs/list.html index 788bb651..5fef548d 100644 --- a/layouts/docs/list.html +++ b/layouts/docs/list.html @@ -1,7 +1,8 @@ {{- define "main" }}
- {{ partialCached "hb/modules/docs/nav" . .FirstSection }} + {{ $rootSection := partialCached "hb/modules/docs/functions/root-section" . . }} + {{ partialCached "hb/modules/docs/nav" . $rootSection }}
{{ partial "hugopress/functions/render-hooks" (dict "Page" . "Name" "hb-docs-main-begin") }} diff --git a/layouts/docs/single.html b/layouts/docs/single.html index 2b05fbb1..4470e9e0 100644 --- a/layouts/docs/single.html +++ b/layouts/docs/single.html @@ -1,7 +1,8 @@ {{- define "main" }}
- {{ partialCached "hb/modules/docs/nav" . .FirstSection }} + {{ $rootSection := partialCached "hb/modules/docs/functions/root-section" . . }} + {{ partialCached "hb/modules/docs/nav" . $rootSection }}
{{ partial "hugopress/functions/render-hooks" (dict "Page" . "Name" "hb-docs-main-begin") }} diff --git a/layouts/partials/hb/modules/docs/functions/root-section.html b/layouts/partials/hb/modules/docs/functions/root-section.html new file mode 100644 index 00000000..428345d6 --- /dev/null +++ b/layouts/partials/hb/modules/docs/functions/root-section.html @@ -0,0 +1,11 @@ +{{- $section := .FirstSection }} +{{- if not (default true $section.Params.docs_root_section) }} + {{- with index .Ancestors.Reverse 2 }} + {{- $section = . }} + {{- else }} + {{- if .IsSection }} + {{- $section = . }} + {{- end }} + {{- end }} +{{- end }} +{{- return $section }} diff --git a/layouts/partials/hb/modules/docs/functions/tree.html b/layouts/partials/hb/modules/docs/functions/tree.html index 5405e6f7..551663bd 100644 --- a/layouts/partials/hb/modules/docs/functions/tree.html +++ b/layouts/partials/hb/modules/docs/functions/tree.html @@ -1,3 +1,3 @@ -{{/* Returns the pages tree of first section of current page. */}} -{{- $tree := partial "hb/modules/docs/functions/walk-section" .FirstSection }} +{{/* Returns the pages tree of the root section of current page. */}} +{{- $tree := partial "hb/modules/docs/functions/walk-section" . }} {{- return $tree -}} diff --git a/layouts/partials/hb/modules/docs/nav.html b/layouts/partials/hb/modules/docs/nav.html index bbcb9856..fbb3b508 100644 --- a/layouts/partials/hb/modules/docs/nav.html +++ b/layouts/partials/hb/modules/docs/nav.html @@ -1,4 +1,5 @@ -{{- $tree := partialCached "hb/modules/docs/functions/tree" . .FirstSection }} +{{- $rootSection := partialCached "hb/modules/docs/functions/root-section" . . }} +{{- $tree := partialCached "hb/modules/docs/functions/tree" $rootSection $rootSection }}