Skip to content

Commit 166af98

Browse files
author
Al Manning
committed
single and multi-folder index flattening with broken link resolution:
1 parent 152158d commit 166af98

File tree

3 files changed

+47
-33
lines changed

3 files changed

+47
-33
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -513,27 +513,36 @@ export const flattenIndexes = (
513513
}
514514

515515
const fileName = getFileNameForChange(change);
516-
516+
const parentFileName = fileName.replace("/index.xml", "");
517+
const parentSitePage: SitePage = metadataByFileName[parentFileName];
517518
if (isIndexFile(change)) {
518-
// console.log("change", change);
519-
console.log("is index file, return");
520-
const parentId = fileName.replace("/index.xml", "");
521-
console.log("parentId", parentId);
522-
523-
// console.log("parentCreateChange", parentCreateChange);
524-
// if (!parentCreateChange) {
525-
// the parent has already been created, this index create
526-
// is actually an index parent update
527-
// const parentUpdate: ContentUpdate = buildContentUpdate(id);
528-
// }
519+
if (parentSitePage) {
520+
// The parent has already been created, this index create
521+
// is actually an index parent update update the folder with
522+
// index contents
523+
const parentUpdate = buildContentUpdate(
524+
parentSitePage.id,
525+
change.title,
526+
change.body,
527+
parentSitePage.metadata.fileName ?? "",
528+
"",
529+
ContentStatusEnum.current,
530+
PAGE_TYPE,
531+
null,
532+
parentSitePage.ancestors
533+
);
529534

530-
return accumulator;
535+
return [...accumulator, parentUpdate];
536+
} else {
537+
return [...accumulator]; //filter out index file creates
538+
}
531539
}
532540

533-
const indexChange: ConfluenceSpaceChange = indexLookup[fileName];
534-
if (indexChange && !isContentDelete(indexChange)) {
535-
change.title = indexChange.title ?? change.title;
536-
change.body = indexChange.body ?? change.body;
541+
const indexCreateChange: ConfluenceSpaceChange = indexLookup[fileName];
542+
543+
if (indexCreateChange && !isContentDelete(indexCreateChange)) {
544+
change.title = indexCreateChange.title ?? change.title;
545+
change.body = indexCreateChange.body ?? change.body;
537546
}
538547

539548
return [...accumulator, change];

src/publish/confluence/confluence.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ async function publish(
666666
trace("fileMetadata", fileMetadata);
667667

668668
let metadataByFilename = buildFileToMetaTable(existingSite);
669+
669670
trace("metadataByFilename", metadataByFilename);
670671

671672
let changeList: ConfluenceSpaceChange[] = buildSpaceChanges(
@@ -675,12 +676,8 @@ async function publish(
675676
existingSite
676677
);
677678

678-
console.log("before flatten", changeList);
679-
680679
changeList = flattenIndexes(changeList, metadataByFilename);
681680

682-
console.log("after flatten", changeList);
683-
684681
const { pass1Changes, pass2Changes } = updateLinks(
685682
metadataByFilename,
686683
changeList,
@@ -802,9 +799,6 @@ async function publish(
802799
existingSite = await fetchExistingSite(parentId);
803800
metadataByFilename = buildFileToMetaTable(existingSite);
804801

805-
console.log("existingSite", existingSite);
806-
console.log("metadataByFilename", metadataByFilename);
807-
808802
const linkUpdateChanges: ConfluenceSpaceChange[] = convertForSecondPass(
809803
metadataByFilename,
810804
pass2Changes,

tests/unit/confluence.test.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ import {
6161
Space,
6262
} from "../../src/publish/confluence/api/types.ts";
6363

64-
const RUN_ALL_TESTS = false;
65-
const FOCUS_TEST = true;
64+
const RUN_ALL_TESTS = true;
65+
const FOCUS_TEST = false;
66+
const HIDE_NOISE = true;
6667

6768
const xtest = (
6869
name: string,
@@ -3108,10 +3109,15 @@ const runFlattenIndexes = () => {
31083109
const FAKE_METADATA_ONE_FOLDER = {
31093110
["fake-parent"]: {
31103111
title: "Fake Parent Title",
3111-
id: "12345",
3112+
id: "fake-parent-id",
31123113
metadata: {
31133114
fileName: "fake-parent",
31143115
},
3116+
ancestors: [
3117+
{
3118+
id: "fake-space-id",
3119+
},
3120+
],
31153121
},
31163122
};
31173123

@@ -3299,7 +3305,7 @@ const runFlattenIndexes = () => {
32993305
assertEquals(expected, actual);
33003306
});
33013307

3302-
otest(suiteLabel("update_one_folder_with_index"), async () => {
3308+
test(suiteLabel("update_one_folder_with_index"), async () => {
33033309
const spaceChanges: ConfluenceSpaceChange[] = [
33043310
{
33053311
contentChangeType: ContentChangeType.create,
@@ -3332,7 +3338,7 @@ const runFlattenIndexes = () => {
33323338
version: null,
33333339
ancestors: [
33343340
{
3335-
id: "8781825",
3341+
id: "fake-space-id",
33363342
},
33373343
],
33383344
body: {
@@ -3351,8 +3357,7 @@ const runFlattenIndexes = () => {
33513357
spaceChanges,
33523358
FAKE_METADATA_ONE_FOLDER
33533359
);
3354-
console.log("actual", actual);
3355-
// assertEquals(expected, actual);
3360+
assertEquals(expected, actual);
33563361
});
33573362

33583363
test(suiteLabel("one_multinested_folder_with_indexes"), async () => {
@@ -3901,7 +3906,7 @@ const runUpdateLinks = () => {
39013906
check(expected, changes, fileMetadataTable, "fake-server", FAKE_PARENT);
39023907
});
39033908

3904-
otest(suiteLabel("one_update_link_nested_dot_slash"), async () => {
3909+
test(suiteLabel("one_update_link_nested_dot_slash"), async () => {
39053910
const changes: ConfluenceSpaceChange[] = [
39063911
UPDATE_LINKS_ONE_NESTED_DOT_SLASH,
39073912
];
@@ -4622,7 +4627,7 @@ const runFootnoteTransform = () => {
46224627
assertEquals(expected, footnoteTransform(value));
46234628
});
46244629

4625-
otest(suiteLabel("ignore_existing"), async () => {
4630+
test(suiteLabel("ignore_existing"), async () => {
46264631
const value =
46274632
'<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:local-id="a6aa6f25-0bee-4a7f-929b-71fcb7eba592" ac:macro-id="d2cb5be1217ae6e086bc60005e9d27b7"><ac:parameter ac:name="">fnref1</ac:parameter></ac:structured-macro><a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a></p>' +
46284633
'<section id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes">' +
@@ -4690,6 +4695,12 @@ const runFootnoteTransform = () => {
46904695
});
46914696
};
46924697

4698+
if (HIDE_NOISE) {
4699+
console.info(
4700+
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
4701+
);
4702+
}
4703+
46934704
if (RUN_ALL_TESTS) {
46944705
runGeneralTests();
46954706
runFilterFilesForUpdate();

0 commit comments

Comments
 (0)