Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Handle smartcards storing URL without page name on the end
- Loading branch information
1 parent
f17dd84
commit d489f83
Showing
3 changed files
with
53 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export function cleanUpUrlIfConfluence( | ||
input: string, | ||
confluenceBaseUrl: string | ||
): string { | ||
let url: URL; | ||
|
||
// Check if the input is a valid URL | ||
try { | ||
url = new URL(input); | ||
} catch { | ||
return "#"; | ||
} | ||
|
||
const confluenceUrl = new URL(confluenceBaseUrl); | ||
if (url.hostname !== confluenceUrl.hostname) { | ||
return input; | ||
} | ||
|
||
// Check if the input matches the specified path format | ||
const pathRegex = /\/wiki\/spaces\/(?:~)?(\w+)\/pages\/(\d+)(?:\/(\w*))?/; | ||
const matches = url.pathname.match(pathRegex); | ||
|
||
if (matches) { | ||
// Update the pathname to remove the last optional part | ||
url.pathname = `/wiki/spaces/${matches[1]}/pages/${matches[2]}`; | ||
|
||
// Return the updated URL | ||
return url.href; | ||
} | ||
|
||
return input; | ||
} |
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