From 13e4eb3414e5d79decd34ca7dfbb143f97373a55 Mon Sep 17 00:00:00 2001 From: Xin Date: Mon, 23 Oct 2023 21:59:26 +0100 Subject: [PATCH] chore: add section-tree.html --- layouts/partials/sidebar-tree.html | 64 ++++++++++++++++++++++++++++++ layouts/partials/sidebar.html | 1 - layouts/partials/sidebar/toc.html | 4 +- 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 layouts/partials/sidebar-tree.html diff --git a/layouts/partials/sidebar-tree.html b/layouts/partials/sidebar-tree.html new file mode 100644 index 0000000..7fb17ee --- /dev/null +++ b/layouts/partials/sidebar-tree.html @@ -0,0 +1,64 @@ + + +{{- define "partials/sidebar/mobile-search" -}} +
+ {{- partialCached "search.html" . -}} +
+{{- end -}} + +{{- define "partials/sidebar/link" -}} + {{- $external := strings.HasPrefix .link "http" -}} + {{- $open := .open | default true -}} + + {{- .title -}} + {{- with .context }} + {{- if or .RegularPages .Sections }}{{ partialCached "sidebar/collapsible-button" . }}{{ end -}} + {{ end -}} + +{{- end -}} + +{{- define "partials/sidebar/tree" -}} + {{- if ge .level 4 -}} + {{- return -}} + {{- end -}} + + {{- $context := .context -}} + {{- $page := .page }} + {{- $level := .level -}} + + {{- with $items := union .context.RegularPages .context.Sections -}} + {{- if eq $level 0 -}} + {{- range $items.ByWeight }} +
  • + {{- partial "sidebar/link" (dict "context" . "title" .LinkTitle "link" .RelPermalink) -}} + {{- partial "sidebar/tree" (dict "context" . "page" $page "level" (add $level 1)) -}} +
  • + {{- end -}} + {{- else -}} +
    + +
    + {{- end -}} + {{- end }} +{{- end -}} diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index 742a6e4..0f406d5 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -6,7 +6,6 @@ {{- $sidebarClass := cond $disableSidebar (cond $displayPlaceholder "md:hidden xl:block" "md:hidden") "md:sticky" -}} {{- $navRoot := cond (eq site.Home.Type "docs") site.Home $context.FirstSection -}} -{{- $navPages := union $navRoot.RegularPages $navRoot.Sections -}} {{- $pageURL := $context.RelPermalink -}} diff --git a/layouts/partials/sidebar/toc.html b/layouts/partials/sidebar/toc.html index 1006013..a5baf5a 100644 --- a/layouts/partials/sidebar/toc.html +++ b/layouts/partials/sidebar/toc.html @@ -1,6 +1,8 @@ {{ $page := . }} {{ with $page.Fragments.Headings }} -