From 290f488c78601bb07f7ce61e55e90330461d645e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 27 Dec 2025 22:09:16 +0200 Subject: [PATCH] feat(share): ignore unsupported icon packs --- apps/server/src/share/content_renderer.ts | 2 + apps/server/src/share/shaca/entities/snote.ts | 40 +++++++++---------- .../share-theme/src/templates/tree_item.ejs | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/apps/server/src/share/content_renderer.ts b/apps/server/src/share/content_renderer.ts index 1a07c0110..b1c83f923 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.ts index 19dbd463e..5bc50bfe3 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 sql from "../../sql.js"; -import utils from "../../../services/utils.js"; -import AbstractShacaEntity from "./abstract_shaca_entity.js"; import escape from "escape-html"; + +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 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.ejs index 58d04a07b..28b45996f 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) { %> > <% if (note.hasVisibleChildren()) { %><% } %> - <%= note.title %> + <%= note.title %> <% } %>