Skip to content

Commit fb418d6

Browse files
jamietannaClaude Sonnet 4.6
andauthored
docs: show all Managers in sidebar (#42155)
As we do with the other modules, we should include Managers too. Although there are many, it can be a little jarring not seeing the list of Managers when viewing a specific one. This requires we also show the "display name" (`Ansible`) in the sidebar, and then use the more verbose `Automated Dependency Updates for Ansible` as the header. To do this, we can utilise the `sidebar_label` (which was previously used in Docusarus, but unused by Material for MkDocs) via a custom hook to inject the label for the sidebar. Unfortunately this requires a custom hook, which will make moving away from Material for MkDocs (to Zensical) a little less straightforward. Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@mend.io>
1 parent 72968d3 commit fb418d6

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

docs/usage/modules/manager/.pages

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
title: Managers
22
nav:
3-
- index.md
4-
# TODO: add all managers ?
5-
# - Introduction: index.md
6-
# - ...
3+
- Introduction: index.md
4+
- ...
75
collapse_single_pages: true
86
order: asc
97
sort_type: natural
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Uses sidebar_label from YAML frontmatter as the nav/sidebar title,
2+
# while keeping the full title for the HTML <title> element (via page.meta.title).
3+
#
4+
# Because on_page_context fires per-page before each template render, we must
5+
# fix ALL page titles on the first call so the sidebar is consistent across
6+
# every rendered page.
7+
8+
_titles_fixed = False
9+
10+
11+
def on_page_context(context, page, config, nav, **kwargs):
12+
global _titles_fixed
13+
if not _titles_fixed:
14+
_titles_fixed = True
15+
_fix_all_titles(nav)
16+
return context
17+
18+
19+
def _fix_all_titles(items):
20+
for item in items:
21+
if hasattr(item, 'children') and item.children:
22+
_fix_all_titles(item.children)
23+
if hasattr(item, 'meta') and 'sidebar_label' in getattr(item, 'meta', {}):
24+
item.title = item.meta['sidebar_label']

tools/mkdocs/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ remote_branch: gh-pages
2222

2323
hooks:
2424
- mkdocs-hooks/custom-edit-url.py
25+
- mkdocs-hooks/sidebar-label.py
2526

2627
# General site info
2728

0 commit comments

Comments
 (0)