Skip to content

Commit 8713dce

Browse files
author
Al Manning
committed
fix bug where titles arent uniqified on update
1 parent 9876934 commit 8713dce

File tree

3 files changed

+10
-27
lines changed

3 files changed

+10
-27
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,6 @@ export const updateLinks = (
503503
server: string,
504504
parent: ConfluenceParent
505505
): ConfluenceSpaceChange[] => {
506-
console.log("updateLinks");
507-
console.log("fileMetadataTable", fileMetadataTable);
508-
509506
const root = `${server}`;
510507
const url = `${ensureTrailingSlash(server)}wiki/spaces/${
511508
parent.space
@@ -514,12 +511,7 @@ export const updateLinks = (
514511
const changeMapper = (
515512
changeToProcess: ConfluenceSpaceChange
516513
): ConfluenceSpaceChange => {
517-
console.log("changeToProcess", changeToProcess);
518-
519514
const replacer = (match: string): string => {
520-
console.log("replacer");
521-
console.log("match", match);
522-
523515
let documentFileName = "";
524516
if (
525517
isContentUpdate(changeToProcess) ||
@@ -529,26 +521,23 @@ export const updateLinks = (
529521
}
530522

531523
const docFileNamePathList = documentFileName.split("/");
532-
console.log("docFileNamePathList", docFileNamePathList);
533524

534525
let updated: string = match;
535526
const linkFileNameMatch = FILE_FINDER.exec(match);
536-
console.log("linkFileNameMatch", linkFileNameMatch);
527+
537528
const linkFileName = linkFileNameMatch ? linkFileNameMatch[0] ?? "" : "";
538-
console.log("fileName", linkFileName);
529+
539530
const fileNamePathList = linkFileName.split("/");
540-
console.log("fileNamePathList", fileNamePathList);
541531

542532
const linkFullFileName = `${linkFileName}.qmd`;
543-
console.log("linkFullFileName", linkFullFileName);
544533

545534
let siteFilePath = linkFullFileName;
546535
const isAbsolute = siteFilePath.startsWith("/");
547536
if (!isAbsolute && docFileNamePathList.length > 1) {
548537
const relativePath = docFileNamePathList
549538
.slice(0, docFileNamePathList.length - 1)
550539
.join("/");
551-
console.log("relativePath", relativePath);
540+
552541
if (siteFilePath.startsWith("./")) {
553542
siteFilePath = siteFilePath.replace("./", `${relativePath}/`);
554543
} else {
@@ -560,36 +549,31 @@ export const updateLinks = (
560549
siteFilePath = siteFilePath.slice(1); //remove '/'
561550
}
562551

563-
console.log("siteFilePath", siteFilePath);
564-
565552
const sitePage: SitePage | null = fileMetadataTable[siteFilePath] ?? null;
566553

567-
console.log("sitePage", sitePage);
568-
569554
if (sitePage) {
570555
updated = match.replace('href="', `href="${url}`);
571556
const pagePath: string = `${url}${sitePage.id}/${encodeURI(
572557
sitePage.title ?? ""
573558
)}`;
574559

575560
updated = updated.replace(linkFullFileName, pagePath);
576-
console.log("updated", updated);
577561
} else {
578-
console.warn("no site page found");
562+
console.warn(`Link not found for ${siteFilePath}`);
579563
}
580564

581565
return updated;
582566
};
583567

584568
if (isContentUpdate(changeToProcess) || isContentCreate(changeToProcess)) {
585569
const valueToProcess = changeToProcess?.body?.storage?.value;
586-
console.log("valueToProcess", valueToProcess);
570+
587571
if (valueToProcess) {
588572
const replacedLinks: string = valueToProcess.replaceAll(
589573
LINK_FINDER,
590574
replacer
591575
);
592-
console.log("replacedLinks", replacedLinks);
576+
593577
changeToProcess.body.storage.value = replacedLinks;
594578
}
595579
}

src/publish/confluence/confluence.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ async function publish(
350350
publishFiles: PublishFiles,
351351
id: string,
352352
body: ContentBody,
353-
titleParam: string = title,
353+
titleToUpdate: string = title,
354354
fileName: string = ""
355355
): Promise<Content> => {
356356
const previousPage = await client.getContent(id);
@@ -360,14 +360,16 @@ async function publish(
360360
publishFiles.files
361361
);
362362

363+
const uniqueTitle = await uniquifyTitle(titleToUpdate);
364+
363365
trace("attachmentsToUpload", attachmentsToUpload, LogPrefix.ATTACHMENT);
364366

365367
const updatedBody: ContentBody = updateImagePaths(body);
366368
const toUpdate: ContentUpdate = {
367369
contentChangeType: ContentChangeType.update,
368370
id,
369371
version: getNextVersion(previousPage),
370-
title: `${titleParam}`,
372+
title: uniqueTitle,
371373
type: PAGE_TYPE,
372374
status: ContentStatusEnum.current,
373375
ancestors: null,
@@ -638,8 +640,6 @@ async function publish(
638640

639641
trace("changelist", changeList);
640642

641-
console.log("changeList", changeList);
642-
643643
let pathsToId: Record<string, string> = {}; // build from existing site
644644

645645
const doChange = async (change: ConfluenceSpaceChange) => {

tests/unit/confluence.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2767,7 +2767,6 @@ const runUpdateLinks = () => {
27672767
parent = FAKE_PARENT
27682768
) => {
27692769
const result = updateLinks(fileMetadataTable, changes, server, parent);
2770-
console.log("result", result);
27712770
assertEquals(expected, result);
27722771
};
27732772

0 commit comments

Comments
 (0)