added #shareDisallowRobotIndexing label and reworked how the child-image exclusion works

This commit is contained in:
zadam 2022-03-22 23:17:47 +01:00
parent 0a95d0f6f5
commit e00fcd93a1
9 changed files with 52 additions and 32 deletions

View File

@ -216,6 +216,7 @@ const ATTR_HELP = {
"shareOmitDefaultCss": "default share page CSS will be omitted. Use when you make extensive styling changes.", "shareOmitDefaultCss": "default share page CSS will be omitted. Use when you make extensive styling changes.",
"shareRoot": "marks note which is served on /share root.", "shareRoot": "marks note which is served on /share root.",
"shareRaw": "note will be served in its raw format, without HTML wrapper", "shareRaw": "note will be served in its raw format, without HTML wrapper",
"shareDisallowRobotIndexing": `will forbid robot indexing of this note via <code>X-Robots-Tag: noindex</code> header`,
"displayRelations": "comma delimited names of relations which should be displayed. All other ones will be hidden.", "displayRelations": "comma delimited names of relations which should be displayed. All other ones will be hidden.",
"hideRelations": "comma delimited names of relations which should be hidden. All other ones will be displayed.", "hideRelations": "comma delimited names of relations which should be hidden. All other ones will be displayed.",
}, },

View File

@ -128,10 +128,6 @@ function isAttributeDangerous(type, name) {
); );
} }
function getBuiltinAttributeNames() {
return BUILTIN_ATTRIBUTES;
}
function sanitizeAttributeName(origName) { function sanitizeAttributeName(origName) {
let fixedName; let fixedName;
@ -156,6 +152,5 @@ module.exports = {
getAttributeNames, getAttributeNames,
isAttributeType, isAttributeType,
isAttributeDangerous, isAttributeDangerous,
getBuiltinAttributeNames,
sanitizeAttributeName sanitizeAttributeName
}; };

View File

@ -47,6 +47,7 @@ module.exports = [
{ type: 'label', name: 'shareOmitDefaultCss' }, { type: 'label', name: 'shareOmitDefaultCss' },
{ type: 'label', name: 'shareRoot' }, { type: 'label', name: 'shareRoot' },
{ type: 'label', name: 'shareRaw' }, { type: 'label', name: 'shareRaw' },
{ type: 'label', name: 'shareDisallowRobotIndexing' },
{ type: 'label', name: 'displayRelations' }, { type: 'label', name: 'displayRelations' },
{ type: 'label', name: 'hideRelations' }, { type: 'label', name: 'hideRelations' },

View File

@ -20,10 +20,22 @@ function getSharedSubTreeRoot(note) {
return getSharedSubTreeRoot(parentNote); return getSharedSubTreeRoot(parentNote);
} }
function addNoIndexHeader(note, res) {
if (note.hasLabel('shareDisallowRobotIndexing')) {
res.setHeader('X-Robots-Tag', 'noindex');
}
}
function register(router) { function register(router) {
function renderNote(note, res) { function renderNote(note, res) {
if (note) { if (!note) {
if (note.hasLabel('shareRaw')) { 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.setHeader('Content-Type', note.mime);
res.send(note.getContent()); res.send(note.getContent());
@ -41,9 +53,6 @@ function register(router) {
isEmpty, isEmpty,
subRoot subRoot
}); });
} else {
res.status(404).render("share/404");
}
} }
router.get(['/share', '/share/'], (req, res, next) => { router.get(['/share', '/share/'], (req, res, next) => {
@ -70,6 +79,8 @@ function register(router) {
return res.status(404).send(`Note ${noteId} not found`); return res.status(404).send(`Note ${noteId} not found`);
} }
addNoIndexHeader(note, res);
res.json(note.getPojoWithAttributes()); res.json(note.getPojoWithAttributes());
}); });
@ -81,6 +92,8 @@ function register(router) {
return res.status(404).send(`Note ${noteId} not found`); return res.status(404).send(`Note ${noteId} not found`);
} }
addNoIndexHeader(note, res);
const utils = require("../services/utils"); const utils = require("../services/utils");
const filename = utils.formatDownloadTitle(note.title, note.type, note.mime); 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"); return res.status(400).send("Requested note is not an image");
} }
addNoIndexHeader(image, res);
res.set('Content-Type', image.mime); res.set('Content-Type', image.mime);
res.send(image.getContent()); res.send(image.getContent());
@ -117,6 +132,8 @@ function register(router) {
return res.status(404).send(`Note ${noteId} not found`); return res.status(404).send(`Note ${noteId} not found`);
} }
addNoIndexHeader(note, res);
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
res.setHeader('Content-Type', note.mime); res.setHeader('Content-Type', note.mime);

View File

@ -34,9 +34,9 @@ class Attribute extends AbstractEntity {
const linkedChildNote = this.note.getChildNotes().find(childNote => childNote.noteId === this.value); const linkedChildNote = this.note.getChildNotes().find(childNote => childNote.noteId === this.value);
if (linkedChildNote) { 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;
} }
} }

View File

@ -16,6 +16,8 @@ class Branch extends AbstractEntity {
this.prefix = prefix; this.prefix = prefix;
/** @param {boolean} */ /** @param {boolean} */
this.isExpanded = !!isExpanded; this.isExpanded = !!isExpanded;
/** @param {boolean} */
this.isHidden = false;
const childNote = this.childNote; const childNote = this.childNote;
const parentNote = this.parentNote; const parentNote = this.parentNote;

View File

@ -59,7 +59,10 @@ class Note extends AbstractEntity {
} }
getVisibleChildNotes() { 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() { hasChildren() {
@ -67,7 +70,7 @@ class Note extends AbstractEntity {
} }
hasVisibleChildren() { hasVisibleChildren() {
return this.children && !!this.children.find(childNote => !childNote.hasLabel('shareHiddenFromTree') && !childNote.isProtected); return this.getVisibleChildNotes().length > 0;
} }
getChildBranches() { getChildBranches() {

View File

@ -21,6 +21,9 @@
<% for (const jsRelation of note.getRelations("shareJs")) { %> <% for (const jsRelation of note.getRelations("shareJs")) { %>
<script type="module" src="api/notes/<%= jsRelation.value %>/download"></script> <script type="module" src="api/notes/<%= jsRelation.value %>/download"></script>
<% } %> <% } %>
<% if (note.hasLabel('shareDisallowRobotIndexing')) { %>
<meta name="robots" content="noindex,follow" />
<% } %>
<%- header %> <%- header %>
<title><%= note.title %></title> <title><%= note.title %></title>
</head> </head>

View File

@ -8,12 +8,10 @@
<% if (note.hasChildren()) { %> <% if (note.hasChildren()) { %>
<ul> <ul>
<% note.getChildNotes().forEach(function (childNote) { %> <% note.getVisibleChildNotes().forEach(function (childNote) { %>
<% if (!childNote.hasLabel("shareHiddenFromTree")) { %>
<li> <li>
<%- include('tree_item', {note: childNote}) %> <%- include('tree_item', {note: childNote}) %>
</li> </li>
<% } %>
<% }) %> <% }) %>
</ul> </ul>
<% } %> <% } %>