From a57334f3919cc0fb015f969f8a5881c08247051c Mon Sep 17 00:00:00 2001 From: Guoyin-Wen Date: Thu, 22 Oct 2026 17:35:40 +0800 Subject: [PATCH] feat: support SVG site logo with dark mode color inversion - Detect SVG avatars (URL path or data URI) and apply dark:invert in dark mode so monochrome logos stay readable on dark backgrounds - Opt out per-URL by appending #no-invert, mirroring the existing #blurhash= URL-fragment metadata convention - Apply inversion to the header brand, admin sidebar and settings previews via the existing ImageWithFallback imageClassName - Accept image/svg+xml in the editor image picker - Serve SVG avatars directly as the favicon (cached as favicon.svg) instead of rasterizing them through Cloudflare Image Resizing - Update the avatar setting description in en/ja/zh-CN/zh-TW --- client/public/locales/en/translation.json | 2 +- client/public/locales/ja/translation.json | 2 +- client/public/locales/zh-CN/translation.json | 2 +- client/public/locales/zh-TW/translation.json | 2 +- client/src/components/admin-layout.tsx | 3 +- client/src/components/image-upload-input.tsx | 2 + client/src/components/markdown_editor.tsx | 2 +- .../site-header/primitives/brand-link.tsx | 2 + client/src/page/settings-items.tsx | 2 + .../utils/__tests__/image-dark-invert.test.ts | 68 ++++++++++ client/src/utils/image-dark-invert.ts | 33 +++++ server/src/services/__tests__/favicon.test.ts | 123 ++++++++++++++++++ server/src/services/favicon.ts | 57 ++++++++ 13 files changed, 294 insertions(+), 6 deletions(-) create mode 100644 client/src/utils/__tests__/image-dark-invert.test.ts create mode 100644 client/src/utils/image-dark-invert.ts diff --git a/client/public/locales/en/translation.json b/client/public/locales/en/translation.json index 69b1f1296..53680eedc 100644 --- a/client/public/locales/en/translation.json +++ b/client/public/locales/en/translation.json @@ -445,7 +445,7 @@ }, "avatar": { "title": "Site Avatar", - "desc": "Set the avatar shown in the navigation bar by URL, upload, or drag and drop", + "desc": "Set the avatar shown in the navigation bar by URL, upload, or drag and drop. SVG logos are inverted automatically in dark mode; append #no-invert to the URL to disable", "label": "Avatar URL" }, "page_size": { diff --git a/client/public/locales/ja/translation.json b/client/public/locales/ja/translation.json index ade8c8135..27b8589f6 100644 --- a/client/public/locales/ja/translation.json +++ b/client/public/locales/ja/translation.json @@ -436,7 +436,7 @@ }, "avatar": { "title": "サイトアバター", - "desc": "ナビゲーションバーに表示する画像を URL、アップロード、またはドラッグ&ドロップで設定します", + "desc": "ナビゲーションバーに表示する画像を URL、アップロード、またはドラッグ&ドロップで設定します。SVG ロゴはダークモードで自動的に反転されます。無効にするには URL に #no-invert を追加してください", "label": "アバター URL" }, "page_size": { diff --git a/client/public/locales/zh-CN/translation.json b/client/public/locales/zh-CN/translation.json index eac605ea3..96b2da312 100644 --- a/client/public/locales/zh-CN/translation.json +++ b/client/public/locales/zh-CN/translation.json @@ -445,7 +445,7 @@ }, "avatar": { "title": "站点头像", - "desc": "设置显示在导航栏的头像,支持填写 URL、上传图片或拖拽上传", + "desc": "设置显示在导航栏的头像,支持填写 URL、上传图片或拖拽上传。SVG 头像在暗色模式下自动反色,URL 后加 #no-invert 可停用", "label": "头像 URL" }, "page_size": { diff --git a/client/public/locales/zh-TW/translation.json b/client/public/locales/zh-TW/translation.json index cae4da408..3a5f0ed01 100644 --- a/client/public/locales/zh-TW/translation.json +++ b/client/public/locales/zh-TW/translation.json @@ -445,7 +445,7 @@ }, "avatar": { "title": "網站頭像", - "desc": "設定顯示在導覽列的頭像,支援填寫 URL、上傳圖片或拖拽上傳", + "desc": "設定顯示在導覽列的頭像,支援填寫 URL、上傳圖片或拖拽上傳。SVG 頭像在暗色模式下自動反色,URL 後加 #no-invert 可停用", "label": "頭像 URL" }, "page_size": { diff --git a/client/src/components/admin-layout.tsx b/client/src/components/admin-layout.tsx index faa0dea18..15dfd911f 100644 --- a/client/src/components/admin-layout.tsx +++ b/client/src/components/admin-layout.tsx @@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next"; import { Link, useLocation } from "wouter"; import { useSiteConfig } from "../hooks/useSiteConfig"; import { ImageWithFallback } from "./image-with-fallback"; +import { darkInvertImageClass } from "../utils/image-dark-invert"; function AdminNavItem({ href, @@ -50,7 +51,7 @@ export function AdminLayout({
{siteConfig.avatar ? ( - + ) : null}

{siteConfig.name}

diff --git a/client/src/components/image-upload-input.tsx b/client/src/components/image-upload-input.tsx index 44c05413b..94240eeba 100644 --- a/client/src/components/image-upload-input.tsx +++ b/client/src/components/image-upload-input.tsx @@ -7,6 +7,7 @@ import { isImageFile, uploadImageFile, } from "../utils/image-upload"; +import { darkInvertImageClass } from "../utils/image-dark-invert"; type ImageUploadInputProps = { value: string; @@ -74,6 +75,7 @@ export function ImageUploadInput({ src={value} alt={t("upload.image.preview_alt")} className="h-full w-full bg-transparent" + imageClassName={darkInvertImageClass(value)} /> ) : (