mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 16:17:25 +02:00
fix(v2): make client-redirect-plugin not baseUrl sensitive (#3010)
* feat(v2): use relative routes path in postBuild hook * feat(v2): use relativeRoutesPath in other methods and modify tests * fix(v2): fix D2 client redirects and tests * feat(v2): add tests for relativeRoutesPaths * fix(v2): fix some typos in configValidation * fix(v2): fix an eslint warning and restart github action * refactor(v2): create a removePrefix method * refactor(v2): inline unnecessary method
This commit is contained in:
parent
b58a53eae8
commit
2e055f4ae2
10 changed files with 81 additions and 71 deletions
|
@ -22,6 +22,7 @@ import {
|
|||
addTrailingSlash,
|
||||
removeTrailingSlash,
|
||||
removeSuffix,
|
||||
removePrefix,
|
||||
getFilePathForRoutePath,
|
||||
} from '../index';
|
||||
|
||||
|
@ -419,6 +420,21 @@ describe('removeSuffix', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('removePrefix', () => {
|
||||
test('should no-op 1', () => {
|
||||
expect(removePrefix('abcdef', 'ijk')).toEqual('abcdef');
|
||||
});
|
||||
test('should no-op 2', () => {
|
||||
expect(removePrefix('abcdef', 'def')).toEqual('abcdef');
|
||||
});
|
||||
test('should no-op 3', () => {
|
||||
expect(removePrefix('abcdef', '')).toEqual('abcdef');
|
||||
});
|
||||
test('should remove prefix', () => {
|
||||
expect(removePrefix('abcdef', 'ab')).toEqual('cdef');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFilePathForRoutePath', () => {
|
||||
test('works for /', () => {
|
||||
expect(getFilePathForRoutePath('/')).toEqual('/index.html');
|
||||
|
|
|
@ -384,6 +384,10 @@ export function removeSuffix(str: string, suffix: string): string {
|
|||
return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
|
||||
}
|
||||
|
||||
export function removePrefix(str: string, prefix: string): string {
|
||||
return str.startsWith(prefix) ? str.slice(prefix.length) : str;
|
||||
}
|
||||
|
||||
export function getFilePathForRoutePath(routePath: string): string {
|
||||
const fileName = path.basename(routePath);
|
||||
const filePath = path.dirname(routePath);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue