Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(client-standalone): integrate note map backlink count
Elian Doran13f25e9fed6e
diff --git a/apps/server/src/routes/api/note_map.ts b/apps/server/src/routes/api/note_map.tsindex 473388af09..69d8f3bcfa 100644--- a/apps/server/src/routes/api/note_map.ts+++ b/apps/server/src/routes/api/note_map.ts@@ -341,6 +341,7 @@ export function findExcerpts(sourceNote: BNote, referencedNoteId: string) {return excerpts;}+// TODO: Deduplicate with corefunction getFilteredBacklinks(note: BNote): BAttribute[] {return (note@@ -350,16 +351,6 @@ function getFilteredBacklinks(note: BNote): BAttribute[] {);}-function getBacklinkCount(req: Request) {- const { noteId } = req.params;-- const note = becca.getNoteOrThrow(noteId);-- return {- count: getFilteredBacklinks(note).length- } satisfies BacklinkCountResponse;-}-function getBacklinks(req: Request): BacklinksResponse {const { noteId } = req.params;const note = becca.getNoteOrThrow(noteId);@@ -389,6 +380,5 @@ function getBacklinks(req: Request): BacklinksResponse {export default {getLinkMap,getTreeMap,- getBacklinkCount,getBacklinks};diff --git a/apps/server/src/routes/routes.ts b/apps/server/src/routes/routes.tsindex c9efb42f83..57f1e61bb0 100644--- a/apps/server/src/routes/routes.ts+++ b/apps/server/src/routes/routes.ts@@ -312,7 +312,6 @@ function register(app: express.Application) {apiRoute(PST, "/api/note-map/:noteId/tree", noteMapRoute.getTreeMap);apiRoute(PST, "/api/note-map/:noteId/link", noteMapRoute.getLinkMap);- apiRoute(GET, "/api/note-map/:noteId/backlink-count", noteMapRoute.getBacklinkCount);apiRoute(GET, "/api/note-map/:noteId/backlinks", noteMapRoute.getBacklinks);shareRoutes.register(router);diff --git a/packages/trilium-core/src/routes/api/note_map.ts b/packages/trilium-core/src/routes/api/note_map.tsnew file mode 100644index 0000000000..d42e989588--- /dev/null+++ b/packages/trilium-core/src/routes/api/note_map.ts@@ -0,0 +1,28 @@+import type { Request } from "express";+import BAttribute from "../../becca/entities/battribute";+import BNote from "../../becca/entities/bnote";+import becca from "../../becca/becca";+import type { BacklinkCountResponse } from "@triliumnext/commons";++function getFilteredBacklinks(note: BNote): BAttribute[] {+ return (+ note+ .getTargetRelations()+ // search notes have "ancestor" relations which are not interesting+ .filter((relation) => !!relation.getNote() && relation.getNote().type !== "search")+ );+}++function getBacklinkCount(req: Request) {+ const { noteId } = req.params;++ const note = becca.getNoteOrThrow(noteId);++ return {+ count: getFilteredBacklinks(note).length+ } satisfies BacklinkCountResponse;+}++export default {+ getBacklinkCount+}diff --git a/packages/trilium-core/src/routes/index.ts b/packages/trilium-core/src/routes/index.tsindex 0d0b11cff0..bff4a3eafc 100644--- a/packages/trilium-core/src/routes/index.ts+++ b/packages/trilium-core/src/routes/index.ts@@ -3,6 +3,7 @@ import treeApiRoute from "./api/tree";import keysApiRoute from "./api/keys";import notesApiRoute from "./api/notes";import attachmentsApiRoute from "./api/attachments";+import noteMapRoute from "./api/note_map";import AbstractBeccaEntity from "../becca/entities/abstract_becca_entity";// TODO: Deduplicate with routes.ts@@ -50,6 +51,8 @@ export function buildSharedApiRoutes(apiRoute: any) {apiRoute(PUT, "/api/attachments/:attachmentId/rename", attachmentsApiRoute.renameAttachment);apiRoute(GET, "/api/attachments/:attachmentId/blob", attachmentsApiRoute.getAttachmentBlob);+ apiRoute(GET, "/api/note-map/:noteId/backlink-count", noteMapRoute.getBacklinkCount);+apiRoute(GET, "/api/keyboard-actions", keysApiRoute.getKeyboardActions);apiRoute(GET, "/api/keyboard-shortcuts-for-notes", keysApiRoute.getShortcutsForNotes);}