mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 14:25:51 +01:00
added #shareDisallowRobotIndexing label and reworked how the child-image exclusion works
This commit is contained in:
@@ -20,30 +20,39 @@ function getSharedSubTreeRoot(note) {
|
||||
return getSharedSubTreeRoot(parentNote);
|
||||
}
|
||||
|
||||
function addNoIndexHeader(note, res) {
|
||||
if (note.hasLabel('shareDisallowRobotIndexing')) {
|
||||
res.setHeader('X-Robots-Tag', 'noindex');
|
||||
}
|
||||
}
|
||||
|
||||
function register(router) {
|
||||
function renderNote(note, res) {
|
||||
if (note) {
|
||||
if (note.hasLabel('shareRaw')) {
|
||||
res.setHeader('Content-Type', note.mime);
|
||||
|
||||
res.send(note.getContent());
|
||||
return;
|
||||
}
|
||||
|
||||
const {header, content, isEmpty} = contentRenderer.getContent(note);
|
||||
|
||||
const subRoot = getSharedSubTreeRoot(note);
|
||||
|
||||
res.render("share/page", {
|
||||
note,
|
||||
header,
|
||||
content,
|
||||
isEmpty,
|
||||
subRoot
|
||||
});
|
||||
} else {
|
||||
if (!note) {
|
||||
res.status(404).render("share/404");
|
||||
return;
|
||||
}
|
||||
|
||||
addNoIndexHeader(note, res);
|
||||
|
||||
if (note.hasLabel('shareRaw') || ['image', 'file'].includes(note.type)) {
|
||||
res.setHeader('Content-Type', note.mime);
|
||||
|
||||
res.send(note.getContent());
|
||||
return;
|
||||
}
|
||||
|
||||
const {header, content, isEmpty} = contentRenderer.getContent(note);
|
||||
|
||||
const subRoot = getSharedSubTreeRoot(note);
|
||||
|
||||
res.render("share/page", {
|
||||
note,
|
||||
header,
|
||||
content,
|
||||
isEmpty,
|
||||
subRoot
|
||||
});
|
||||
}
|
||||
|
||||
router.get(['/share', '/share/'], (req, res, next) => {
|
||||
@@ -70,6 +79,8 @@ function register(router) {
|
||||
return res.status(404).send(`Note ${noteId} not found`);
|
||||
}
|
||||
|
||||
addNoIndexHeader(note, res);
|
||||
|
||||
res.json(note.getPojoWithAttributes());
|
||||
});
|
||||
|
||||
@@ -81,6 +92,8 @@ function register(router) {
|
||||
return res.status(404).send(`Note ${noteId} not found`);
|
||||
}
|
||||
|
||||
addNoIndexHeader(note, res);
|
||||
|
||||
const utils = require("../services/utils");
|
||||
|
||||
const filename = utils.formatDownloadTitle(note.title, note.type, note.mime);
|
||||
@@ -103,6 +116,8 @@ function register(router) {
|
||||
return res.status(400).send("Requested note is not an image");
|
||||
}
|
||||
|
||||
addNoIndexHeader(image, res);
|
||||
|
||||
res.set('Content-Type', image.mime);
|
||||
|
||||
res.send(image.getContent());
|
||||
@@ -117,6 +132,8 @@ function register(router) {
|
||||
return res.status(404).send(`Note ${noteId} not found`);
|
||||
}
|
||||
|
||||
addNoIndexHeader(note, res);
|
||||
|
||||
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
res.setHeader('Content-Type', note.mime);
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ class Attribute extends AbstractEntity {
|
||||
const linkedChildNote = this.note.getChildNotes().find(childNote => childNote.noteId === this.value);
|
||||
|
||||
if (linkedChildNote) {
|
||||
this.note.children = this.note.children.filter(childNote => childNote.noteId !== this.value);
|
||||
const branch = this.shaca.getBranchFromChildAndParent(this.noteId, linkedChildNote.noteId);
|
||||
|
||||
linkedChildNote.parents = linkedChildNote.parents.filter(parentNote => parentNote.noteId !== this.noteId);
|
||||
branch.isHidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ class Branch extends AbstractEntity {
|
||||
this.prefix = prefix;
|
||||
/** @param {boolean} */
|
||||
this.isExpanded = !!isExpanded;
|
||||
/** @param {boolean} */
|
||||
this.isHidden = false;
|
||||
|
||||
const childNote = this.childNote;
|
||||
const parentNote = this.parentNote;
|
||||
|
||||
@@ -59,7 +59,10 @@ class Note extends AbstractEntity {
|
||||
}
|
||||
|
||||
getVisibleChildNotes() {
|
||||
return this.children.filter(childNote => !childNote.hasLabel('shareHiddenFromTree') && !childNote.isProtected);
|
||||
return this.getChildBranches()
|
||||
.filter(branch => !branch.isHidden)
|
||||
.map(branch => branch.getNote())
|
||||
.filter(childNote => !childNote.hasLabel('shareHiddenFromTree') && !childNote.isProtected);
|
||||
}
|
||||
|
||||
hasChildren() {
|
||||
@@ -67,7 +70,7 @@ class Note extends AbstractEntity {
|
||||
}
|
||||
|
||||
hasVisibleChildren() {
|
||||
return this.children && !!this.children.find(childNote => !childNote.hasLabel('shareHiddenFromTree') && !childNote.isProtected);
|
||||
return this.getVisibleChildNotes().length > 0;
|
||||
}
|
||||
|
||||
getChildBranches() {
|
||||
|
||||
Reference in New Issue
Block a user