Skip to content

Commit

Permalink
refactor spaceKey url pattern for custom domains
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycarambat committed May 16, 2024
1 parent cf969ad commit 87b41a6
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions collector/utils/extensions/Confluence/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

// Custom "display" Confluence URL match
const customDisplayPattern = new UrlPattern(
"https\\://(:subdomain.):domain.:tld/display/(:spaceKey)/*"
);
const customDisplayMatch = customDisplayPattern.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);
});

if (customMatch || customDisplayMatch) {
if (customMatch) {
customMatch.customDomain =
(customMatch.subdomain ? `${customMatch.subdomain}.` : "") + //

This comment has been minimized.

Copy link
@timothycarambat

timothycarambat May 16, 2024

Author Member

@cope I got an error when I pulled out this function into a REPL and tried to test some domain patterns, so i just refactored it a tiny bit to just do a loop on any new patterns and return the first one that is true.

This comment has been minimized.

Copy link
@cope

cope May 16, 2024

Contributor

weird, but I like the array approach better

`${customMatch.domain}.${customMatch.tld}`;
Expand Down

0 comments on commit 87b41a6

Please sign in to comment.