feat(theme): 恢复主题桥,工作台页重新跟随 DSH 深浅色 (REQ-20261117-0013)
问题:Gitea 0.5.x 线缺了 qiudl 0.4.x 分支的整套主题桥能力,升级后所有工作台
产物页都不再跟随 DSH 主题(浅色/深色/跟随系统全部失效),页面各自锁死自己的配色。
这是升级引入的真实回归,比单个页面的配色问题严重得多。
移植内容(来自 qiudl 0.4.9-rc.2,theme.ts 无外部依赖,纯函数 + 浏览器脚本):
- 新增 src/theme.ts(191 行):THEME_BRIDGE_JS / injectThemeBridge / 前缀判定
- 模板路由补 /api/worktable/template/theme.js(独立打开/嵌套 iframe 显式引用)
- 站点路由对 .html/.htm 自动注入主题桥(幂等:已含 data-wt-theme-bridge 则原样)
- 新增 04_test/theme-bridge.test.mjs(7 个回归用例,含接线防漏)
顺带修两处写死项(同属「不跟随主题」根因):
- dshell.css::root{color-scheme:dark} → color-scheme:light dark + 浅/深两套
兜底 token(历史事故:写死深色会让所有页面锁死深色)
- dshell.css:正文字体改走 var(--dsw-font-family, ...)
版本 0.5.3-local.3 -> 0.5.3-local.4
验证:build 通过;client-factory-gate 10/10;主题桥测试 7/7;兼容回归 105/105;
release-prep 全过(结构断言、独立安装 import、split anchor dom 14 场景、
sidebar popup、真实 Chromium split margin 5 场景、server home 3 场景)
This commit is contained in:
+12
-1
@@ -8,6 +8,7 @@ import { homedir } from 'node:os'
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||
import { requestRejection, rejectionText } from './requestAuth'
|
||||
import { createPreviewFiles, PREVIEW_PREFIX, PREVIEW_CSP } from './previewFiles'
|
||||
import { injectThemeBridge, THEME_BRIDGE_JS } from './theme'
|
||||
|
||||
/**
|
||||
* 基础数据目录解析:不加载任何官方包(loadPkg 的兜底只能用它,禁止反向调用包加载函数——否则成环)。
|
||||
@@ -397,6 +398,11 @@ export function apply(ctx: Context) {
|
||||
if (rel === '/dshell.css') {
|
||||
res.writeHead(200, { 'content-type': 'text/css; charset=utf-8', 'cache-control': 'no-store' })
|
||||
res.end(dshellCss)
|
||||
} else if (rel === '/theme.js') {
|
||||
// REQ-20261117-0013:主题桥显式引用入口(站点路由已自动注入内联版;
|
||||
// 独立打开 / 嵌套 iframe 时手动引这一份)。移植自 qiudl 0.4.x 分支。
|
||||
res.writeHead(200, { 'content-type': 'text/javascript; charset=utf-8', 'cache-control': 'no-store' })
|
||||
res.end(THEME_BRIDGE_JS)
|
||||
} else {
|
||||
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' })
|
||||
res.end(dshellHtml)
|
||||
@@ -433,7 +439,12 @@ export function apply(ctx: Context) {
|
||||
const ext = (abs.split('.').pop() || '').toLowerCase()
|
||||
res.writeHead(200, { 'content-type': FILE_TYPES[ext] ?? 'application/octet-stream', 'cache-control': 'no-store',
|
||||
'content-security-policy': PREVIEW_CSP, 'referrer-policy': 'no-referrer', 'x-content-type-options': 'nosniff' })
|
||||
res.end(data)
|
||||
// REQ-20261117-0013:产物 HTML 自动挂主题桥,让所有工作台页跟随 DSH 主题
|
||||
// (浅色/深色/跟随系统)。幂等:已含 data-wt-theme-bridge 标记则原样返回;
|
||||
// 非 HTML 不受影响。移植自 qiudl 0.4.x 分支(0.5.x 线缺失该能力)。
|
||||
res.end(ext === 'html' || ext === 'htm'
|
||||
? Buffer.from(injectThemeBridge(data.toString('utf8')), 'utf8')
|
||||
: data)
|
||||
} catch (err) {
|
||||
json(res, 404, { error: String(err) })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user