Skip to content

Commit c372b0a

Browse files
author
Al Manning
committed
link replace only to ids not titles
1 parent c288453 commit c372b0a

File tree

4 files changed

+87
-20
lines changed

4 files changed

+87
-20
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,7 @@ export const updateLinks = (
606606

607607
if (sitePage) {
608608
updated = match.replace('href="', `href="${url}`);
609-
const pagePath: string = `${url}${sitePage.id}/${encodeURI(
610-
sitePage.title ?? ""
611-
)}`;
612-
609+
const pagePath: string = `${url}${sitePage.id}`;
613610
updated = updated.replace(linkFullFileName, pagePath);
614611
} else {
615612
if (!collectedPass2Changes.includes(changeToProcess)) {

src/publish/confluence/confluence.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ import {
8080
verifyConfluenceParent,
8181
verifyLocation,
8282
} from "./confluence-verify.ts";
83-
import { DELETE_DISABLED, DELETE_SLEEP_MILLIS } from "./constants.ts";
83+
import {
84+
DELETE_DISABLED,
85+
DELETE_SLEEP_MILLIS,
86+
EXIT_ON_ERROR,
87+
} from "./constants.ts";
8488
import { logError, trace } from "./confluence-logger.ts";
8589
import { md5Hash } from "../../core/hash.ts";
8690
import { sleep } from "../../core/async.ts";
@@ -709,7 +713,18 @@ async function publish(
709713
};
710714

711715
for (let currentChange of changeList) {
712-
await doChange(currentChange);
716+
try {
717+
await doChange(currentChange);
718+
} catch (error: any) {
719+
console.info("Error Performing Change Pass 1", currentChange);
720+
if (isContentUpdate(currentChange) || isContentCreate(currentChange)) {
721+
console.info("Value to Update", currentChange.body.storage.value);
722+
}
723+
console.error(error);
724+
if (EXIT_ON_ERROR) {
725+
throw error;
726+
}
727+
}
713728
}
714729

715730
if (pass2Changes.length) {
@@ -728,7 +743,22 @@ async function publish(
728743
);
729744

730745
for (let currentChange of linkUpdateChanges) {
731-
await doChange(currentChange, false);
746+
try {
747+
await doChange(currentChange, false);
748+
} catch (error: any) {
749+
//TODO remove duplication
750+
console.info("Error Performing Change Pass 2", currentChange);
751+
if (
752+
isContentUpdate(currentChange) ||
753+
isContentCreate(currentChange)
754+
) {
755+
console.info("Value to Update", currentChange.body.storage.value);
756+
}
757+
console.error(error);
758+
if (EXIT_ON_ERROR) {
759+
throw error;
760+
}
761+
}
732762
}
733763
}
734764

src/publish/confluence/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export const DELETE_DISABLED = false;
22

3+
export const EXIT_ON_ERROR = true;
4+
35
export const DESCENDANT_LIMIT = 500; // Render time would be the big worry here, we can consider paging in the future
46

57
export const V2EDITOR_METADATA = {

tests/unit/confluence.test.ts

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,6 +3232,11 @@ const runUpdateLinks = () => {
32323232
id: "43417628",
32333233
metadata: { editor: "v2", fileName: "authoring/hello-world5.xml" },
32343234
},
3235+
["special-characters.qmd"]: {
3236+
title: "Special Characters !@#$%^&*(){}|?//\\",
3237+
id: "123456",
3238+
metadata: { fileName: "special-characters.xml" },
3239+
},
32353240
};
32363241

32373242
const UPDATE_NO_LINKS: ContentUpdate = {
@@ -3269,6 +3274,23 @@ const runUpdateLinks = () => {
32693274
fileName: "release-planning.xml",
32703275
};
32713276

3277+
const UPDATE_LINKS_SPECIAL_CHAR: ContentUpdate = {
3278+
contentChangeType: ContentChangeType.update,
3279+
id: "19890228",
3280+
version: null,
3281+
title: "Release Planning",
3282+
type: "page",
3283+
status: "current",
3284+
ancestors: [{ id: "19759105" }],
3285+
body: {
3286+
storage: {
3287+
value: "<a href='special-characters.qmd'>team</a>",
3288+
representation: "storage",
3289+
},
3290+
},
3291+
fileName: "release-planning.xml",
3292+
};
3293+
32723294
const UPDATE_LINKS_ONE_NESTED_DOT_SLASH: ContentUpdate = {
32733295
contentChangeType: ContentChangeType.update,
32743296
id: "43778049",
@@ -3394,7 +3416,7 @@ const runUpdateLinks = () => {
33943416
...UPDATE_LINKS_ONE,
33953417
body: {
33963418
storage: {
3397-
value: `<a href=\'no-replace.qmd\'/>no</a> content content <a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/19857455/Team\'>team</a> content content <a href=\'zqmdzz.qmd\'>team</a>`,
3419+
value: `<a href=\'no-replace.qmd\'/>no</a> content content <a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/19857455'>team</a> content content <a href=\'zqmdzz.qmd\'>team</a>`,
33983420
representation: "storage",
33993421
},
34003422
},
@@ -3411,7 +3433,23 @@ const runUpdateLinks = () => {
34113433
);
34123434
});
34133435

3414-
test(suiteLabel("one_update_link_nested_dot_slash"), async () => {
3436+
test(suiteLabel("one_update_link_special_char"), async () => {
3437+
const changes: ConfluenceSpaceChange[] = [UPDATE_LINKS_SPECIAL_CHAR];
3438+
const rootURL = "fake-server/wiki/spaces/QUARTOCONF/pages";
3439+
const expectedUpdate: ContentUpdate = {
3440+
...UPDATE_LINKS_ONE,
3441+
body: {
3442+
storage: {
3443+
value: `<a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/123456'>team</a>`,
3444+
representation: "storage",
3445+
},
3446+
},
3447+
};
3448+
const expected: ConfluenceSpaceChange[] = [expectedUpdate];
3449+
check(expected, changes, fileMetadataTable, "fake-server", FAKE_PARENT);
3450+
});
3451+
3452+
otest(suiteLabel("one_update_link_nested_dot_slash"), async () => {
34153453
const changes: ConfluenceSpaceChange[] = [
34163454
UPDATE_LINKS_ONE_NESTED_DOT_SLASH,
34173455
];
@@ -3420,7 +3458,7 @@ const runUpdateLinks = () => {
34203458
...UPDATE_LINKS_ONE_NESTED_DOT_SLASH,
34213459
body: {
34223460
storage: {
3423-
value: `<a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/43417628/Hello%20World5\'>Hello World 5</a>`,
3461+
value: `<a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/43417628'>Hello World 5</a>`,
34243462
representation: "storage",
34253463
},
34263464
},
@@ -3436,7 +3474,7 @@ const runUpdateLinks = () => {
34363474
...UPDATE_LINKS_ONE_NESTED,
34373475
body: {
34383476
storage: {
3439-
value: `<a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/43417628/Hello%20World5\'>Hello World 5</a>`,
3477+
value: `<a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/43417628'>Hello World 5</a>`,
34403478
representation: "storage",
34413479
},
34423480
},
@@ -3452,7 +3490,7 @@ const runUpdateLinks = () => {
34523490
...UPDATE_LINKS_ONE_NESTED_ABS,
34533491
body: {
34543492
storage: {
3455-
value: `<a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/19890228/Release%20Planning\'>Release Planning</a>`,
3493+
value: `<a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/19890228'>Release Planning</a>`,
34563494
representation: "storage",
34573495
},
34583496
},
@@ -3469,7 +3507,7 @@ const runUpdateLinks = () => {
34693507
body: {
34703508
storage: {
34713509
value:
3472-
"<a href='no-replace.qmd'/>no</a> content content <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19857455/Team#Fake-Anchor'>team</a> content content <a href='zqmdzz.qmd'>team</a>",
3510+
"<a href='no-replace.qmd'/>no</a> content content <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19857455#Fake-Anchor'>team</a> content content <a href='zqmdzz.qmd'>team</a>",
34733511
representation: "storage",
34743512
},
34753513
},
@@ -3493,7 +3531,7 @@ const runUpdateLinks = () => {
34933531
...UPDATE_LINKS_ONE,
34943532
body: {
34953533
storage: {
3496-
value: `<a href='no-replace.qmd'/>not-found</a> content content <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19857455/Team'>teamz</a> content content <a href='zqmdzz.qmd'>not-found</a> <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19890228/Release%20Planning'>Do the Release Planning</a> and then triage.qmd .qmd <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19890180/Issue%20Triage'>triage.qmd</a>`,
3534+
value: `<a href='no-replace.qmd'/>not-found</a> content content <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19857455'>teamz</a> content content <a href='zqmdzz.qmd'>not-found</a> <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19890228'>Do the Release Planning</a> and then triage.qmd .qmd <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19890180'>triage.qmd</a>`,
34973535
representation: "storage",
34983536
},
34993537
},
@@ -3520,7 +3558,7 @@ const runUpdateLinks = () => {
35203558
...UPDATE_LINKS_ONE,
35213559
body: {
35223560
storage: {
3523-
value: `<a href='no-replace.qmd'/>not-found</a> content content <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19857455/Team'>teamz</a> content content <a href='zqmdzz.qmd'>not-found</a> <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19890228/Release%20Planning'>Do the Release Planning</a> and then triage.qmd .qmd <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19890180/Issue%20Triage'>triage.qmd</a>`,
3561+
value: `<a href='no-replace.qmd'/>not-found</a> content content <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19857455'>teamz</a> content content <a href='zqmdzz.qmd'>not-found</a> <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19890228'>Do the Release Planning</a> and then triage.qmd .qmd <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19890180'>triage.qmd</a>`,
35243562
representation: "storage",
35253563
},
35263564
},
@@ -3530,7 +3568,7 @@ const runUpdateLinks = () => {
35303568
...UPDATE_LINKS_ONE,
35313569
body: {
35323570
storage: {
3533-
value: `<a href='no-replace.qmd'/>no</a> content content <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19857455/Team'>team</a> content content <a href='zqmdzz.qmd'>team</a>`,
3571+
value: `<a href='no-replace.qmd'/>no</a> content content <a href='fake-server/wiki/spaces/QUARTOCONF/pages/19857455'>team</a> content content <a href='zqmdzz.qmd'>team</a>`,
35343572
representation: "storage",
35353573
},
35363574
},
@@ -3800,7 +3838,7 @@ const runConvertForSecondPass = () => {
38003838
...UPDATE_LINKS_ONE,
38013839
body: {
38023840
storage: {
3803-
value: `<a href=\'no-replace.qmd\'/>no</a> content content <a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/19857455/Team\'>team</a> content content <a href=\'zqmdzz.qmd\'>team</a>`,
3841+
value: `<a href=\'no-replace.qmd\'/>no</a> content content <a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/19857455'>team</a> content content <a href=\'zqmdzz.qmd\'>team</a>`,
38043842
representation: "storage",
38053843
},
38063844
},
@@ -3816,7 +3854,7 @@ const runConvertForSecondPass = () => {
38163854
...UPDATE_LINKS_ONE,
38173855
body: {
38183856
storage: {
3819-
value: `<a href=\'no-replace.qmd\'/>no</a> content content <a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/19857456/TeamTest\'>team</a> content content <a href=\'zqmdzz.qmd\'>team</a>`,
3857+
value: `<a href=\'no-replace.qmd\'/>no</a> content content <a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/19857456'>team</a> content content <a href=\'zqmdzz.qmd\'>team</a>`,
38203858
representation: "storage",
38213859
},
38223860
},
@@ -3832,7 +3870,7 @@ const runConvertForSecondPass = () => {
38323870
...UPDATE_LINKS_ONE,
38333871
body: {
38343872
storage: {
3835-
value: `<a href=\'no-replace.qmd\'/>no</a> content content <a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/19857455/Team\'>team</a> content content <a href=\'zqmdzz.qmd\'>team</a>`,
3873+
value: `<a href=\'no-replace.qmd\'/>no</a> content content <a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/19857455'>team</a> content content <a href=\'zqmdzz.qmd\'>team</a>`,
38363874
representation: "storage",
38373875
},
38383876
},
@@ -4133,5 +4171,5 @@ if (RUN_ALL_TESTS) {
41334171
runUpdateImagePathsForContentBody();
41344172
runCapFirstLetter();
41354173
} else {
4136-
runConvertForSecondPass();
4174+
runUpdateLinks();
41374175
}

0 commit comments

Comments
 (0)