Files
cindy/apps/desktop/scripts/gen-help-kb.mjs
kirozeng e23e3f3f77 feat(desktop): 设置拆出「外观」栏目
外观相关设置原本是「通用」页中的一节,内容多且与其他设置混在一起。
现在设置左侧菜单「通用」下新增「外观」栏目:

- 页面标题「外观」(20px),首张卡片为主题、显示模式与本地主题,
  其后为壁纸、字体、侧边栏与面板、回复动效(由「个性化」移入)各节,
  均采用标题在卡外、卡内设置行加分割线的排法。
- 主题改为与「显示语言」同款的单行胶囊下拉;只有浅色或深色方案的
  主题标「仅浅色 / 仅深色」,选中时显示模式只读并说明原因,保存的
  模式不变。
- 显示模式改为三张迷你 Cindy 窗口缩略图,颜色取所选主题的浅 / 深方案。
- 旧的「通用 → 外观」「个性化 → 回复动效」深链与搜索结果落到新栏目;
  设置搜索补充各节入口;帮助知识拆为「外观」与「语言和通知」两篇。
- 新增 settingsRowClasses 共用设置行样式;设置页下拉框文字统一为 400。
- DESIGN.md 补「Desktop settings rows」与外观页规则,并记入决策史。

Signed-off-by: kirozeng <kirozeng@gmail.com>
2026-10-18 03:17:05 +08:00

110 lines
3.9 KiB
JavaScript

// Compiles apps/desktop/help-knowledge/*.md into a generated TS module that the
// main process imports (main is Vite-bundled and can't read loose .md at runtime).
// Run after editing any help doc: pnpm gen:help-kb (commit the generated file)
// CI drift check (regenerate + compare, no write): pnpm gen:help-kb:check
import { readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import process from 'node:process';
import matter from 'gray-matter';
const here = dirname(fileURLToPath(import.meta.url));
const KB_DIR = resolve(here, '../help-knowledge');
const OUT = resolve(here, '../src/main/maker-ipc/helpKnowledge.generated.ts');
// Must stay in sync with HelpTabId in src/shared/helpTypes.ts.
const ALLOWED_TABS = new Set([
'general',
'appearance',
'personalization',
'api-keys',
'providers',
'voice-input',
'import',
'connections',
'im-bot',
'about',
'ghosts',
'remote-control',
]);
function fail(msg) {
console.error(`[gen-help-kb] ${msg}`);
process.exit(1);
}
/**
* Read + validate help-knowledge/*.md and render the generated TS module.
* Pure (no write) so both the writer (CLI) and the drift guard can share it.
* Validation failures hard-exit (used by both paths).
*/
export function renderHelpKnowledgeModule() {
const files = readdirSync(KB_DIR).filter((f) => f.endsWith('.md')).sort();
if (files.length === 0) fail(`no .md files found in ${KB_DIR}`);
const seen = new Set();
const docs = [];
for (const file of files) {
const { data, content } = matter(readFileSync(join(KB_DIR, file), 'utf8'));
const id = String(data.id ?? '').trim();
const title = String(data.title ?? '').trim();
const summary = String(data.summary ?? '').trim();
const tab = data.tab === undefined ? undefined : String(data.tab).trim();
// Normalize EOL so generated output is deterministic regardless of the
// checkout's line endings (Windows autocrlf would otherwise embed \r\n).
const body = content.replace(/\r\n/g, '\n').trim();
if (!id) fail(`${file}: missing 'id'`);
if (!/^[a-z0-9-]+$/.test(id)) fail(`${file}: id '${id}' must be kebab-case [a-z0-9-]`);
if (seen.has(id)) fail(`${file}: duplicate id '${id}'`);
if (!title) fail(`${file}: missing 'title'`);
if (!summary) fail(`${file}: missing 'summary'`);
if (tab !== undefined && !ALLOWED_TABS.has(tab)) {
fail(`${file}: tab '${tab}' not in [${[...ALLOWED_TABS].join(', ')}]`);
}
if (!body) fail(`${file}: empty body`);
seen.add(id);
docs.push({ id, title, summary, tab, content: body });
}
docs.sort((a, b) => a.id.localeCompare(b.id));
const entries = docs
.map((d) => {
const lines = [
' {',
` id: ${JSON.stringify(d.id)},`,
` title: ${JSON.stringify(d.title)},`,
` summary: ${JSON.stringify(d.summary)},`,
];
if (d.tab !== undefined) lines.push(` tab: ${JSON.stringify(d.tab)},`);
lines.push(` content: ${JSON.stringify(d.content)},`, ' },');
return lines.join('\n');
})
.join('\n');
const content = `// AUTO-GENERATED by scripts/gen-help-kb.mjs — do not edit by hand.
// Source: apps/desktop/help-knowledge/*.md · Regenerate: pnpm gen:help-kb
import type { HelpTabId } from '../../shared/helpTypes.js';
export interface HelpKnowledgeDoc {
id: string;
title: string;
summary: string;
tab?: HelpTabId;
content: string;
}
export const HELP_KNOWLEDGE: HelpKnowledgeDoc[] = [
${entries}
];
`;
return { outPath: OUT, content, count: docs.length };
}
// CLI: write the generated file when run directly (not when imported by the guard).
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
const { outPath, content, count } = renderHelpKnowledgeModule();
writeFileSync(outPath, content, 'utf8');
console.log(`[gen-help-kb] wrote ${count} docs -> ${outPath}`);
}