-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat(content-docs): expose isCategoryIndex matcher to customize conventions #6451
Conversation
✔️ [V2] 🔨 Explore the source changes: bf2e64e 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/61f17929c12b860007a948fa 😎 Browse the preview: https://deploy-preview-6451--docusaurus-2.netlify.app |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-6451--docusaurus-2.netlify.app/ |
Size Change: +1.67 kB (0%) Total Size: 717 kB
ℹ️ View Unchanged
|
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 great to me 👍 just some tiny changes
this is only ever used for sidebar items generator
Not 100% true (cf slugs) but I don't think it really matters as we already provide options to customize those
isConventionalDocIndex({ | ||
fileName: path.parse(source).name, | ||
extension: path.parse(source).ext, | ||
directories: sourceDirName.split('/').reverse(), |
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.
used twice, extract in util function
@@ -194,6 +194,98 @@ Naming your introductory document `README.md` makes it show up when browsing the | |||
|
|||
::: | |||
|
|||
### Customizing category index matching |
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.
IMHO this doc should be much smaller and less exhaustive
The goal is not to have 1000 words for each tiny customization feature we have, otherwise we are distracting users from reading the essential information (and the metadata seems more important than this section).
Maybe hide all this in a summary/details view?
@@ -194,6 +194,98 @@ Naming your introductory document `README.md` makes it show up when browsing the | |||
|
|||
::: | |||
|
|||
### Customizing category index matching | |||
|
|||
It is possible to opt out any of the category index conventions, or define even more conventions. You can inject your own `isCategoryIndex` matcher through the [`sidebarItemsGenerator`](#customize-the-sidebar-items generator) callback. For example, you can also pick `intro` as another file name eligible for automatically becoming the category index. |
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.
numberPrefixParser: DefaultNumberPrefixParser, | ||
isCategoryIndex({fileName, directories}) { | ||
return ( | ||
fileName.replace( |
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.
🤯 why not using something simpler like file.endsWith("-index")
It was not so easy for me to understand the intent of this code 🤪
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.
The intention is to only match those with the same prefix as the category name, as described in #6255
Almost good, lools like like there's some edge case on windows though, maybe related to posix/win32 path separators |
Motivation
Close #6379. I ended up not creating a new root config option, because this is only ever used for sidebar items generator. Injecting it as part of the generator allows us to provide the default implementation in a non-strained way as well.
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Unit tests + dogfooding