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
unify API for creating note links
zadamd467db222784
diff --git a/src/public/javascripts/dialogs/recent_changes.js b/src/public/javascripts/dialogs/recent_changes.jsindex af2a94bd47..703cb145f2 100644--- a/src/public/javascripts/dialogs/recent_changes.js+++ b/src/public/javascripts/dialogs/recent_changes.js@@ -44,7 +44,10 @@ export async function showDialog() {const note = await treeCache.getNote(change.noteId);const notePath = await treeService.getSomeNotePath(note);- noteLink = await linkService.createNoteLinkWithPath(notePath, change.title);+ noteLink = await linkService.createNoteLink(notePath, {+ title: change.title,+ showNotePath: true+ });}changesListEl.append($('<li>')diff --git a/src/public/javascripts/services/link.js b/src/public/javascripts/services/link.jsindex dcf210d5d6..c1f74bf9a1 100644--- a/src/public/javascripts/services/link.js+++ b/src/public/javascripts/services/link.js@@ -9,7 +9,11 @@ function getNotePathFromUrl(url) {return notePathMatch === null ? null : notePathMatch[1];}-async function createNoteLink(notePath, noteTitle = null, tooltip = true) {+async function createNoteLink(notePath, options = {}) {+ let noteTitle = options.title;+ const showTooltip = options.showTooltip === undefined ? true : options.showTooltip;+ const showNotePath = options.showNotePath === undefined ? false : options.showNotePath;+if (!noteTitle) {const {noteId, parentNoteId} = treeUtils.getNoteIdAndParentIdFromNotePath(notePath);@@ -22,30 +26,26 @@ async function createNoteLink(notePath, noteTitle = null, tooltip = true) {}).attr('data-action', 'note').attr('data-note-path', notePath);- if (!tooltip) {+ if (!showTooltip) {$noteLink.addClass("no-tooltip-preview");}- return $noteLink;-}--async function createNoteLinkWithPath(notePath, noteTitle = null) {- const $link = await createNoteLink(notePath, noteTitle);+ const $container = $("<span>").append($noteLink);- const $res = $("<span>").append($link);+ if (showNotePath) {+ notePath = await treeService.resolveNotePath(notePath);- if (notePath.includes("/")) {const noteIds = notePath.split("/");noteIds.pop(); // remove last elementconst parentNotePath = noteIds.join("/").trim();if (parentNotePath) {- $res.append($("<small>").text(" (" + await treeUtils.getNotePathTitle(parentNotePath) + ")"));+ $container.append($("<small>").text(" (" + await treeUtils.getNotePathTitle(parentNotePath) + ")"));}}- return $res;+ return $container;}function getNotePathFromLink($link) {@@ -180,7 +180,6 @@ $(document).on('contextmenu', ".note-detail-render a", newTabContextMenu);export default {getNotePathFromUrl,createNoteLink,- createNoteLinkWithPath,addLinkToEditor,addTextToEditor,goToLinkdiff --git a/src/public/javascripts/services/link_map.js b/src/public/javascripts/services/link_map.jsindex 967415a97d..37bc0c77f6 100644--- a/src/public/javascripts/services/link_map.js+++ b/src/public/javascripts/services/link_map.js@@ -88,7 +88,7 @@ export default class LinkMap {.addClass("note-box").prop("id", noteBoxId);- linkService.createNoteLink(noteId, note.title).then($link => {+ linkService.createNoteLink(noteId, {title: note.title}).then($link => {$link.on('click', e => {try {$link.tooltip('dispose');diff --git a/src/public/javascripts/services/note_detail_book.js b/src/public/javascripts/services/note_detail_book.jsindex 09ed86bf5b..f2bbd8e5e8 100644--- a/src/public/javascripts/services/note_detail_book.js+++ b/src/public/javascripts/services/note_detail_book.js@@ -137,7 +137,7 @@ class NoteDetailBook {.attr('data-note-id', childNote.noteId).css("flex-basis", ZOOMS[this.zoomLevel].width).addClass("type-" + type)- .append($('<h5 class="note-book-title">').append(await linkService.createNoteLink(childNotePath, null, false)))+ .append($('<h5 class="note-book-title">').append(await linkService.createNoteLink(childNotePath, {showTooltip: false}))).append($('<div class="note-book-content">').css("max-height", ZOOMS[this.zoomLevel].height).append(await this.getNoteContent(type, childNote)));diff --git a/src/public/javascripts/services/note_detail_relation_map.js b/src/public/javascripts/services/note_detail_relation_map.jsindex 45feb0d921..c46ffde32b 100644--- a/src/public/javascripts/services/note_detail_relation_map.js+++ b/src/public/javascripts/services/note_detail_relation_map.js@@ -494,7 +494,7 @@ class NoteDetailRelationMap {}async createNoteBox(noteId, title, x, y) {- const $link = await linkService.createNoteLink(noteId, title);+ const $link = await linkService.createNoteLink(noteId, {title});$link.mousedown(e => {console.log(e);diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.jsindex f5f5125db2..86aa65fa9e 100644--- a/src/public/javascripts/services/tab_context.js+++ b/src/public/javascripts/services/tab_context.js@@ -379,7 +379,7 @@ class TabContext {async addPath(notePath, isCurrent) {const title = await treeUtils.getNotePathTitle(notePath);- const noteLink = await linkService.createNoteLink(notePath, title);+ const noteLink = await linkService.createNoteLink(notePath, {title});noteLink.addClass("no-tooltip-preview")diff --git a/src/public/javascripts/widgets/edited_notes.js b/src/public/javascripts/widgets/edited_notes.jsindex ee7dbe793b..01ebf07b1a 100644--- a/src/public/javascripts/widgets/edited_notes.js+++ b/src/public/javascripts/widgets/edited_notes.js@@ -45,7 +45,7 @@ class EditedNotesWidget extends StandardWidget {$item.append($("<i>").text(editedNote.title + " (deleted)"));}else {- $item.append(editedNote.notePath ? await linkService.createNoteLinkWithPath(editedNote.notePath.join("/")) : editedNote.title);+ $item.append(editedNote.notePath ? await linkService.createNoteLink(editedNote.notePath.join("/"), {showNotePath: true}) : editedNote.title);}$list.append($item);diff --git a/src/public/javascripts/widgets/similar_notes.js b/src/public/javascripts/widgets/similar_notes.jsindex e4e3380329..21e6d2b41f 100644--- a/src/public/javascripts/widgets/similar_notes.js+++ b/src/public/javascripts/widgets/similar_notes.js@@ -39,7 +39,7 @@ class SimilarNotesWidget extends StandardWidget {}const $item = $("<li>")- .append(await linkService.createNoteLinkWithPath(similarNote.notePath.join("/")));+ .append(await linkService.createNoteLink(similarNote.notePath.join("/"), {showNotePath: true}));$list.append($item);}