mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-09 23:27:28 +02:00
migrate useful helper functions to docusaurus-utils
This commit is contained in:
parent
c964a1e3b6
commit
6b507630e3
7 changed files with 77 additions and 95 deletions
|
@ -339,3 +339,24 @@ export function isValidPathname(str: string): boolean {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function addTrailingSlash(str: string) {
|
||||
return str.endsWith('/') ? str : `${str}/`;
|
||||
}
|
||||
|
||||
export function removeTrailingSlash(str: string) {
|
||||
return removeSuffix(str, '/');
|
||||
}
|
||||
|
||||
export function removeSuffix(str: string, suffix: string) {
|
||||
if (suffix === '') {
|
||||
return str; // always returns "" otherwise!
|
||||
}
|
||||
return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
|
||||
}
|
||||
|
||||
export function getFilePathForRoutePath(routePath: string) {
|
||||
const fileName = path.basename(routePath);
|
||||
const filePath = path.dirname(routePath);
|
||||
return path.join(filePath, `${fileName}/index.html`);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue