Skip to content

Commit 7951194

Browse files
authored
Adds a warning when truncating sidebar section entries (#2069)
1 parent 27ff9b6 commit 7951194

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ For the full list of changes, see the [0.x.y] release notes.
3232
base support for RTL][bs-rtl].
3333
- The URL to your project's contribution guidelines is configurable. For
3434
details, see [Adding a community page].
35+
- A warning is now output when a section's sidebar entries are truncated because
36+
there are more than [params.ui.sidebar_menu_truncate] section entries.
3537

3638
**Other changes**: TBC
3739

3840
[0.x.y]: https://github.com/google/docsy/releases/latest?FIXME=v0.X.Y
3941
[bs-rtl]: https://getbootstrap.com/docs/5.3/getting-started/rtl/
4042
[Adding a community page]:
4143
https://www.docsy.dev/docs/adding-content/content/#adding-a-community-page
44+
[params.ui.sidebar_menu_truncate]:
45+
https://www.docsy.dev/docs/adding-content/navigation/#section-menu-options
4246

4347
## 0.10.0
4448

layouts/partials/sidebar-tree.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{{ $navRoot := cond (and (ne .Params.toc_root true) (eq .Site.Home.Type "docs")) .Site.Home .FirstSection -}}
3131
{{ $ulNr := 0 -}}
3232
{{ $ulShow := .Site.Params.ui.ul_show | default 1 -}}
33-
{{ $sidebarMenuTruncate := .Site.Params.ui.sidebar_menu_truncate | default 50 -}}
33+
{{ $sidebarMenuTruncate := .Site.Params.ui.sidebar_menu_truncate | default 100 -}}
3434
<ul class="td-sidebar-nav__section pe-md-3 ul-{{ $ulNr }}">
3535
{{ template "section-tree-nav-section" (dict "page" . "section" $navRoot "shouldDelayActive" $shouldDelayActive "sidebarMenuTruncate" $sidebarMenuTruncate "ulNr" $ulNr "ulShow" (add $ulShow 1)) }}
3636
</ul>
@@ -50,6 +50,11 @@
5050
{{ $mid := printf "m-%s" ($s.RelPermalink | anchorize) -}}
5151
{{ $pages_tmp := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true -}}
5252
{{ $pages := $pages_tmp | first $sidebarMenuTruncate -}}
53+
{{ $truncatedEntryCount := sub (len $pages_tmp) $sidebarMenuTruncate -}}
54+
{{ if gt $truncatedEntryCount 0 -}}
55+
{{ warnf "WARNING: %d sidebar entries have been truncated. To avoid this, increase `params.ui.sidebar_menu_truncate` to at least %d (from %d) in your config file. Section: %s"
56+
$truncatedEntryCount (len $pages_tmp) $sidebarMenuTruncate $s.Path -}}
57+
{{ end -}}
5358
{{ $withChild := gt (len $pages) 0 -}}
5459
{{ $manualLink := cond (isset $s.Params "manuallink") $s.Params.manualLink ( cond (isset $s.Params "manuallinkrelref") (relref $s $s.Params.manualLinkRelref) $s.RelPermalink) -}}
5560
{{ $manualLinkTitle := cond (isset $s.Params "manuallinktitle") $s.Params.manualLinkTitle $s.Title -}}
@@ -71,4 +76,4 @@
7176
</ul>
7277
{{- end }}
7378
</li>
74-
{{- end }}
79+
{{- end -}}

userguide/content/en/docs/adding-content/navigation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ By default, the section menu shows the current section fully expanded all the wa
222222

223223
With the compact menu (`.ui.sidebar_menu_compact = true`), only the current page's ancestors, siblings and direct descendants are shown. You can use the optional parameter `.ui.ul_show` to set a desired menu depth to always be visible. For example, with `.ui.ul_show = 1` the first menu level is always displayed.
224224

225-
The number of sidebar entries shown per section can be configured using the `.ui.sidebar_menu_truncate` parameter (default: 50).
225+
The number of sidebar entries shown per section can be configured using the `.ui.sidebar_menu_truncate` parameter (default: 100).
226226

227227
As well as the completely expanded and compact menu options, you can also create a foldable menu by setting the site parameter `ui.sidebar_menu_foldable = true` in `hugo.toml`. The foldable menu lets users expand and collapse menu sections by toggling arrow icons beside the section parents in the menu.
228228

0 commit comments

Comments
 (0)