-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
240 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/docusaurus-plugin-content-docs/src/__tests__/numberPrefix.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {stripNumberPrefix} from '../numberPrefix'; | ||
|
||
describe('stripNumberPrefix', () => { | ||
test('should strip number prefix if present', () => { | ||
expect(stripNumberPrefix('1-My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('01-My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('001-My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('001 - My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('001 - My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('999 - My Doc')).toEqual('My Doc'); | ||
// | ||
expect(stripNumberPrefix('1---My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('01---My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('001---My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('001 --- My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('001 --- My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('999 --- My Doc')).toEqual('My Doc'); | ||
// | ||
expect(stripNumberPrefix('1___My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('01___My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('001___My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('001 ___ My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('001 ___ My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('999 ___ My Doc')).toEqual('My Doc'); | ||
// | ||
expect(stripNumberPrefix('1.My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('01.My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('001.My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('001 . My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('001 . My Doc')).toEqual('My Doc'); | ||
expect(stripNumberPrefix('999 . My Doc')).toEqual('My Doc'); | ||
}); | ||
|
||
test('should not strip number prefix if pattern does not match', () => { | ||
const badPatterns = [ | ||
'a1-My Doc', | ||
'My Doc-000', | ||
'00abc01-My Doc', | ||
'My 001- Doc', | ||
'My -001 Doc', | ||
]; | ||
|
||
badPatterns.forEach((badPattern) => { | ||
expect(stripNumberPrefix(badPattern)).toEqual(badPattern); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/docusaurus-plugin-content-docs/src/numberPrefix.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
export function stripNumberPrefix(str: string) { | ||
const numberPrefixPattern = /(?:^(\d)+(\s)*([-_.])+(\s)*)(?<suffix>.*)/; | ||
const result = numberPrefixPattern.exec(str); | ||
return result?.groups?.suffix ?? str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...autogenerated-folder/000-My First Category/001- Some Subfolder/Subfolder Doc.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This doc is in a subfolder |
File renamed without changes.
Oops, something went wrong.