From 3b47c58936a6095976c98d7f29922be94be82948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Fri, 9 Jun 2023 18:26:22 +0200 Subject: [PATCH] Remove custom sidebar-tree partial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kévin Commaille --- config.toml | 2 + layouts/partials/sidebar-tree.html | 82 ------------------------------ static/js/toc.js | 11 +++- 3 files changed, 11 insertions(+), 84 deletions(-) delete mode 100644 layouts/partials/sidebar-tree.html diff --git a/config.toml b/config.toml index 3cf2a50b..c6f1bd45 100644 --- a/config.toml +++ b/config.toml @@ -64,6 +64,8 @@ footer_about_disable = false rendered_data_collapsed = false # Hide the search entry in the sidebar sidebar_search_disable = true +# Only show the current page's ancestors, siblings and direct descendants in the sidebar menu +sidebar_menu_compact = true [params.links] # End user relevant links. These will show up on left side of footer and in the community page if you have one. diff --git a/layouts/partials/sidebar-tree.html b/layouts/partials/sidebar-tree.html deleted file mode 100644 index 03ecacf0..00000000 --- a/layouts/partials/sidebar-tree.html +++ /dev/null @@ -1,82 +0,0 @@ -{{/* - - A version of the sidebar-tree.html partial in Docsy, with a few small - modifications: - - * include `div#toc` for the ToC - -*/}} - -{{/* We cache this partial for bigger sites and set the active class client side. */}} -{{ $sidebarCacheLimit := cond (isset .Site.Params.ui "sidebar_cache_limit") .Site.Params.ui.sidebar_cache_limit 2000 -}} -{{ $shouldDelayActive := ge (len .Site.Pages) $sidebarCacheLimit -}} -
- {{ if not .Site.Params.ui.sidebar_search_disable -}} - - {{ else -}} -
- -
-
- {{ end -}} - -
-{{ define "section-tree-nav-section" -}} -{{ $s := .section -}} -{{ $p := .page -}} -{{ $shouldDelayActive := .shouldDelayActive -}} -{{ $sidebarMenuTruncate := .sidebarMenuTruncate -}} -{{ $treeRoot := cond (eq .ulNr 0) true false -}} -{{ $ulNr := .ulNr -}} -{{ $ulShow := .ulShow -}} -{{ $active := and (not $shouldDelayActive) (eq $s $p) -}} -{{ $activePath := and (not $shouldDelayActive) (or (eq $p $s) ($p.IsDescendant $s)) -}} -{{ $show := cond (or (lt $ulNr $ulShow) $activePath (and (not $shouldDelayActive) (eq $s.Parent $p.Parent)) (and (not $shouldDelayActive) (eq $s.Parent $p)) (not $p.Site.Params.ui.sidebar_menu_compact) (and (not $shouldDelayActive) ($p.IsDescendant $s.Parent))) true false -}} -{{ $mid := printf "m-%s" ($s.RelPermalink | anchorize) -}} -{{ $pages_tmp := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true -}} -{{ $pages := $pages_tmp | first $sidebarMenuTruncate -}} -{{ $withChild := gt (len $pages) 0 -}} -{{ $manualLink := cond (isset $s.Params "manuallink") $s.Params.manualLink ( cond (isset $s.Params "manuallinkrelref") (relref $s $s.Params.manualLinkRelref) $s.RelPermalink) -}} -{{ $manualLinkTitle := cond (isset $s.Params "manuallinktitle") $s.Params.manualLinkTitle $s.Title -}} -
  • - {{ if (and $p.Site.Params.ui.sidebar_menu_foldable (ge $ulNr 1)) -}} - - - {{ else -}} - {{ with $s.Params.Icon}}{{ end }}{{ $s.LinkTitle }} - {{- end }} - {{- if $withChild }} - {{- $ulNr := add $ulNr 1 }} -
      - {{ range $pages -}} - {{ if (not (and (eq $s $p.Site.Home) (eq .Params.toc_root true))) -}} - {{ template "section-tree-nav-section" (dict "page" $p "section" . "shouldDelayActive" $shouldDelayActive "sidebarMenuTruncate" $sidebarMenuTruncate "ulNr" $ulNr "ulShow" $ulShow) }} - {{- end }} - {{- end }} -
    - {{- end }} -
  • -{{- end }} diff --git a/static/js/toc.js b/static/js/toc.js index fa36ba4a..6386e40d 100644 --- a/static/js/toc.js +++ b/static/js/toc.js @@ -111,11 +111,18 @@ function makeToc() { const section = makeTocSection(tocTargets, 0); nav.appendChild(section.content); - // append title and content to the #toc placeholder - const toc = document.body.querySelector("#toc"); + // build the TOC and append to it title and content + const toc = document.createElement("div"); + toc.id = "toc"; toc.appendChild(title); toc.appendChild(nav); + // append TOC to the section navigation + const section_nav = document.body.querySelector("#td-section-nav"); + let hr = document.createElement("hr"); + section_nav.appendChild(hr); + section_nav.appendChild(toc); + // tell ToC items about any rendered-data headings they contain setTocItemChildren(section.content, headings); }