Added support for URLs with prefix

Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com>
This commit is contained in:
Andre Wanlin
2023-05-11 10:39:56 -05:00
parent 8492db6cbc
commit 6ece5434ca
2 changed files with 16 additions and 0 deletions
@@ -30,6 +30,16 @@ describe('createConfluenceVariables', () => {
expect(titleWithSpaces).toEqual('Page Title');
});
it('should return values for Confluence Url with prefix', () => {
const url =
'https://confluence.example.com/prefix/display/PREFIXSPACEKEY/Prefix+Page+Title';
const { spacekey, title, titleWithSpaces } = createConfluenceVariables(url);
expect(spacekey).toEqual('PREFIXSPACEKEY');
expect(title).toEqual('Prefix+Page+Title');
expect(titleWithSpaces).toEqual('Prefix Page Title');
});
it('should return values for Confluence Cloud Url', () => {
const url =
'https://example.atlassian.net/wiki/spaces/CLOUDSPACEKEY/pages/1234567/Cloud+Page+Title';
@@ -197,6 +197,12 @@ export const createConfluenceVariables = (url: string) => {
title = params.pathname.split('/')[3];
titleWithSpaces = title?.replace(/\+/g, ' ');
return { spacekey, title, titleWithSpaces };
} else if (params.pathname.split('/')[2] === 'display') {
// https://confluence.example.com/prefix/display/SPACEKEY/Page+Title
spacekey = params.pathname.split('/')[3];
title = params.pathname.split('/')[4];
titleWithSpaces = title?.replace(/\+/g, ' ');
return { spacekey, title, titleWithSpaces };
} else if (params.pathname.split('/')[2] === 'spaces') {
// https://example.atlassian.net/wiki/spaces/SPACEKEY/pages/1234567/Page+Title
spacekey = params.pathname.split('/')[3];