Skip to content

Commit 41db022

Browse files
author
Allen Manning
authored
Merge pull request #4726 from quarto-dev/bug/index-root
Index flattening isn't working for root page. #4725
2 parents c628af5 + f0f808a commit 41db022

File tree

3 files changed

+81
-9
lines changed

3 files changed

+81
-9
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ export const buildSpaceChanges = (
464464

465465
export const flattenIndexes = (
466466
changes: ConfluenceSpaceChange[],
467-
metadataByFileName: Record<string, SitePage>
467+
metadataByFileName: Record<string, SitePage>,
468+
siteParentId: string
468469
): ConfluenceSpaceChange[] => {
469470
const getFileNameForChange = (change: ConfluenceSpaceChange) => {
470471
if (isContentDelete(change)) {
@@ -513,6 +514,17 @@ export const flattenIndexes = (
513514
}
514515

515516
const fileName = getFileNameForChange(change);
517+
518+
if (fileName === "index.xml") {
519+
const rootUpdate = buildContentUpdate(
520+
siteParentId,
521+
change.title,
522+
change.body,
523+
"index.xml"
524+
);
525+
return [...accumulator, rootUpdate];
526+
}
527+
516528
const parentFileName = fileName.replace("/index.xml", "");
517529
const parentSitePage: SitePage = metadataByFileName[parentFileName];
518530
if (isIndexFile(change)) {

src/publish/confluence/confluence.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ async function publish(
676676
existingSite
677677
);
678678

679-
changeList = flattenIndexes(changeList, metadataByFilename);
679+
changeList = flattenIndexes(changeList, metadataByFilename, parentId);
680680

681681
const { pass1Changes, pass2Changes } = updateLinks(
682682
metadataByFilename,

tests/unit/confluence.test.ts

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import {
6363

6464
const RUN_ALL_TESTS = true;
6565
const FOCUS_TEST = false;
66-
const HIDE_NOISE = true;
66+
const HIDE_NOISE = false;
6767

6868
const xtest = (
6969
name: string,
@@ -3106,6 +3106,8 @@ const runSpaceUpdatesWithNestedMoves = () => {
31063106
const runFlattenIndexes = () => {
31073107
const suiteLabel = (label: string) => `FlattenIndexes_${label}`;
31083108

3109+
const FAKE_SITE_PARENT_ID = "fake-site-parent-id";
3110+
31093111
const FAKE_METADATA_ONE_FOLDER = {
31103112
["fake-parent"]: {
31113113
title: "Fake Parent Title",
@@ -3128,7 +3130,8 @@ const runFlattenIndexes = () => {
31283130
const expected: ConfluenceSpaceChange[] = [];
31293131
const actual: ConfluenceSpaceChange[] = flattenIndexes(
31303132
spaceChanges,
3131-
FAKE_METADATA_EMPTY
3133+
FAKE_METADATA_EMPTY,
3134+
FAKE_SITE_PARENT_ID
31323135
);
31333136
assertEquals(expected, actual);
31343137
});
@@ -3162,7 +3165,8 @@ const runFlattenIndexes = () => {
31623165
const expected: ConfluenceSpaceChange[] = spaceChanges;
31633166
const actual: ConfluenceSpaceChange[] = flattenIndexes(
31643167
spaceChanges,
3165-
FAKE_METADATA_EMPTY
3168+
FAKE_METADATA_EMPTY,
3169+
FAKE_SITE_PARENT_ID
31663170
);
31673171
assertEquals(expected, actual);
31683172
});
@@ -3219,7 +3223,8 @@ const runFlattenIndexes = () => {
32193223
const expected: ConfluenceSpaceChange[] = spaceChanges;
32203224
const actual: ConfluenceSpaceChange[] = flattenIndexes(
32213225
spaceChanges,
3222-
FAKE_METADATA_EMPTY
3226+
FAKE_METADATA_EMPTY,
3227+
FAKE_SITE_PARENT_ID
32233228
);
32243229
assertEquals(expected, actual);
32253230
});
@@ -3300,7 +3305,60 @@ const runFlattenIndexes = () => {
33003305
];
33013306
const actual: ConfluenceSpaceChange[] = flattenIndexes(
33023307
spaceChanges,
3303-
FAKE_METADATA_EMPTY
3308+
FAKE_METADATA_EMPTY,
3309+
FAKE_SITE_PARENT_ID
3310+
);
3311+
assertEquals(expected, actual);
3312+
});
3313+
3314+
otest(suiteLabel("create_root_with_index"), async () => {
3315+
const spaceChanges: ConfluenceSpaceChange[] = [
3316+
{
3317+
contentChangeType: ContentChangeType.create,
3318+
ancestors: [
3319+
{
3320+
id: "8781825",
3321+
},
3322+
],
3323+
body: {
3324+
storage: {
3325+
representation: "storage",
3326+
value: "fake content root index",
3327+
},
3328+
},
3329+
fileName: "index.xml",
3330+
space: {
3331+
key: "fake-space-key",
3332+
id: "fake-space-id",
3333+
homepage: buildFakeContent(),
3334+
},
3335+
status: "current",
3336+
title: "Root Index",
3337+
type: "page",
3338+
},
3339+
];
3340+
const expected: ConfluenceSpaceChange[] = [
3341+
{
3342+
contentChangeType: ContentChangeType.update,
3343+
id: FAKE_SITE_PARENT_ID,
3344+
version: null,
3345+
ancestors: null,
3346+
body: {
3347+
storage: {
3348+
representation: "storage",
3349+
value: "fake content root index",
3350+
},
3351+
},
3352+
fileName: "index.xml",
3353+
status: "current",
3354+
title: "Root Index",
3355+
type: "page",
3356+
},
3357+
];
3358+
const actual: ConfluenceSpaceChange[] = flattenIndexes(
3359+
spaceChanges,
3360+
FAKE_METADATA_EMPTY,
3361+
FAKE_SITE_PARENT_ID
33043362
);
33053363
assertEquals(expected, actual);
33063364
});
@@ -3355,7 +3413,8 @@ const runFlattenIndexes = () => {
33553413
];
33563414
const actual: ConfluenceSpaceChange[] = flattenIndexes(
33573415
spaceChanges,
3358-
FAKE_METADATA_ONE_FOLDER
3416+
FAKE_METADATA_ONE_FOLDER,
3417+
FAKE_SITE_PARENT_ID
33593418
);
33603419
assertEquals(expected, actual);
33613420
});
@@ -3529,7 +3588,8 @@ const runFlattenIndexes = () => {
35293588
];
35303589
const actual: ConfluenceSpaceChange[] = flattenIndexes(
35313590
spaceChanges,
3532-
FAKE_METADATA_EMPTY
3591+
FAKE_METADATA_EMPTY,
3592+
FAKE_SITE_PARENT_ID
35333593
);
35343594
assertEquals(expected, actual);
35353595
});

0 commit comments

Comments
 (0)