astro/docs/src/util.ts
Caleb Jasik 73a98821b7
📘DOC: Fix URL normalization for the Left Sidebar in docs (#1299)
* Fix URL normalization for the Left Sidebar in docs

* Move the fix into `util.ts` as suggested by @FredKSchott
2021-09-04 19:55:55 -05:00

14 lines
450 B
TypeScript

export function getLanguageFromURL(pathname: string) {
const langCodeMatch = pathname.match(/\/([a-z]{2}-?[A-Z]{0,2})\//);
return langCodeMatch ? langCodeMatch[1] : 'en';
}
/** Remove \ and / from beginning of string */
export function removeLeadingSlash(path: string) {
return path.replace(/^[/\\]+/, '');
}
/** Remove \ and / from end of string */
export function removeTrailingSlash(path: string) {
return path.replace(/[/\\]+$/, '');
}