Skip to content

Commit 4cfd0f5

Browse files
author
Al Manning
committed
index page link resolution creation and updates
1 parent 166af98 commit 4cfd0f5

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,14 @@ export const updateLinks = (
680680
siteFilePath = siteFilePath.slice(1); //remove '/'
681681
}
682682

683+
if (siteFilePath.endsWith("/index.qmd")) {
684+
//flatten child index links to the parent
685+
const siteFilePathParent = siteFilePath.replace("/index.qmd", "");
686+
if (fileMetadataTable[siteFilePathParent]) {
687+
siteFilePath = siteFilePathParent;
688+
}
689+
}
690+
683691
const sitePage: SitePage | null = fileMetadataTable[siteFilePath] ?? null;
684692

685693
if (sitePage) {

tests/unit/confluence.test.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3694,6 +3694,16 @@ const runUpdateLinks = () => {
36943694
id: "123456",
36953695
metadata: { fileName: "special-characters.xml" },
36963696
},
3697+
["folder/index.qmd"]: {
3698+
title: "fake-index-title",
3699+
id: "fake-index-id",
3700+
metadata: { editor: "v2", fileName: "folder/index.xml" },
3701+
},
3702+
["folder"]: {
3703+
title: "fake-folder-title",
3704+
id: "fake-folder-id",
3705+
metadata: { editor: "v2", fileName: "folder" },
3706+
},
36973707
};
36983708

36993709
const UPDATE_NO_LINKS: ContentUpdate = {
@@ -3731,6 +3741,23 @@ const runUpdateLinks = () => {
37313741
fileName: "release-planning.xml",
37323742
};
37333743

3744+
const UPDATE_LINKS_INDEX: ContentUpdate = {
3745+
contentChangeType: ContentChangeType.update,
3746+
id: "19890228",
3747+
version: null,
3748+
title: "Release Planning",
3749+
type: "page",
3750+
status: "current",
3751+
ancestors: [{ id: "19759105" }],
3752+
body: {
3753+
storage: {
3754+
value: "<a href='folder/index.qmd'>team</a>",
3755+
representation: "storage",
3756+
},
3757+
},
3758+
fileName: "release-planning.xml",
3759+
};
3760+
37343761
const UPDATE_LINKS_SPECIAL_CHAR: ContentUpdate = {
37353762
contentChangeType: ContentChangeType.update,
37363763
id: "19890228",
@@ -3890,6 +3917,22 @@ const runUpdateLinks = () => {
38903917
);
38913918
});
38923919

3920+
test(suiteLabel("one_update_link_index"), async () => {
3921+
const changes: ConfluenceSpaceChange[] = [UPDATE_LINKS_INDEX];
3922+
const rootURL = "fake-server/wiki/spaces/QUARTOCONF/pages";
3923+
const expectedUpdate: ContentUpdate = {
3924+
...UPDATE_LINKS_INDEX,
3925+
body: {
3926+
storage: {
3927+
value: `<a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/fake-folder-id'>team</a>`,
3928+
representation: "storage",
3929+
},
3930+
},
3931+
};
3932+
const expected: ConfluenceSpaceChange[] = [expectedUpdate];
3933+
check(expected, changes, fileMetadataTable, "fake-server", FAKE_PARENT);
3934+
});
3935+
38933936
test(suiteLabel("one_update_link_special_char"), async () => {
38943937
const changes: ConfluenceSpaceChange[] = [UPDATE_LINKS_SPECIAL_CHAR];
38953938
const rootURL = "fake-server/wiki/spaces/QUARTOCONF/pages";
@@ -4724,5 +4767,5 @@ if (RUN_ALL_TESTS) {
47244767
runConfluenceParentFromString();
47254768
runFlattenIndexes();
47264769
} else {
4727-
runFlattenIndexes();
4770+
runUpdateLinks();
47284771
}

0 commit comments

Comments
 (0)