Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ This project started as a rewrite of a few small Java + Vue 2 systems at work. R

The backend, the web admin console, a desktop template, a mobile template and the docs site live in one pnpm + turbo monorepo: install once, and one `pnpm dev` starts backend and frontend.

This pays off most when coding with AI: when it changes an API, the backend, the generated frontend/backend contract and the pages that call it are all in view, so the change lands in one PR; CI then runs repo-wide type checks, a contract-freshness check and an architecture check (dependency direction `i18n ← ui ← platform ← web`) on that PR.

```
apps/
├── api backend · FastAPI + Celery
Expand Down
2 changes: 2 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ AI 让写代码变快了,要做的系统反而更多了:排不上队的小

后端、Web 后台、桌面端模板、移动端模板和文档站都在一个 pnpm + turbo monorepo 里:一次安装,`pnpm dev` 一条命令起前后端。

这对和 AI 一起写代码尤其有用:AI 改一个接口,后端、生成的前后端契约和调用它的页面都在它眼前,一个 PR 改完;CI 对这个 PR 跑全仓的类型检查、契约新鲜度检查和架构检查(依赖方向 `i18n ← ui ← platform ← web`)。

```
apps/
├── api 后端 · FastAPI + Celery
Expand Down
98 changes: 90 additions & 8 deletions apps/docs/AGENTS.md

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion apps/docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,29 @@ export default defineConfig({
logo: { src: './src/assets/logo.svg' },
favicon: '/favicon.svg',
// 主题和后台同一套:Inter / JetBrains Mono 自托管(不走 Google Fonts —— 国内打不开),品牌紫见 theme.css
customCss: ['@fontsource-variable/inter', '@fontsource-variable/jetbrains-mono', './src/styles/theme.css'],
// 字阶(typography.css)先于配色(theme.css):后者用到前者的字重 token
customCss: ['@fontsource-variable/inter', '@fontsource-variable/jetbrains-mono', './src/styles/typography.css', './src/styles/theme.css'],
// 代码块:去掉终端那条带三个点的灰标题栏(frame: 'code' 且没写标题时不出标题栏),
// 边框和底色跟表格同一套中性灰,字号走字阶的 13px(typography.css 的 --fs-xs)
expressiveCode: {
defaultProps: { frame: 'code' },
styleOverrides: {
borderRadius: '0.6rem',
borderColor: 'var(--sl-color-gray-5)',
codeBackground: 'var(--sl-color-gray-7)',
codeFontSize: 'var(--fs-xs)',
codeLineHeight: '1.7',
uiFontSize: 'var(--fs-2xs)',
frames: {
frameBoxShadowCssValue: 'none',
editorBackground: 'var(--sl-color-gray-7)',
editorTabBarBackground: 'var(--sl-color-gray-7)',
editorActiveTabBackground: 'var(--sl-color-gray-7)',
terminalBackground: 'var(--sl-color-gray-7)',
terminalTitlebarBackground: 'var(--sl-color-gray-7)',
},
},
},
// 首页 hero 换成登录页那套品牌面板 + 立体榫卯(src/components/Hero.astro)
// 顶栏的主题切换是一个图标按钮 + 「浅色 / 深色 / 跟随系统」菜单(src/components/ThemeSelect.astro)
components: {
Expand All @@ -96,6 +118,8 @@ export default defineConfig({
// 语言切换不用原生 <select>;内页标题下加「复制 Markdown / 打开方式」
LanguageSelect: './src/components/LangSelect.astro',
PageTitle: './src/components/PageTitle.astro',
// 右侧「本页内容」:阶梯轨道线 + 屏幕里露着的那几节一起高亮
TableOfContents: './src/components/DocsToc.astro',
},
social: [{ icon: 'github', label: 'GitHub', href: REPO }],
editLink: { baseUrl: `${REPO}/edit/main/apps/docs/` },
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"start": "astro dev",
"build": "astro build && node scripts/check-links.mjs",
"build": "astro build && node scripts/check-links.mjs && node scripts/check-type.mjs && node scripts/check-headings.mjs",
"preview": "astro preview",
"og": "node scripts/gen-og.mjs"
},
Expand Down
63 changes: 63 additions & 0 deletions apps/docs/scripts/check-headings.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env node
/**
* 标题闸门:正文里的 h2 / h3 / h4 要写成短的名词短语,不写问句。接在 `build` 后面,PR 的 CI 就会红。
*
* 为什么要它:2026-11-26 之前标题按「写成人会问的问题」的规矩写,一页十几条「…怎么…?」「…吗?」,
* 在右侧目录里折成两三行,读者扫一眼读不出这节讲什么(用户原话:长得让人没有读的欲望)。
* 一次改了全站 698 条;不设闸门的话,下一篇新文档又会照老习惯写回问句。
*
* 规则(和 AGENTS.md「写内容」一节同一份):
* - 不带问号(? / ?)
* - 中文 h2 ≤ 8 字、h3/h4 ≤ 10 字(常见问题页 ≤ 12);英文单词、数字、括号里的缩写各按 1 个字算,开头的「1. 」不算
* - 英文 h2 ≤ 4 个词、h3/h4 ≤ 5 个词(常见问题页 ≤ 6)
* 代码块里的 `#` 行不算标题。
*/
import { readFileSync, readdirSync } from 'node:fs'
import { dirname, join, relative, sep } from 'node:path'
import { fileURLToPath } from 'node:url'

const ROOT = join(dirname(fileURLToPath(import.meta.url)), '../src/content/docs')
const files = readdirSync(ROOT, { recursive: true, withFileTypes: true })
.filter((e) => e.isFile() && /\.mdx?$/.test(e.name)).map((e) => join(e.parentPath, e.name))

/** 中文长度:英文词 / 数字 / 括号缩写各算 1,空格不算 */
const zhLength = (t) => t
.replace(/`([^`]*)`/g, '$1')
.replace(/([A-Za-z0-9/+ -]+)/g, 'X')
.replace(/[A-Za-z0-9][A-Za-z0-9.+/_-]*/g, 'X')
.replace(/\s+/g, '').length

const problems = []
let count = 0
for (const file of files) {
const rel = relative(ROOT, file).split(sep).join('/')
const en = rel.startsWith('en/')
const faq = rel.endsWith('reference/faq.md')
let fence = false
readFileSync(file, 'utf8').split('\n').forEach((line, i) => {
if (/^\s*(```|~~~)/.test(line)) { fence = !fence; return }
if (fence) return
const m = line.match(/^(#{2,4})\s+(.*?)\s*$/)
if (!m) return
count++
const level = m[1].length
const text = m[2].replace(/^\d+\.\s*/, '')
const where = `src/content/docs/${rel}:${i + 1} ${m[1]} ${m[2]}`
if (/[??]/.test(text)) { problems.push(`${where} —— 不写问句`); return }
if (en) {
const words = text.split(/\s+/).filter(Boolean).length
const max = level === 2 ? 4 : faq ? 6 : 5
if (words > max) problems.push(`${where} —— ${words} 个词,上限 ${max}`)
} else {
const n = zhLength(text)
const max = level === 2 ? 8 : faq ? 12 : 10
if (n > max) problems.push(`${where} —— ${n} 个字,上限 ${max}`)
}
})
}

if (problems.length) {
console.error(`标题检查没过(${problems.length} 处):标题写成短的名词短语,见 apps/docs/AGENTS.md「写内容」\n ${problems.join('\n ')}`)
process.exit(1)
}
console.log(`标题:${files.length} 页 · ${count} 条 · 0 处越界`)
61 changes: 61 additions & 0 deletions apps/docs/scripts/check-type.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env node
/**
* 字阶闸门:内页用到的样式里,字号只能取 typography.css 的 7 级(`var(--fs-*)`),
* 字重只能是 400 / 500 / 600 三档(`var(--fw-*)`)。接在 `build` 后面,所以 PR 的 CI 就会红。
*
* 为什么要它:2026-11-26 统一字阶之前,内页实测出现 13 种字号(11.52 / 12.8 / 13 / 14.4 / 16.8 …)
* 和 6 档字重(含 650 / 700 / 800)—— 每一处都是某个组件里随手写的 `0.8rem`、`font-weight: 650`,
* 单看都合理,合起来就是「字有大有小、看着累」。这种漂移构建和链接检查全都放行。
*
* 只查源码,不渲染页面:漂移的来源就是源码里的字面量,查源码不用在 CI 里装浏览器。
* 渲染后的实际字号用 ego / Playwright 另外核对过(见 AGENTS.md「字阶与配色」)。
*
* 豁免:
* - 首页专用的展示组件(HOME_ONLY):落地页有自己的展示字号。脚本同时核对它们**只**被首页引用,
* 哪天被功能页 import 了,就得先按字阶改掉再移出这张表
* - 某一行确实不是文字(比如按钮里的 × 图标):行尾写 `type-ok: 原因`
*/
import { readFileSync, readdirSync } from 'node:fs'
import { dirname, join, relative, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'

const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
const HOME_ONLY = [
'Closing', 'DiagramAiGuard', 'DiagramDataScope', 'DiagramMonorepo', 'FeatureLine', 'Hero', 'HomeHeader',
'ProductTour', 'SectionTitle', 'Showcase', 'TenonStage',
]
const SIZE_OK = /^(var\(--(fs|sl-text)-[\w-]+\)|inherit)$/
const WEIGHT_OK = /^(var\(--fw-[\w-]+\)|400|500|600|normal|inherit)$/

const files = (dir, ext) => readdirSync(join(ROOT, dir), { recursive: true, withFileTypes: true })
.filter((e) => e.isFile() && ext.test(e.name)).map((e) => join(e.parentPath, e.name))

const problems = []
const styleFiles = [...files('src/styles', /\.css$/), ...files('src/components', /\.astro$/)]
.filter((f) => !HOME_ONLY.some((name) => f.endsWith(`/${name}.astro`)))
for (const file of styleFiles) {
readFileSync(file, 'utf8').split('\n').forEach((line, i) => {
if (line.includes('type-ok:')) return
for (const [, prop, value] of line.matchAll(/(?<![\w-])(font-size|font-weight)\s*:\s*([^;}]+)/g)) {
const v = value.trim().replace(/\s*!important$/, '')
if (!(prop === 'font-size' ? SIZE_OK : WEIGHT_OK).test(v)) {
problems.push(`${relative(ROOT, file)}:${i + 1} ${prop}: ${v} —— ${prop === 'font-size' ? '用 var(--fs-*)' : '只用 400 / 500 / 600(var(--fw-*))'}`)
}
}
})
}

// 首页专用组件不能出现在功能页里(首页是 content/docs 下的 index.mdx 和 en/index.mdx)
for (const file of files('src/content/docs', /\.mdx$/)) {
const rel = relative(join(ROOT, 'src/content/docs'), file)
if (rel === 'index.mdx' || rel === 'en/index.mdx') continue
for (const [, name] of readFileSync(file, 'utf8').matchAll(/^import\s+(\w+)\s+from\s+['"][^'"]*components\//gm)) {
if (HOME_ONLY.includes(name)) problems.push(`src/content/docs/${rel} 引用了首页专用的 ${name}:先按字阶改掉它,再从 check-type.mjs 的 HOME_ONLY 里移出`)
}
}

if (problems.length) {
console.error(`字阶检查没过(${problems.length} 处),字阶见 src/styles/typography.css:\n ${problems.join('\n ')}`)
process.exit(1)
}
console.log(`字阶:${styleFiles.length} 个样式文件 · 0 处越界`)
Loading