Skip to content
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

feat(content-docs): expose isCategoryIndex matcher to customize conventions #6451

Merged
merged 7 commits into from
Jan 26, 2022

Conversation

Josh-Cena
Copy link
Collaborator

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

@Josh-Cena Josh-Cena added the pr: new feature This PR adds a new API or behavior. label Jan 23, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jan 23, 2022
@netlify
Copy link

netlify bot commented Jan 23, 2022

✔️ [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

@github-actions
Copy link

github-actions bot commented Jan 23, 2022

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 84
🟢 Accessibility 100
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 92

Lighthouse ran on https://deploy-preview-6451--docusaurus-2.netlify.app/

@github-actions
Copy link

github-actions bot commented Jan 23, 2022

Size Change: +1.67 kB (0%)

Total Size: 717 kB

Filename Size Change
website/.docusaurus/globalData.json 45.5 kB +462 B (+1%)
website/build/assets/js/main.********.js 537 kB +1.21 kB (0%)
ℹ️ View Unchanged
Filename Size
website/build/assets/css/styles.********.css 104 kB
website/build/index.html 29.8 kB

compressed-size-action

Copy link
Collaborator

@slorber slorber left a 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(),
Copy link
Collaborator

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
Copy link
Collaborator

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.
Copy link
Collaborator

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(
Copy link
Collaborator

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 🤪

Copy link
Collaborator Author

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

@slorber
Copy link
Collaborator

slorber commented Jan 26, 2022

Almost good, lools like like there's some edge case on windows though, maybe related to posix/win32 path separators

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Doc plugin option isCategoryIndex
3 participants