-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(content-docs): use category index convention to infer document title #8052
base: main
Are you sure you want to change the base?
fix(content-docs): use category index convention to infer document title #8052
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that looks like a useful change that I'll classify as a bug fix (and not a breaking change)
Note we already have a convention to detect "category index documents", see
// By convention, Docusaurus considers some docs are "indexes":
// - index.md
// - readme.md
// - <folder>/<folder>.md
//
// This function is the default implementation of this convention
//
// Those index docs produce a different behavior
// - Slugs do not end with a weird "/index" suffix
// - Auto-generated sidebar categories link to them as intro
export const isCategoryIndex: CategoryIndexMatcher = ({
fileName,
directories,
}): boolean => {
const eligibleDocIndexNames = [
'index',
'readme',
directories[0]?.toLowerCase(),
];
return eligibleDocIndexNames.includes(fileName.toLowerCase());
};
It makes sense to find a way to reuse the same logic instead of duplicating it.
We also want to cover such subtle behaviors with unit tests
Also note that with autogeneated sidebars, folders might have a number prefix for ordering reasons, and you may want to strip that number in the infered title: /xx/yy/03-zz/index.md
should infer to zz
and not 03-zz
? (see impl of getSlug()
for inspiration)
Good job!
Sorry to admit that I have few ideas on how to write unit tests for directory strucurues.
Yep! |
Pre-flight checklist
Motivation
I found if I have file path like
xx/yy/zz/index.md
orxx/yy/zz/readme.md
without a 'tittle' frontmatter or '#1' title in the document, then the title of this file shown in the sidebar would beindex
orreadme
, which is not desired, since the directory namezz
may be more suitable.Test Plan
Test links
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
Related issues/PRs