An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Prefill localized network icon names https://github.com/siyuan-note/siyuan/issues/12926
Daniel5ca2873b61bf
diff --git a/app/src/emoji/iconValue.test.ts b/app/src/emoji/iconValue.test.tsindex 9abff133d8..54254f0854 100644--- a/app/src/emoji/iconValue.test.ts+++ b/app/src/emoji/iconValue.test.ts@@ -5,6 +5,7 @@ import {genEmojiImageHTML,getIconSearchText,getIconValueKind,+ getNetworkIconName,normalizeNetworkIconURL,normalizeRecentIconValue,parseBase64Image,@@ -32,6 +33,19 @@ describe("normalizeNetworkIconURL", () => {});});+describe("getNetworkIconName", () => {+ it("uses the decoded URL path name without its extension", () => {+ assert.equal(getNetworkIconName("https://example.com/images/%E5%A4%B4%E5%83%8F.png?size=64"), "头像");+ assert.equal(getNetworkIconName("https://example.com/images/icon.php"), "icon");+ assert.equal(getNetworkIconName("https://example.com/images/foo%2Fbar.webp"), "foo_bar");+ });++ it("falls back when the URL has no usable path name", () => {+ assert.equal(getNetworkIconName("https://example.com/"), "icon");+ assert.equal(getNetworkIconName("invalid"), "icon");+ });+});+describe("getIconValueKind", () => {it("distinguishes supported icon value formats", () => {assert.equal(getIconValueKind("1f600"), "unicode");diff --git a/app/src/emoji/iconValue.ts b/app/src/emoji/iconValue.tsindex d237fdd96c..fe078fc81a 100644--- a/app/src/emoji/iconValue.ts+++ b/app/src/emoji/iconValue.ts@@ -31,6 +31,24 @@ export const normalizeNetworkIconURL = (value: string): string | undefined => {return url.href;};+export const getNetworkIconName = (value: string): string => {+ const normalizedURL = normalizeNetworkIconURL(value);+ if (!normalizedURL) {+ return "icon";+ }++ const pathSegment = new URL(normalizedURL).pathname.split("/").filter(Boolean).pop() || "";+ let name = pathSegment;+ try {+ name = decodeURIComponent(pathSegment);+ } catch {+ // 保留 URL 中未正确编码的路径名称。+ }+ name = name.replace(/\.[^.]*$/, "").replace(/[\\/:*?"<>|]/g, "_");+ name = Array.from(name, character => character.charCodeAt(0) < 32 ? "_" : character).join("").trim();+ return name || "icon";+};+export const parseBase64Image = (value: string): IBase64Image | undefined => {const icon = value.trim();const commaIndex = icon.indexOf(",");diff --git a/app/src/emoji/index.ts b/app/src/emoji/index.tsindex b29e538054..103f4ca91f 100644--- a/app/src/emoji/index.ts+++ b/app/src/emoji/index.ts@@ -16,6 +16,7 @@ import {genEmojiImageHTML,getIconSearchText,getIconValueKind,+ getNetworkIconName,normalizeNetworkIconURL,normalizeRecentIconValue,parseBase64Image,@@ -1217,6 +1218,7 @@ export const openEmojiPanel = (};const localizeNetworkIconFile = () => {localizeNetworkIcon = true;+ customIconNameElement.value = getNetworkIconName(networkIconInputElement.value);renderNetworkIconPreview();customIconNameElement.focus();};