diff --git a/src/public/javascripts/services/link.js b/src/public/javascripts/services/link.js index 20a904812..6f4cb77cb 100644 --- a/src/public/javascripts/services/link.js +++ b/src/public/javascripts/services/link.js @@ -30,6 +30,25 @@ async function createNoteLink(notePath, noteTitle = null) { return noteLink; } +async function createNoteLinkWithPath(notePath) { + const $link = await createNoteLink(notePath); + + const $res = $("").append($link); + + if (notePath.includes("/")) { + const noteIds = notePath.split("/"); + noteIds.pop(); // remove last element + + const parentNotePath = noteIds.join("/").trim(); + + if (parentNotePath) { + $res.append($("").text(" (" + await treeUtils.getNotePathTitle(parentNotePath) + ")")); + } + } + + return $res; +} + function getNotePathFromLink($link) { const notePathAttr = $link.attr("data-note-path"); @@ -159,6 +178,7 @@ $(document).on('mousedown', 'span.ck-button__label', e => { export default { getNotePathFromUrl, createNoteLink, + createNoteLinkWithPath, addLinkToEditor, addTextToEditor, goToLink diff --git a/src/public/javascripts/widgets/similar_notes.js b/src/public/javascripts/widgets/similar_notes.js index b0cf4e4f1..d56d714c2 100644 --- a/src/public/javascripts/widgets/similar_notes.js +++ b/src/public/javascripts/widgets/similar_notes.js @@ -3,6 +3,7 @@ import linkService from "../services/link.js"; import server from "../services/server.js"; import treeCache from "../services/tree_cache.js"; import treeUtils from "../services/tree_utils.js"; +import treeService from "../services/tree.js"; class SimilarNotesWidget extends StandardWidget { getWidgetTitle() { return "Similar notes"; } @@ -19,18 +20,20 @@ class SimilarNotesWidget extends StandardWidget { await treeCache.getNotes(similarNotes.map(note => note.noteId)); // preload all at once - const $list = $('