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
feat(share): ignore unsupported icon packs
Elian Doran290f488c7860
diff --git a/apps/server/src/share/content_renderer.ts b/apps/server/src/share/content_renderer.tsindex 1a07c01107..b1c83f9239 100644--- a/apps/server/src/share/content_renderer.ts+++ b/apps/server/src/share/content_renderer.ts@@ -140,6 +140,7 @@ export function renderNoteContent(note: SNote) {iconPackCss: iconPacks.map(p => generateCss(p, true)).filter(Boolean).join("\n\n"),+ iconPackSupportedPrefixes: iconPacks.map(p => p.manifest.prefix)});}@@ -153,6 +154,7 @@ interface RenderArgs {isStatic: boolean;faviconUrl: string;iconPackCss: string;+ iconPackSupportedPrefixes: string[];}function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs) {diff --git a/apps/server/src/share/shaca/entities/snote.ts b/apps/server/src/share/shaca/entities/snote.tsindex 19dbd463e2..5bc50bfe34 100644--- a/apps/server/src/share/shaca/entities/snote.ts+++ b/apps/server/src/share/shaca/entities/snote.ts@@ -1,15 +1,14 @@-"use strict";+import escape from "escape-html";-import sql from "../../sql.js";+import { NOTE_TYPE_ICONS } from "../../../becca/entities/bnote.js";+import type { Blob } from "../../../services/blob-interface.js";import utils from "../../../services/utils.js";+import sql from "../../sql.js";import AbstractShacaEntity from "./abstract_shaca_entity.js";-import escape from "escape-html";-import type { Blob } from "../../../services/blob-interface.js";+import type { SNoteRow } from "./rows.js";import type SAttachment from "./sattachment.js";import type SAttribute from "./sattribute.js";import type SBranch from "./sbranch.js";-import type { SNoteRow } from "./rows.js";-import { NOTE_TYPE_ICONS } from "../../../becca/entities/bnote.js";const LABEL = "label";const RELATION = "relation";@@ -101,18 +100,16 @@ class SNote extends AbstractShacaEntity {if (!row) {if (silentNotFoundError) {return undefined;- } else {- throw new Error(`Cannot find note content for note '${this.noteId}', blob '${this.blobId}'`);}+ throw new Error(`Cannot find note content for note '${this.noteId}', blob '${this.blobId}'`);}const content = row.content;if (this.hasStringContent()) {return content === null ? "" : content.toString("utf-8");- } else {- return content;}+ return content;}/** @returns true if the note has string content (not binary) */@@ -137,9 +134,8 @@ class SNote extends AbstractShacaEntity {return attributeCache.filter((attr) => attr.type === type && !isCredentials(attr));} else if (name) {return attributeCache.filter((attr) => attr.name === name && !isCredentials(attr));- } else {- return attributeCache.filter((attr) => !isCredentials(attr));}+ return attributeCache.filter((attr) => !isCredentials(attr));}getCredentials() {@@ -460,9 +456,8 @@ class SNote extends AbstractShacaEntity {return this.ownedAttributes.filter((attr) => attr.type === type);} else if (name) {return this.ownedAttributes.filter((attr) => attr.name === name);- } else {- return this.ownedAttributes.slice();}+ return this.ownedAttributes.slice();}/**@@ -532,8 +527,13 @@ class SNote extends AbstractShacaEntity {};}- getIcon() {- const iconClassLabels = this.getLabels("iconClass");+ getIcon(filterByPrefix: string[] = []) {+ const iconClassLabels = this.getLabels("iconClass").filter(label => {+ if (filterByPrefix.length === 0) {+ return true;+ }+ return filterByPrefix.some(prefix => label.value.startsWith(prefix));+ });if (iconClassLabels && iconClassLabels.length > 0) {return iconClassLabels[0].value;@@ -545,14 +545,12 @@ class SNote extends AbstractShacaEntity {} else if (this.type === "text") {if (this.isFolder()) {return "bx bx-folder";- } else {- return "bx bx-note";}+ return "bx bx-note";} else if (this.type === "code" && this.mime.startsWith("text/x-sql")) {return "bx bx-data";- } else {- return NOTE_TYPE_ICONS[this.type];}+ return NOTE_TYPE_ICONS[this.type];}isFolder() {diff --git a/packages/share-theme/src/templates/tree_item.ejs b/packages/share-theme/src/templates/tree_item.ejsindex 58d04a07b7..28b45996f8 100644--- a/packages/share-theme/src/templates/tree_item.ejs+++ b/packages/share-theme/src/templates/tree_item.ejs@@ -15,7 +15,7 @@ const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : "<% if (note.noteId !== subRoot.note.noteId) { %><a class="<%= linkClass %>" href="<%= linkHref %>"<%= target %>><% if (note.hasVisibleChildren()) { %><button class="collapse-button" aria-label="<%= t("share_theme.expand") %>"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon right-triangle"><path d="M3 8L12 17L21 8"></path></svg></button><% } %>- <span><i class="<%= note.getIcon() %>"></i> <%= note.title %></span>+ <span><i class="<%= note.getIcon(iconPackSupportedPrefixes) %>"></i> <%= note.title %></span></a><% } %>