Skip to content

feat(v2): docs, make numberPrefixParser configurable, better defaults, minor breaking-changes - #4655

Merged
slorber merged 4 commits into
masterfrom
slorber/parseNumberPrefix-refactor
Apr 21, 2021
Merged

slorber merged 4 commits into
masterfrom
slorber/parseNumberPrefix-refactor

Conversation

@slorber

@slorber slorber commented Apr 21, 2021 •

Copy link
Copy Markdown
Collaborator

Motivation

Alpha 73 introduced autogenerated sidebars with support for number prefixes like 01-My Folder/02-My Doc.

This default non-configurable logic is annoying for some users that use numbers in filenames that should rather not be interpreted as numbers prefixes by default:

As it's impossible to predict all possible filename patterns that a Docusaurus would like to use, we try to provide good opinionated defaults and ignore some common patterns.

This new default behavior can be disabled entirely and revert back to a post-alpha-73 behavior, or the user can also provide its own parsing logic:

        numberPrefixParser: function (filename) {
          // Implement your own logic to extract a potential number prefix
          const numberPrefix = findNumberPrefix(filename);
          // Prefix found: return it with the cleaned filename
          if (numberPrefix) {
            return {
              numberPrefix,
              filename: filename.replace(prefix, ''),
            };
          }
          // No number prefix found
          return {numberPrefix: undefined, filename};
        },

Minor breaking changes (from alpha.73):

  • rename doc frontmatter: strip_number_prefix to parse_number_prefix for consistency
  • changes in the default numberPrefixParser (now ignore dates and versions)

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

tests

@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Apr 21, 2021
@slorber
slorber requested a review from lex111 as a code owner April 21, 2021 09:08
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Apr 21, 2021
@netlify

netlify Bot commented Apr 21, 2021

Copy link
Copy Markdown

@netlify

netlify Bot commented Apr 21, 2021

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Apr 21, 2021 •

Copy link
Copy Markdown

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 40
🟢 Accessibility 96
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

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

@netlify

netlify Bot commented Apr 21, 2021 •

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Apr 21, 2021 •

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 630 kB

ℹ️ View Unchanged
Filename Size Change
website/build/assets/css/styles.********.css 87.5 kB 0 B
website/build/assets/js/main.********.js 453 kB 0 B
website/build/blog/2017/12/14/introducing-docusaurus/index.html 62.3 kB 0 B
website/build/docs/introduction/index.html 235 B 0 B
website/build/index.html 27.1 kB 0 B

compressed-size-action

@netlify

netlify Bot commented Apr 21, 2021 •

Copy link
Copy Markdown

@valentine

Copy link
Copy Markdown

Not really sure where I should comment, but I would like to propose that yyyymmdd be ignored as well.

^\d{8}(.*)$ would match 20210422.md and more.

If we want to add slightly more complexity, ^[19|20]{2}\d{2}[0|1]{1}\d{1}[0-3]{1}\d{1}(.*)$ could help ensure that it is a (mostly) valid date.

@slorber

slorber commented Apr 22, 2021

Copy link
Copy Markdown
Collaborator Author

@valentine we have the infra in place for customizations, and PRs are welcome.

I don't think we'll ever find the perfect opinionated regex to fit all usecases by default. Some users would be happy if 20210422-my-doc.md was converted to /MyDoc, and some would prefer to have /20210422-my-doc

Note that we don't extract number prefixes if there is no separator such as -_. so in your case 20210422.md will not be processed (otherwise it would have an empty suffix)

If you want these heuristics to keep being improved please open a proper bug report explaining how something is affecting you in practice. I think you didn't encounter any bug or annoyance yet right?

@valentine

Copy link
Copy Markdown

@slorber Thanks for your thoughts. Yes, this won't affect me, especially after alpha.74 is released.

I was preemptively thinking how it might be possible to make this feature better, but it looks like I completely looked past how a number without a separator won't be affected anyway.

@slorber
slorber deleted the slorber/parseNumberPrefix-refactor branch August 17, 2021 17:49
mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
…, minor breaking-changes (meta#4655)

* make number prefix parsing logic configurable

* Make numberPrefixParser configurable + rename frontmatter + avoid parsing date/version patterns by default

* add more tests

* more test cases
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.

[2.0.0-alpha.73] Numeric value in subdirectory of DOCS yields issues with sideba

3 participants