Skip to content

Use index page titles for auto-generated section names - #54

Merged
shenxianpeng merged 4 commits into
mainfrom
feature/smart-section-titles
Aug 3, 2026
Merged

Use index page titles for auto-generated section names#54
shenxianpeng merged 4 commits into
mainfrom
feature/smart-section-titles

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Apr 28, 2026

Copy link
Copy Markdown
Member

When the nav configuration is not explicitly set, MkDocs generates navigation sections from directory names. This change updates those auto-generated section titles to use the index page's title instead of the raw directory name when an index page exists in the section.

For example, an about/ directory with about/index.md whose title is "About this Project" will now show "About this Project" as the section name instead of about.

Scope and behavior:

  • Only applies to auto-generated navigation (nav unset). Explicitly configured nav section titles are always preserved.
  • Only affects sections that contain an index page, and uses the existing Page.title precedence (metadata title > first H1 > filename fallback).
  • Applied after pages are read and before template rendering, so rendered navigation reflects the updated titles.

Fixes mkdocs/mkdocs#3356

Type of Change

  • New feature
  • Bug fix
  • Documentation update
  • Refactor / code cleanup
  • CI / build / dependency update
  • Other (describe below)

Checklist

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

@github-actions github-actions Bot added the enhancement New feature or request label Apr 28, 2026
@shenxianpeng shenxianpeng added this to the v1.8.0 milestone Apr 28, 2026
@shenxianpeng
shenxianpeng force-pushed the feature/smart-section-titles branch 3 times, most recently from 005c1fe to 5a048db Compare April 29, 2026 06:38
When the 'nav' configuration is not explicitly set, MkDocs generates
navigation sections from directory names. This change updates those
auto-generated section titles to use the index page's title instead
of the raw directory name when an index page exists in the section.

For example, an 'about/' directory with 'about/index.md' whose title
is 'About this Project' will now show 'About this Project' as the
section name instead of 'about'.

This only applies after pages have been read/rendered (titles are
resolved from metadata or headings), and only affects sections that
contain an index page.

Fixes #3656, #3356
Smart section titles must not override section titles that users
explicitly configure in the 'nav' setting. Restrict the behavior to
auto-generated navigation, matching upstream issue mkdocs/mkdocs#3356.

Also move the release note entry to the unreleased 1.7.4 section and
add integration tests covering both auto-generated and explicit nav.
@shenxianpeng
shenxianpeng force-pushed the feature/smart-section-titles branch from b296996 to f6cf226 Compare August 3, 2026 17:57
@shenxianpeng
shenxianpeng merged commit d1c42ad into main Aug 3, 2026
23 checks passed
@shenxianpeng
shenxianpeng deleted the feature/smart-section-titles branch August 3, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

smart section titles when no navigation is configured

1 participant