summaryrefslogtreecommitdiff
path: root/docs/src/util.ts
diff options
context:
space:
mode:
authorGravatar Caleb Jasik <calebjasik@jasik.xyz> 2021-09-04 19:55:55 -0500
committerGravatar GitHub <noreply@github.com> 2021-09-04 19:55:55 -0500
commit73a98821b785e0de1e059d50bbdce402b3a8eaca (patch)
tree0c3b44563edddbd54fb2a2687ace4b350426e934 /docs/src/util.ts
parent02c38a0d3b1e71d2cb708c5ef2d2c472ca977e5a (diff)
downloadastro-73a98821b785e0de1e059d50bbdce402b3a8eaca.tar.gz
astro-73a98821b785e0de1e059d50bbdce402b3a8eaca.tar.zst
astro-73a98821b785e0de1e059d50bbdce402b3a8eaca.zip
📘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
Diffstat (limited to 'docs/src/util.ts')
-rw-r--r--docs/src/util.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/docs/src/util.ts b/docs/src/util.ts
index 0ec91bce0..269373735 100644
--- a/docs/src/util.ts
+++ b/docs/src/util.ts
@@ -2,3 +2,13 @@ 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(/[/\\]+$/, '');
+}