A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
core: fix duplicate backlinks shown on note
Ammar Ahmed0a5f0d407ef0
diff --git a/packages/core/src/collections/notes.ts b/packages/core/src/collections/notes.tsindex ea9b61db0..67d187483 100644--- a/packages/core/src/collections/notes.ts+++ b/packages/core/src/collections/notes.ts@@ -400,6 +400,15 @@ export class Notes implements ICollection {.blocks;}+ async contentBlocksWithLinks(id: string) {+ const content = await this.db.content.findByNoteId(id);+ if (!content || content.locked) return [];++ return getContentFromData(content.type, content.data).extract(+ "linked-blocks"+ ).blocks;+ }+async internalLinks(id: string) {const content = await this.db.content.findByNoteId(id);if (!content || content.locked) return [];diff --git a/packages/core/src/content-types/tiptap.ts b/packages/core/src/content-types/tiptap.tsindex b0edc4a66..cd7d0cd27 100644--- a/packages/core/src/content-types/tiptap.ts+++ b/packages/core/src/content-types/tiptap.ts@@ -42,7 +42,7 @@ export type ResolveHashes = (hashes: string[]) => Promise<Record<string, string>>;-const ExtractableTypes = ["blocks", "internalLinks"] as const;+const ExtractableTypes = ["blocks", "internalLinks", "linked-blocks"] as const;type ExtractableType = (typeof ExtractableTypes)[number];type ExtractionResult = {blocks: ContentBlock[];@@ -150,6 +150,27 @@ export class Tiptap {withStartIndices: true});+ if (types.includes("linked-blocks")) {+ result.blocks.push(+ ...findAll((element): element is Element => {+ return isTag(element) && element.tagName === "a";+ }, document.childNodes).map((node) => {+ let parent = node.parent as Element;+ while (!(parent as Element).attribs[ATTRIBUTES.blockId]) {+ parent = parent?.parent as Element;+ }+ return {+ id: parent.attribs[ATTRIBUTES.blockId],+ type: parent.tagName.toLowerCase(),+ content: convertHtmlToTxt(+ this.data.slice(parent.startIndex || 0, parent.endIndex || 0),+ false+ )+ };+ })+ );+ }+if (types.includes("blocks")) {result.blocks.push(...findAll((element): element is Element => {