diff --git a/apps/server/src/routes/api/note_map.spec.ts b/apps/server/src/routes/api/note_map.spec.ts index c3696fc3a..0ab5d1d2d 100644 --- a/apps/server/src/routes/api/note_map.spec.ts +++ b/apps/server/src/routes/api/note_map.spec.ts @@ -57,7 +57,7 @@ describe("Note map service", () => { { excerpts: [ trimIndentation`\ - ` ], noteId: "first", }, { excerpts: [ trimIndentation`\ - ` ], noteId: "second" } diff --git a/apps/server/src/routes/api/note_map.ts b/apps/server/src/routes/api/note_map.ts index 6547ad6b9..84161cacc 100644 --- a/apps/server/src/routes/api/note_map.ts +++ b/apps/server/src/routes/api/note_map.ts @@ -243,8 +243,8 @@ function updateDescendantCountMapForSearch(noteIdToDescendantCountMap: Record 0) { - images[0]?.parentNode?.removeChild(images[0]); + for (const image of images) { + image.remove(); } } @@ -257,9 +257,13 @@ export function findExcerpts(sourceNote: BNote, referencedNoteId: string) { const excerpts: string[] = []; + console.log("Removing images") removeImages(document); + console.log("Querying links"); + for (const linkEl of document.querySelectorAll("a")) { + console.log("Got ", linkEl.innerHTML); const href = linkEl.getAttribute("href"); if (!href || !href.endsWith(referencedNoteId)) { @@ -271,6 +275,7 @@ export function findExcerpts(sourceNote: BNote, referencedNoteId: string) { let centerEl: HTMLElement = linkEl; while (centerEl.tagName !== "BODY" && centerEl.parentNode && (centerEl.parentNode?.textContent?.length || 0) <= EXCERPT_CHAR_LIMIT) { + console.log("Got ", centerEl.tagName, centerEl.parentNode); centerEl = centerEl.parentNode; } @@ -366,6 +371,7 @@ function getBacklinks(req: Request): BacklinksResponse { let backlinksWithExcerptCount = 0; return getFilteredBacklinks(note).map((backlink) => { + console.log("Processing ", backlink); const sourceNote = backlink.note; if (sourceNote.type !== "text" || backlinksWithExcerptCount > 50) {