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
Allow external link notes in share tree
Zack Rauen7729aad1e950
diff --git a/src/share/content_renderer.js b/src/share/content_renderer.jsindex 8c1dbee10e..1870f039b4 100644--- a/src/share/content_renderer.js+++ b/src/share/content_renderer.js@@ -44,8 +44,10 @@ function renderIndex(result) {const rootNote = shaca.getNote(shareRoot.SHARE_ROOT_NOTE_ID);for (const childNote of rootNote.getChildNotes()) {- const href = childNote.getLabelValue("shareExternal") ?? `./${childNote.shareId}`;- result.content += `<li><a class="${childNote.type}" href="${href}">${childNote.escapedTitle}</a></li>`;+ const isExternalLink = childNote.hasLabel("shareExternalLink");+ const href = isExternalLink ? childNote.getLabelValue("shareExternalLink") : `./${childNote.shareId}`;+ const target = isExternalLink ? `target="_blank" rel="noopener noreferrer"` : "";+ result.content += `<li><a class="${childNote.type}" href="${href}" ${target}>${childNote.escapedTitle}</a></li>`;}result.content += '</ul>';@@ -85,8 +87,13 @@ function renderText(result, note) {const noteId = notePathSegments[notePathSegments.length - 1];const linkedNote = shaca.getNote(noteId);if (linkedNote) {- const href = linkedNote.getLabelValue("shareExternal") ?? `./${linkedNote.shareId}`;+ const isExternalLink = linkedNote.hasLabel("shareExternalLink");+ const href = isExternalLink ? linkedNote.getLabelValue("shareExternalLink") : `./${linkedNote.shareId}`;linkEl.setAttribute("href", href);+ if (isExternalLink) {+ linkEl.setAttribute("target", "_blank");+ linkEl.setAttribute("rel", "noopener noreferrer");+ }linkEl.classList.add(`type-${linkedNote.type}`);} else {linkEl.removeAttribute("href");diff --git a/src/views/share/page.ejs b/src/views/share/page.ejsindex 52e891dbcf..9d95a155a7 100644--- a/src/views/share/page.ejs+++ b/src/views/share/page.ejs@@ -32,7 +32,7 @@<%- header %><title><%= note.title %></title></head>-<body data-note-id="<%= note.noteId %>">+<body data-note-id="<%= note.noteId %>" data-wtf="true"><div id="layout"><div id="main"><% if (note.parents[0].noteId !== '_share' && note.parents.length !== 0) { %>@@ -62,9 +62,14 @@<% } %><ul>- <% for (const childNote of note.getVisibleChildNotes()) { %>+ <%+ for (const childNote of note.getVisibleChildNotes()) {+ const isExternalLink = childNote.hasLabel('shareExternalLink');+ const linkHref = isExternalLink ? childNote.getLabelValue('shareExternalLink') : `./${childNote.shareId}`;+ const target = isExternalLink ? `target="_blank" rel="noopener noreferrer"` : '';+ %><li>- <a href="<%= childNote.shareId %>"+ <a href="<%= linkHref %>" <%= target %>class="type-<%= childNote.type %>"><%= childNote.title %></a></li><% } %>diff --git a/src/views/share/tree_item.ejs b/src/views/share/tree_item.ejsindex 12eec3fbb9..f139be8acd 100644--- a/src/views/share/tree_item.ejs+++ b/src/views/share/tree_item.ejs@@ -1,10 +1,16 @@+<%+const isExternalLink = note.hasLabel('shareExternalLink');+const linkHref = isExternalLink ? note.getLabelValue('shareExternalLink') : `./${note.shareId}`;+const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : '';+console.log(note.shareId, note.title, isExternalLink, linkHref, target);+%><p><% const titleWithPrefix = (branch.prefix ? `${branch.prefix} - ` : '') + note.title; %><% if (activeNote.noteId === note.noteId) { %><strong><%= titleWithPrefix %></strong><% } else { %>- <a class="type-<%= note.type %>" href="./<%= note.shareId %>"><%= titleWithPrefix %></a>+ <a class="type-<%= note.type %>" href="<%= linkHref %>"<%= target %>><%= titleWithPrefix %></a><% } %></p>