Skip to content

Keep each entry's own title when a page is listed more than once in nav - #103

Merged
shenxianpeng merged 2 commits into
mainfrom
fix/duplicate-nav-titles
Sep 24, 2026
Merged

shenxianpeng merged 2 commits into
mainfrom
fix/duplicate-nav-titles

Conversation

@shenxianpeng

Copy link
Copy Markdown
Member

When the same file is listed more than once in nav, every entry shows the title of the first one:

nav:
  - French Main Dishes: french.md
  - French Desserts: french.md   # rendered as "French Main Dishes"

Root cause: navigation reuses the page already attached to File.page (so that plugins can provide their own Page subclass). The second entry therefore got the same Page object, and its configured title was dropped. The page also appeared twice in Navigation.pages, which scrambled the previous/next links.

Fix: repeated entries are now PageAlias objects (in mkdocs.structure.nav):

  • own title (falls back to the page's title if none is given in nav) and own parent;
  • every other attribute (url, active, toc, meta, is_page, ...) is forwarded to the page, so existing theme templates work unchanged;
  • not included in Navigation.pages, so the page is built once and appears once in previous/next links.

The first occurrence is still the page object itself, including pages provided by plugins.

Verified with both built-in themes: each entry shows its own title, the page's TOC is rendered once, and previous/next links are linear again. The theme developer guide documents PageAlias under "Navigation Objects".

Related Issue

No issue in this repository.

Checklist

  • New tests added for new behavior (if applicable)
  • Documentation updated (if applicable)
  • Release notes docs/about/release-notes.md updated (if applicable)

🤖 Generated with Claude Code

shenxianpeng and others added 2 commits September 24, 2026 12:32
When the same file was listed more than once in `nav`, every entry
showed the title of the first one. Navigation reuses the page already
attached to the file (so that plugins can provide their own `Page`), so
the second entry got the same `Page` object and its configured title was
dropped. The page also appeared twice in `Navigation.pages`, which
scrambled the previous/next links.

Repeated entries are now `PageAlias` objects: they have their own
`title` and `parent`, and forward all other attributes to the page, so
existing theme templates keep working. Aliases aren't part of
`Navigation.pages`, so the page is built once and appears once in
previous/next links.

Co-Authored-By: Claude <[email protected]>
@github-actions github-actions Bot added the bug Something isn't working label Sep 24, 2026
@shenxianpeng
shenxianpeng merged commit 6657fa0 into main Sep 24, 2026
22 checks passed
@shenxianpeng
shenxianpeng deleted the fix/duplicate-nav-titles branch September 24, 2026 09:44
@codspeed

codspeed Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 12.21%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 27 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_get_yaml_loader 316.5 µs 360.5 µs -12.21%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/duplicate-nav-titles (73d2845) with main (7c41de6)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant