mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 06:15:48 +01:00
added shareAlias label
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const {JSDOM} = require("jsdom");
|
||||
const NO_CONTENT = '<p>This note has no content.</p>';
|
||||
const shaca = require("./shaca/shaca");
|
||||
|
||||
function getChildrenList(note) {
|
||||
if (note.hasChildren()) {
|
||||
@@ -43,7 +44,15 @@ function getContent(note) {
|
||||
if (href?.startsWith("#")) {
|
||||
const notePathSegments = href.split("/");
|
||||
|
||||
linkEl.setAttribute("href", notePathSegments[notePathSegments.length - 1]);
|
||||
const noteId = notePathSegments[notePathSegments.length - 1];
|
||||
const linkedNote = shaca.getNote(noteId);
|
||||
|
||||
if (linkedNote) {
|
||||
linkEl.setAttribute("href", linkedNote.shareId);
|
||||
}
|
||||
else {
|
||||
linkEl.removeAttribute("href");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,14 +18,14 @@ function getSubRoot(note) {
|
||||
}
|
||||
|
||||
function register(router) {
|
||||
router.get('/share/:noteId', (req, res, next) => {
|
||||
const {noteId} = req.params;
|
||||
router.get('/share/:shareId', (req, res, next) => {
|
||||
const {shareId} = req.params;
|
||||
|
||||
shacaLoader.ensureLoad();
|
||||
|
||||
if (noteId in shaca.notes) {
|
||||
const note = shaca.notes[noteId];
|
||||
const note = shaca.aliasToNote[shareId] || shaca.notes[shareId];
|
||||
|
||||
if (note) {
|
||||
const content = contentRenderer.getContent(note);
|
||||
|
||||
const subRoot = getSubRoot(note);
|
||||
|
||||
@@ -39,6 +39,10 @@ class Attribute extends AbstractEntity {
|
||||
linkedChildNote.parents = linkedChildNote.parents.filter(parentNote => parentNote.noteId !== this.noteId);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.type === 'label' && this.name === 'shareAlias' && this.value.trim()) {
|
||||
this.shaca.aliasToNote[this.value.trim()] = this.note;
|
||||
}
|
||||
}
|
||||
|
||||
get isAffectingSubtree() {
|
||||
|
||||
@@ -549,6 +549,12 @@ class Note extends AbstractEntity {
|
||||
|
||||
return notePaths.some(path => path.includes(ancestorNoteId));
|
||||
}
|
||||
|
||||
get shareId() {
|
||||
const sharedAlias = this.getOwnedLabelValue("shareAlias");
|
||||
|
||||
return sharedAlias || this.noteId;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Note;
|
||||
|
||||
@@ -14,6 +14,8 @@ class Shaca {
|
||||
this.childParentToBranch = {};
|
||||
/** @type {Object.<String, Attribute>} */
|
||||
this.attributes = {};
|
||||
/** @type {Object.<String, String>} */
|
||||
this.aliasToNote = {};
|
||||
|
||||
this.loaded = false;
|
||||
}
|
||||
@@ -22,6 +24,10 @@ class Shaca {
|
||||
return this.notes[noteId];
|
||||
}
|
||||
|
||||
hasNote(noteId) {
|
||||
return noteId in this.notes;
|
||||
}
|
||||
|
||||
getNotes(noteIds, ignoreMissing = false) {
|
||||
const filteredNotes = [];
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ function load() {
|
||||
WHERE isDeleted = 0
|
||||
AND noteId IN (${noteIdStr})
|
||||
AND (
|
||||
(type = 'label' AND name IN ('archived', 'shareHiddenFromTree'))
|
||||
(type = 'label' AND name IN ('archived', 'shareHiddenFromTree', 'shareAlias'))
|
||||
OR (type = 'relation' AND name IN ('imageLink', 'template', 'shareCss'))
|
||||
)`, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user