Skip to content

Conversation

@sharp-bits
Copy link

Provide use_index_title option within .nav.yml which will use the title defined in the index.md frontmatter as the nav title. This is the behavior we expected when transitioning from JTD and this is a preferable option to renaming all the directories.

Fixes #61 and also provides a better solution for mkdocs #2086

(Thanks for the awesome plugin)

@sharp-bits
Copy link
Author

It wasn't clear which checks were going to be ran in CI so I added a Makefile to make it more obvious. I'll take that out if it isn't desired.

resolved_children: list[NavPage | NavSection | NavLink] = resolve_in_priority_order(parsed_children, context)

return section_type(resolved_children, path=self.path, title=self._title)
title = self._resolved_title or dirname_to_title(self.path.name)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling dirname_to_title shouldn't be necessary here as it's already called by _generate_title

context.visit(self._directory)

# Generate title if not already set
if self._resolved_title is None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always be true. I think you don't actually need two separate fields (_explicit_titleand _resolved_title).

I would revert back to _title and then do this:

if self._title is None:
    self._title = self._generate_title(context)

@@ -0,0 +1,210 @@
def test_use_index_title_disabled_by_default(mkdocs):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you drop use_index_title_ from all the function titles? It's a bit redundant since it's already in the filename.

- User Guide Documentation: user-guide/index.md
- Another page: user-guide/another-page.md
"""
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on the tests 👏


To use the title from an `index.md` file as the directory navigation title:

``` tab | `true`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be /// instead of the backticks to render correctly

??? tip "Interaction with other title settings"
- **Custom title**: A `title` set in `.nav.yml` always takes precedence over `use_index_title`
- **External title**: A title specified in the parent directory's `nav` configuration takes precedence
- **Preserve directory names**: When `preserve_directory_names: true` is set, it takes precedence over `use_index_title`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate you updating the docs as well 🙏

@@ -0,0 +1,50 @@
.PHONY: all help init clean test lint format type-check coverage
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if you could remove the Makefile. Thanks for putting in the effort though!
I do see your point that it's difficult for contributors to know what they should run. I'll work on improving that 👍

@sharp-bits
Copy link
Author

@lukasgeiter Thanks for the feedback! It's been a long week but I will get back to this eventually and clean it up.

@GodVenn
Copy link

GodVenn commented Oct 17, 2025

@sharp-bits Soon? 🙏 We would love this feature

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default title to directory/index.md

4 participants