mirror of
https://github.com/zadam/trilium.git
synced 2026-01-18 04:24:23 +01:00
chore(client-standalone): integrate note map backlink count
This commit is contained in:
parent
91db73703b
commit
13f25e9fed
@ -341,6 +341,7 @@ export function findExcerpts(sourceNote: BNote, referencedNoteId: string) {
|
||||
return excerpts;
|
||||
}
|
||||
|
||||
// TODO: Deduplicate with core
|
||||
function 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
|
||||
};
|
||||
|
||||
@ -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);
|
||||
|
||||
28
packages/trilium-core/src/routes/api/note_map.ts
Normal file
28
packages/trilium-core/src/routes/api/note_map.ts
Normal file
@ -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
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user