mirror of
https://github.com/zadam/trilium.git
synced 2025-11-15 09:45:52 +01:00
use isLabelTruthy() for most binary labels
This commit is contained in:
@@ -27,7 +27,7 @@ function getSharedSubTreeRoot(note) {
|
||||
}
|
||||
|
||||
function addNoIndexHeader(note, res) {
|
||||
if (note.hasLabel('shareDisallowRobotIndexing')) {
|
||||
if (note.isLabelTruthy('shareDisallowRobotIndexing')) {
|
||||
res.setHeader('X-Robots-Tag', 'noindex');
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,7 @@ function register(router) {
|
||||
|
||||
addNoIndexHeader(note, res);
|
||||
|
||||
if (note.hasLabel('shareRaw')) {
|
||||
if (note.isLabelTruthy('shareRaw')) {
|
||||
res.setHeader('Content-Type', note.mime)
|
||||
.send(note.getContent());
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ class SNote extends AbstractShacaEntity {
|
||||
return this.getChildBranches()
|
||||
.filter(branch => !branch.isHidden)
|
||||
.map(branch => branch.getNote())
|
||||
.filter(childNote => !childNote.hasLabel('shareHiddenFromTree'));
|
||||
.filter(childNote => !childNote.isLabelTruthy('shareHiddenFromTree'));
|
||||
}
|
||||
|
||||
/** @returns {boolean} */
|
||||
@@ -238,6 +238,20 @@ class SNote extends AbstractShacaEntity {
|
||||
*/
|
||||
hasLabel(name) { return this.hasAttribute(LABEL, name); }
|
||||
|
||||
/**
|
||||
* @param {string} name - label name
|
||||
* @returns {boolean} true if label exists (including inherited) and does not have "false" value.
|
||||
*/
|
||||
isLabelTruthy(name) {
|
||||
const label = this.getLabel(name);
|
||||
|
||||
if (!label) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return label && label.value !== 'false';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name - label name
|
||||
* @returns {boolean} true if label exists (excluding inherited)
|
||||
|
||||
Reference in New Issue
Block a user