Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
use isLabelTruthy() for most binary labels
zadama46c5a224304
diff --git a/src/public/app/components/note_context.js b/src/public/app/components/note_context.jsindex 9116304b25..365b68ad19 100644--- a/src/public/app/components/note_context.js+++ b/src/public/app/components/note_context.js@@ -85,7 +85,7 @@ class NoteContext extends Component {async setHoistedNoteIfNeeded() {if (this.hoistedNoteId === 'root'&& this.notePath.startsWith("root/_hidden")- && !this.note.hasLabel("keepCurrentHoisting")+ && !this.note.isLabelTruthy("keepCurrentHoisting")) {// hidden subtree displays only when hoisted, so it doesn't make sense to keep root as hoisted note@@ -221,7 +221,7 @@ class NoteContext extends Component {return false;}- if (this.note.hasLabel('readOnly')) {+ if (this.note.isLabelTruthy('readOnly')) {return true;}@@ -236,7 +236,7 @@ class NoteContext extends Component {: options.getInt('autoReadonlySizeCode');return blob.contentLength > sizeLimit- && !this.note.hasLabel('autoReadOnlyDisabled');+ && !this.note.isLabelTruthy('autoReadOnlyDisabled');}async entitiesReloadedEvent({loadResults}) {@@ -261,7 +261,7 @@ class NoteContext extends Component {&& this.note.hasChildren()&& ['book', 'text', 'code'].includes(this.note.type)&& this.note.mime !== 'text/x-sqlite;schema=trilium'- && !this.note.hasLabel('hideChildrenOverview');+ && !this.note.isLabelTruthy('hideChildrenOverview');}async getTextEditor(callback) {diff --git a/src/public/app/entities/fnote.js b/src/public/app/entities/fnote.jsindex 4a6f0c8474..7d243d2bdc 100644--- a/src/public/app/entities/fnote.js+++ b/src/public/app/entities/fnote.js@@ -761,7 +761,7 @@ class FNote {}getPromotedDefinitionAttributes() {- if (this.hasLabel('hidePromotedAttributes')) {+ if (this.isLabelTruthy('hidePromotedAttributes')) {return [];}diff --git a/src/public/app/services/note_list_renderer.js b/src/public/app/services/note_list_renderer.jsindex dca6ac3630..873b1f09d4 100644--- a/src/public/app/services/note_list_renderer.js+++ b/src/public/app/services/note_list_renderer.js@@ -230,7 +230,7 @@ class NoteListRenderer {const pageNotes = await froca.getNotes(pageNoteIds);for (const note of pageNotes) {- const $card = await this.renderNote(note, this.parentNote.hasLabel('expanded'));+ const $card = await this.renderNote(note, this.parentNote.isLabelTruthy('expanded'));$container.append($card);}diff --git a/src/public/app/widgets/bookmark_buttons.js b/src/public/app/widgets/bookmark_buttons.jsindex 1bc5345273..53121ecb9c 100644--- a/src/public/app/widgets/bookmark_buttons.js+++ b/src/public/app/widgets/bookmark_buttons.js@@ -20,7 +20,7 @@ export default class BookmarkButtons extends FlexContainer {for (const note of await bookmarkParentNote.getChildNotes()) {this.noteIds.push(note.noteId);- const buttonWidget = note.hasLabel("bookmarkFolder")+ const buttonWidget = note.isLabelTruthy("bookmarkFolder")? new BookmarkFolderWidget(note): new OpenNoteButtonWidget(note).class("launcher-button");diff --git a/src/public/app/widgets/buttons/launcher/script_launcher.js b/src/public/app/widgets/buttons/launcher/script_launcher.jsindex b5cfebbf9f..71ca35f1c3 100644--- a/src/public/app/widgets/buttons/launcher/script_launcher.js+++ b/src/public/app/widgets/buttons/launcher/script_launcher.js@@ -10,7 +10,7 @@ export default class ScriptLauncher extends AbstractLauncher {}async launch() {- if (this.launcherNote.hasLabel('scriptInLauncherContent')) {+ if (this.launcherNote.isLabelTruthy('scriptInLauncherContent')) {await this.launcherNote.executeScript();} else {const script = await this.launcherNote.getRelationTarget('script');diff --git a/src/public/app/widgets/containers/launcher.js b/src/public/app/widgets/containers/launcher.jsindex bb85f8b842..a4697c76f8 100644--- a/src/public/app/widgets/containers/launcher.js+++ b/src/public/app/widgets/containers/launcher.js@@ -31,7 +31,7 @@ export default class LauncherWidget extends BasicWidget {throw new Error(`Note '${note.noteId}' '${note.title}' is not a launcher even though it's in the launcher subtree`);}- if (!utils.isDesktop() && note.hasLabel('desktopOnly')) {+ if (!utils.isDesktop() && note.isLabelTruthy('desktopOnly')) {return false;}diff --git a/src/public/app/widgets/editability_select.js b/src/public/app/widgets/editability_select.jsindex 3aedd38e34..2cc4f14deb 100644--- a/src/public/app/widgets/editability_select.js+++ b/src/public/app/widgets/editability_select.js@@ -65,10 +65,10 @@ export default class EditabilitySelectWidget extends NoteContextAwareWidget {async refreshWithNote(note) {let editability = 'auto'- if (this.note.hasLabel('readOnly')) {+ if (this.note.isLabelTruthy('readOnly')) {editability = 'readOnly';}- else if (this.note.hasLabel('autoReadOnlyDisabled')) {+ else if (this.note.isLabelTruthy('autoReadOnlyDisabled')) {editability = 'autoReadOnlyDisabled';}diff --git a/src/public/app/widgets/note_wrapper.js b/src/public/app/widgets/note_wrapper.jsindex a724c3b6db..91e9ff3cf5 100644--- a/src/public/app/widgets/note_wrapper.js+++ b/src/public/app/widgets/note_wrapper.js@@ -44,7 +44,7 @@ export default class NoteWrapperWidget extends FlexContainer {this.$widget.toggleClass("full-content-width",['image', 'mermaid', 'book', 'render', 'canvas', 'webView'].includes(note.type)- || !!note?.hasLabel('fullContentWidth')+ || !!note?.isLabelTruthy('fullContentWidth'));this.$widget.addClass(note.getCssClass());diff --git a/src/public/app/widgets/ribbon_widgets/book_properties.js b/src/public/app/widgets/ribbon_widgets/book_properties.jsindex 48861150dd..90147b7bfc 100644--- a/src/public/app/widgets/ribbon_widgets/book_properties.js+++ b/src/public/app/widgets/ribbon_widgets/book_properties.js@@ -72,7 +72,7 @@ export default class BookPropertiesWidget extends NoteContextAwareWidget {this.$expandChildrenButton = this.$widget.find('.expand-children-button');this.$expandChildrenButton.on('click', async () => {- if (!this.note.hasLabel('expanded')) {+ if (!this.note.isLabelTruthy('expanded')) {await attributeService.addLabel(this.noteId, 'expanded');}diff --git a/src/public/app/widgets/ribbon_widgets/similar_notes.js b/src/public/app/widgets/ribbon_widgets/similar_notes.jsindex 0d47375fd2..562e1c0c14 100644--- a/src/public/app/widgets/ribbon_widgets/similar_notes.js+++ b/src/public/app/widgets/ribbon_widgets/similar_notes.js@@ -42,7 +42,7 @@ export default class SimilarNotesWidget extends NoteContextAwareWidget {isEnabled() {return super.isEnabled()&& this.note.type !== 'search'- && !this.note.hasLabel('similarNotesWidgetDisabled');+ && !this.note.isLabelTruthy('similarNotesWidgetDisabled');}getTitle() {diff --git a/src/services/notes.js b/src/services/notes.jsindex ff02f683f0..22c9d858c4 100644--- a/src/services/notes.js+++ b/src/services/notes.js@@ -661,7 +661,7 @@ function saveLinks(note, content) {/** @param {BNote} note */function saveRevisionIfNeeded(note) {// files and images are versioned separately- if (note.type === 'file' || note.type === 'image' || note.hasLabel('disableVersioning')) {+ if (note.type === 'file' || note.type === 'image' || note.isLabelTruthy('disableVersioning')) {return;}diff --git a/src/share/routes.js b/src/share/routes.jsindex 31fc293708..2191413d18 100644--- a/src/share/routes.js+++ b/src/share/routes.js@@ -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());diff --git a/src/share/shaca/entities/snote.js b/src/share/shaca/entities/snote.jsindex 2f4bc2fac6..adfc5d02e0 100644--- a/src/share/shaca/entities/snote.js+++ b/src/share/shaca/entities/snote.js@@ -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)diff --git a/src/views/share/page.ejs b/src/views/share/page.ejsindex 41e0a5c199..2bdb1050ed 100644--- a/src/views/share/page.ejs+++ b/src/views/share/page.ejs@@ -13,7 +13,7 @@<link rel="shortcut icon" href="../favicon.ico"><% } %><script src="../<%= appPath %>/share.js"></script>- <% if (!note.hasLabel("shareOmitDefaultCss")) { %>+ <% if (!note.isLabelTruthy("shareOmitDefaultCss")) { %><link href="../<%= assetPath %>/libraries/normalize.min.css" rel="stylesheet"><link href="../<%= assetPath %>/stylesheets/share.css" rel="stylesheet"><% } %>@@ -26,7 +26,7 @@<% for (const jsRelation of note.getRelations("shareJs")) { %><script type="module" src="api/notes/<%= jsRelation.value %>/download"></script><% } %>- <% if (note.hasLabel('shareDisallowRobotIndexing')) { %>+ <% if (note.isLabelTruthy('shareDisallowRobotIndexing')) { %><meta name="robots" content="noindex,follow" /><% } %><%- header %>