refactor spaceKey url pattern for custom domains

This commit is contained in:
timothycarambat 2024-05-16 11:01:34 -07:00
parent cf969adf37
commit 87b41a60e9

View File

@ -19,19 +19,17 @@ function validSpaceUrl(spaceUrl = "") {
return { valid: true, result: atlassianMatch };
}
// Custom Confluence URL match
const customPattern = new UrlPattern(
"https\\://(:subdomain.):domain.:tld/wiki/spaces/(:spaceKey)/*"
);
const customMatch = customPattern.match(spaceUrl);
let customMatch = null;
[
"https\\://(:subdomain.):domain.:tld/wiki/spaces/(:spaceKey)/*", // Custom Confluence space
"https\\://(:subdomain.):domain.:tld/display/(:spaceKey)/*", // Custom Confluence space + Human-readable space tag.
].forEach((matchPattern) => {
if (!!customMatch) return;
const pattern = new UrlPattern(matchPattern);
customMatch = pattern.match(spaceUrl);
});
// Custom "display" Confluence URL match
const customDisplayPattern = new UrlPattern(
"https\\://(:subdomain.):domain.:tld/display/(:spaceKey)/*"
);
const customDisplayMatch = customDisplayPattern.match(spaceUrl);
if (customMatch || customDisplayMatch) {
if (customMatch) {
customMatch.customDomain =
(customMatch.subdomain ? `${customMatch.subdomain}.` : "") + //
`${customMatch.domain}.${customMatch.tld}`;