Skip to content

Commit 192f9df

Browse files
authored
feat: add the docs_root_section page parameter (#866)
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
1 parent 3ef53bd commit 192f9df

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

layouts/docs/list.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{{- define "main" }}
22
<div class="hb-docs">
33
<div class="hb-docs-sidebar" tabindex="-1" data-bs-hide="focusout">
4-
{{ partialCached "hb/modules/docs/nav" . .FirstSection }}
4+
{{ $rootSection := partialCached "hb/modules/docs/functions/root-section" . . }}
5+
{{ partialCached "hb/modules/docs/nav" . $rootSection }}
56
</div>
67
<div class="hb-docs-main col-12 col-xxl-10">
78
{{ partial "hugopress/functions/render-hooks" (dict "Page" . "Name" "hb-docs-main-begin") }}

layouts/docs/single.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{{- define "main" }}
22
<div class="hb-docs">
33
<div class="hb-docs-sidebar" tabindex="-1" data-bs-hide="focusout">
4-
{{ partialCached "hb/modules/docs/nav" . .FirstSection }}
4+
{{ $rootSection := partialCached "hb/modules/docs/functions/root-section" . . }}
5+
{{ partialCached "hb/modules/docs/nav" . $rootSection }}
56
</div>
67
<div class="hb-docs-main">
78
{{ partial "hugopress/functions/render-hooks" (dict "Page" . "Name" "hb-docs-main-begin") }}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{- $section := .FirstSection }}
2+
{{- if not (default true $section.Params.docs_root_section) }}
3+
{{- with index .Ancestors.Reverse 2 }}
4+
{{- $section = . }}
5+
{{- else }}
6+
{{- if .IsSection }}
7+
{{- $section = . }}
8+
{{- end }}
9+
{{- end }}
10+
{{- end }}
11+
{{- return $section }}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{{/* Returns the pages tree of first section of current page. */}}
2-
{{- $tree := partial "hb/modules/docs/functions/walk-section" .FirstSection }}
1+
{{/* Returns the pages tree of the root section of current page. */}}
2+
{{- $tree := partial "hb/modules/docs/functions/walk-section" . }}
33
{{- return $tree -}}

layouts/partials/hb/modules/docs/nav.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{{- $tree := partialCached "hb/modules/docs/functions/tree" . .FirstSection }}
1+
{{- $rootSection := partialCached "hb/modules/docs/functions/root-section" . . }}
2+
{{- $tree := partialCached "hb/modules/docs/functions/tree" $rootSection $rootSection }}
23
<div
34
class="hb-docs-nav offcanvas-lg pe-lg-2 offcanvas-start"
45
aria-labelledby="hb-docs-nav-label">

0 commit comments

Comments
 (0)