refactor: enforce named capture groups; clean up regexes (#6524)

* refactor: enforce named capture groups; clean up regexes

* fixes

* fix
This commit is contained in:
Joshua Chen 2022-02-01 17:43:15 +08:00 committed by GitHub
parent c56e6194b4
commit 1cefb643dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 80 additions and 77 deletions

View file

@ -11,14 +11,14 @@ import type {NumberPrefixParser} from '@docusaurus/plugin-content-docs';
const IgnoredPrefixPatterns = (() => {
// ignore common date-like patterns: https://github.com/facebook/docusaurus/issues/4640
const DateLikePrefixRegex =
/^((\d{2}|\d{4})[-_.]\d{2}([-_.](\d{2}|\d{4}))?)(.*)$/;
/^(?:\d{2}|\d{4})[-_.]\d{2}(?:[-_.](?:\d{2}|\d{4}))?.*$/;
// ignore common versioning patterns: https://github.com/facebook/docusaurus/issues/4653
// note: we could try to parse float numbers in filenames but that is
// probably not worth it as a version such as "8.0" can be interpreted as both
// a version and a float. User can configure her own NumberPrefixParser if
// she wants 8.0 to be interpreted as a float
const VersionLikePrefixRegex = /^(\d+[-_.]\d+)(.*)$/;
const VersionLikePrefixRegex = /^\d+[-_.]\d+.*$/;
return new RegExp(
`${DateLikePrefixRegex.source}|${VersionLikePrefixRegex.source}`,