Skip to content

Commit 9876934

Browse files
author
Al Manning
committed
abs path link replacement for nested pages
1 parent 0491c06 commit 9876934

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,8 @@ export const updateLinks = (
543543
console.log("linkFullFileName", linkFullFileName);
544544

545545
let siteFilePath = linkFullFileName;
546-
const isRelative =
547-
!siteFilePath.startsWith("/") && docFileNamePathList.length > 1;
548-
if (isRelative) {
546+
const isAbsolute = siteFilePath.startsWith("/");
547+
if (!isAbsolute && docFileNamePathList.length > 1) {
549548
const relativePath = docFileNamePathList
550549
.slice(0, docFileNamePathList.length - 1)
551550
.join("/");
@@ -556,6 +555,11 @@ export const updateLinks = (
556555
siteFilePath = `${relativePath}/${linkFullFileName}`;
557556
}
558557
}
558+
559+
if (isAbsolute) {
560+
siteFilePath = siteFilePath.slice(1); //remove '/'
561+
}
562+
559563
console.log("siteFilePath", siteFilePath);
560564

561565
const sitePage: SitePage | null = fileMetadataTable[siteFilePath] ?? null;

tests/unit/confluence.test.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,6 +2706,23 @@ const runUpdateLinks = () => {
27062706
fileName: "authoring/links2.xml",
27072707
};
27082708

2709+
const UPDATE_LINKS_ONE_NESTED_ABS: ContentUpdate = {
2710+
contentChangeType: ContentChangeType.update,
2711+
id: "43778049",
2712+
version: null,
2713+
title: "Links2",
2714+
type: "page",
2715+
status: "current",
2716+
ancestors: [{ id: "42336414" }],
2717+
body: {
2718+
storage: {
2719+
value: `<a href='/release-planning.qmd'>Release Planning</a>`,
2720+
representation: "storage",
2721+
},
2722+
},
2723+
fileName: "authoring/links2.xml",
2724+
};
2725+
27092726
const UPDATE_LINKS_ONE_ANCHOR: ContentUpdate = {
27102727
contentChangeType: ContentChangeType.update,
27112728
id: "19890228",
@@ -2751,7 +2768,7 @@ const runUpdateLinks = () => {
27512768
) => {
27522769
const result = updateLinks(fileMetadataTable, changes, server, parent);
27532770
console.log("result", result);
2754-
// assertEquals(expected, result);
2771+
assertEquals(expected, result);
27552772
};
27562773

27572774
test(suiteLabel("no_files"), async () => {
@@ -2800,7 +2817,7 @@ const runUpdateLinks = () => {
28002817
check(expected, changes, fileMetadataTable);
28012818
});
28022819

2803-
otest(suiteLabel("one_update_link_nested_relative"), async () => {
2820+
test(suiteLabel("one_update_link_nested_relative"), async () => {
28042821
const changes: ConfluenceSpaceChange[] = [UPDATE_LINKS_ONE_NESTED];
28052822
const rootURL = "fake-server/wiki/spaces/QUARTOCONF/pages";
28062823
const expectedUpdate: ContentUpdate = {
@@ -2816,6 +2833,22 @@ const runUpdateLinks = () => {
28162833
check(expected, changes, fileMetadataTable);
28172834
});
28182835

2836+
otest(suiteLabel("one_update_link_nested_absolute"), async () => {
2837+
const changes: ConfluenceSpaceChange[] = [UPDATE_LINKS_ONE_NESTED_ABS];
2838+
const rootURL = "fake-server/wiki/spaces/QUARTOCONF/pages";
2839+
const expectedUpdate: ContentUpdate = {
2840+
...UPDATE_LINKS_ONE_NESTED_ABS,
2841+
body: {
2842+
storage: {
2843+
value: `<a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/19890228/Release%20Planning\'>Release Planning</a>`,
2844+
representation: "storage",
2845+
},
2846+
},
2847+
};
2848+
const expected: ConfluenceSpaceChange[] = [expectedUpdate];
2849+
check(expected, changes, fileMetadataTable);
2850+
});
2851+
28192852
test(suiteLabel("one_update_link_anchor"), async () => {
28202853
const changes: ConfluenceSpaceChange[] = [UPDATE_LINKS_ONE_ANCHOR];
28212854
const rootURL = "fake-server/wiki/spaces/QUARTOCONF/pages";

0 commit comments

Comments
 (0)