feat: native DSH skin template (dshell.css/html served at /api/worktable/template) + knowledge pack mandates it for generated HTML

This commit is contained in:
Aisland
2026-08-19 23:54:26 +08:00
parent a4d5646f1d
commit 30b694341b
7 changed files with 202 additions and 0 deletions
+3
View File
@@ -428,6 +428,9 @@ const KNOWLEDGE_PACK = [
' 窗内容还可放 iframe 网页与文件预览(.md/.txt/.tsx/.css/.html 等)。',
'- 窗口可装载的形式:HTML 单文件(交互 UI,放项目文件夹后在资源管理器点击渲染)、网页 URL、',
' 文件预览(.md/.txt/.tsx/.css/.html/图片/.mp4 等);产出形式按任务类型选,不要一律 HTML。',
'- 产出 HTML 必须用工作台原生皮肤:在页面 <head> 加 <link rel="stylesheet" href="/api/worktable/template/dshell.css">,',
' 组件类参考 /api/worktable/template/dshell.html(卡片/按钮/状态徽标/标签页/列表/统计/进度/表格等),',
' 界面即可与 DSH 原生风格一致;自造样式控制在最小范围。',
'- 服务端能力:/api/worktable/fs(列目录)、/api/worktable/write(写文件)、/api/worktable/mkdir(建目录)、',
' /api/worktable/git(git 状态)、/api/worktable/site(静态托管)。',
'- 改完插件在 01_content 目录执行 npm run build;重启 dsh web 或浏览器 F5 生效。',
+29
View File
@@ -38,6 +38,13 @@ const FILE_TYPES: Record<string, string> = {
const SITE_PREFIX = '/api/worktable/site'
// 原生皮肤模板(esbuild text loader 嵌入;/api/worktable/template 路由直接下发)
// @ts-ignore
import dshellCss from '../template/dshell.css'
// @ts-ignore
import dshellHtml from '../template/dshell.html'
const TEMPLATE_PREFIX = '/api/worktable/template'
/**
* 从本插件模块位置向祖先方向查找并加载 node_modules 包(如 ws / node-pty)。
* 本包经 junction 链接进 profile,普通 import 可能解析不到 profile 级依赖;
@@ -236,6 +243,28 @@ export function apply(ctx: Context) {
// 本地站点(目录级静态托管):点开 index.html 时挂载整个所在目录,
// 让 ./assets/... 等相对引用正常解析(前缀路由,余下路径 = <rootToken>/<相对路径>)。
// 原生皮肤模板:HTML 骨架 + 设计系统样式表(随插件分发,主题自动适配)
webServer.register({
kind: 'prefix',
path: TEMPLATE_PREFIX,
handler: (req: any, res: any) => {
try {
if (req.method !== 'GET') { res.writeHead(405); res.end(); return }
const pathname = new URL(req.url ?? '/', 'http://dsh.internal').pathname
const rel = pathname.slice(TEMPLATE_PREFIX.length)
if (rel === '/dshell.css') {
res.writeHead(200, { 'content-type': 'text/css; charset=utf-8', 'cache-control': 'no-store' })
res.end(dshellCss)
} else {
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' })
res.end(dshellHtml)
}
} catch (err) {
res.writeHead(404); res.end(String(err))
}
},
})
webServer.register({
kind: 'prefix',
path: SITE_PREFIX,