added shareAlias label

This commit is contained in:
zadam
2021-12-22 10:57:02 +01:00
parent bcef8579ce
commit c0964a4f12
10 changed files with 49 additions and 11 deletions

View File

@@ -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");
}
}
}

View File

@@ -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);

View File

@@ -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() {

View File

@@ -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;

View File

@@ -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 = [];

View File

@@ -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'))
)`, []);