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