docs: add bilingual guides and English API descriptions
This commit is contained in:
1 parent
1e9e0678ee
commit
a874a39ea5
12 files changed
+991
-582
No files matched your search
+51
-49
@@ -1,16 +1,18 @@
|
||||
# 开发指南
|
||||
# Development guide
|
||||
|
||||
[返回项目首页](../README.zh-CN.md) · [API 与认证](api.md) · [项目约束](../AGENTS.md)
|
||||
**English** · [简体中文](development.zh-CN.md)
|
||||
|
||||
## 工具链
|
||||
[Project home](../README.md) · [API and authentication](api.md) · [Project instructions](../AGENTS.md)
|
||||
|
||||
- Go 1.27.2 或更高版本,具体要求见 [go.mod](../go.mod)。
|
||||
- Node.js 24+、pnpm **12.11.2**;前端依赖以 [pnpm-lock.yaml](../web/pnpm-lock.yaml) 为准。
|
||||
- Docker 仅在验证容器构建或部署时需要,本地开发不强制使用。
|
||||
## Toolchain
|
||||
|
||||
前端采用 Vue 3、TypeScript、Vite、Router、Pinia、Element Plus、Axios、SCSS 与 UnoCSS;编辑器使用 CodeMirror 6。服务端使用 Go 标准库 HTTP、SQLite 与文件系统;Markdown 文件是真源,搜索索引可以重建。
|
||||
- Go 1.27.2 or later; see [go.mod](../go.mod) for the requirement.
|
||||
- Node.js 24+ and pnpm **12.11.2**. Frontend dependencies follow [pnpm-lock.yaml](../web/pnpm-lock.yaml).
|
||||
- Docker is needed only for container build verification or deployment, not for local development.
|
||||
|
||||
## 启动本地开发
|
||||
The frontend uses Vue 3, TypeScript, Vite, Router, Pinia, Element Plus, Axios, SCSS, and UnoCSS, with CodeMirror 6 for editing. The backend uses Go's standard HTTP library, SQLite, and the filesystem. Markdown files are the source of truth; the search index can be rebuilt.
|
||||
|
||||
## Start local development
|
||||
|
||||
```sh
|
||||
corepack enable
|
||||
@@ -18,50 +20,50 @@ corepack prepare [email protected] --activate
|
||||
scripts/dev.sh
|
||||
```
|
||||
|
||||
脚本使用锁文件安装前端依赖,同时启动 Go 开发服务和 Vite 热更新。打开 http://localhost:5173,首次访问初始化密码;Ctrl+C 同时退出。
|
||||
The script installs frontend dependencies from the lockfile and starts the Go development service and Vite with hot updates. Open http://localhost:5173 and initialize a password on first use. Ctrl+C stops both services.
|
||||
|
||||
```sh
|
||||
scripts/dev.sh --host # 允许局域网设备访问前端
|
||||
scripts/dev.sh --host # Allow LAN devices to access the frontend
|
||||
scripts/dev.sh --help
|
||||
```
|
||||
|
||||
`RAWMARK_DATA` 默认指向仓库的 `.dev-data/`,`API_PORT` 默认 8080,`WEB_PORT` 默认 5173。可通过环境变量覆盖,例如 `API_PORT=18080 WEB_PORT=15173 scripts/dev.sh`。不要将开发服务指向生产数据;初始化、恢复、导入和删除测试只使用合成数据。
|
||||
`RAWMARK_DATA` defaults to the repository's `.dev-data/`, `API_PORT` to 8080, and `WEB_PORT` to 5173. Override them through environment variables, for example `API_PORT=18080 WEB_PORT=15173 scripts/dev.sh`. Do not point a development service at production data. Use synthetic data for initialization, restore, import, and deletion tests.
|
||||
|
||||
开发模式从源码统计可选字体,日志版本显示为 `dev`,不读取旧 `web/dist`。生产模式使用嵌入的前端构建、字体清单和构建版本。
|
||||
Development mode calculates optional-font sizes from source, reports the log version as `dev`, and does not read an old `web/dist`. Production mode uses the embedded frontend build, font manifest, and build version.
|
||||
|
||||
## 目录职责
|
||||
## Directory responsibilities
|
||||
|
||||
```text
|
||||
cmd/rawmark/ 服务入口
|
||||
cmd/rawmark/ Service entry point
|
||||
internal/
|
||||
api/ HTTP 路由、授权、协议及 OpenAPI
|
||||
auth/ 密码、会话与 API 凭据
|
||||
store/ 应用 SQLite
|
||||
vault/ 真源笔记、附件与文件操作
|
||||
search/ 可重建的派生索引
|
||||
api/ HTTP routes, authorization, contracts, and OpenAPI
|
||||
auth/ Passwords, sessions, and API credentials
|
||||
store/ Application SQLite storage
|
||||
vault/ Source notes, attachments, and file operations
|
||||
search/ Rebuildable derived index
|
||||
web/
|
||||
src/
|
||||
pages/login/ 初始化与验证码登录
|
||||
pages/workspace/ 笔记、目录、编辑器与图片管理
|
||||
pages/settings/ 设置、账户与维护
|
||||
common/apis/ 全部资源 API
|
||||
common/components/ 跨模块公共组件
|
||||
common/ 共享外观、Markdown、插件 SDK 与工具
|
||||
http/ Axios、认证头、统一响应与错误
|
||||
router/ 路由与守卫
|
||||
pinia/ 实例及共享认证、权限、设置状态
|
||||
types/auto/ 自动生成的导入声明
|
||||
deploy/ 容器与代理配置
|
||||
scripts/ 开发、资源生成及历史迁移脚本
|
||||
pages/login/ Initialization and captcha sign-in
|
||||
pages/workspace/ Notes, tree, editor, and image management
|
||||
pages/settings/ Settings, account, and maintenance
|
||||
common/apis/ All resource APIs
|
||||
common/components/ Components shared across modules
|
||||
common/ Shared appearance, Markdown, plugin SDK, and utilities
|
||||
http/ Axios, auth headers, responses, and errors
|
||||
router/ Routes and guards
|
||||
pinia/ Pinia instance and shared auth, permission, settings state
|
||||
types/auto/ Generated import declarations
|
||||
deploy/ Container and proxy configuration
|
||||
scripts/ Development, resource generation, historical migrations
|
||||
```
|
||||
|
||||
页面私有组件、类型、状态、组合函数和资源跟随 `pages/<module>/`,确实跨模块复用的能力才进入 `common`;公共代码不得依赖页面私有实现。模块内优先相对导入,跨职责用 `@`(`web/src`)与 `@@`(`web/src/common`)。
|
||||
Page-private components, types, state, composables, and assets belong to `pages/<module>/`. Only capabilities reused across modules belong in `common`, which must not depend on page-private implementations. Prefer relative imports within modules; use `@` (`web/src`) and `@@` (`web/src/common`) across responsibilities.
|
||||
|
||||
全部资源接口位于 `common/apis/<resource>/index.ts` 和 `type.ts`。函数直接调用 `request<ResponseData>({ url, method, data, params })`,返回完整 `{ code, data, message }`,调用方显式读取 `.data`。原文/下载设置 `returnResponse: true` 保留 Axios 响应与响应头,204 返回 void,事件连接也归资源 API。不增加页面私有请求入口或多格式 fallback。
|
||||
All resource APIs live in `common/apis/<resource>/index.ts` and `type.ts`. Functions call `request<ResponseData>({ url, method, data, params })` directly and return the complete `{ code, data, message }` envelope; callers explicitly read `.data`. Raw-text/download requests use `returnResponse: true` to preserve Axios responses and headers; 204 returns void. Event connections also belong to the resource API. Do not add page-private request entry points or fallbacks for multiple response formats.
|
||||
|
||||
公共组件放在 `common/components/<PascalCaseName>/index.vue`。SFC 使用 Composition API 与 TypeScript,其他文件使用 kebab-case。自动声明应修改生成配置后重新构建,不手工编辑。更完整的执行约束以根 [AGENTS.md](../AGENTS.md) 为准,不另维护一套规范。
|
||||
Shared components use `common/components/<PascalCaseName>/index.vue`. SFCs use the Composition API and TypeScript; other files use kebab-case. Change generation configuration and rebuild automatic declarations rather than editing them by hand. The root [AGENTS.md](../AGENTS.md), in Simplified Chinese, is the authoritative source of project instructions; do not maintain a second rule set.
|
||||
|
||||
## 验证
|
||||
## Verification
|
||||
|
||||
```sh
|
||||
pnpm -C web install --frozen-lockfile
|
||||
@@ -74,34 +76,34 @@ go test ./internal/...
|
||||
go test -tags dev ./web
|
||||
```
|
||||
|
||||
前端使用 Vitest,测试随模块存放;Go 使用标准 `testing`。生产构建需先生成 `web/dist`,Go 再将其嵌入二进制。`-tags dev` 保留无需嵌入产物的开发和对应测试边界。
|
||||
Frontend tests use Vitest and live alongside their modules. Go uses standard `testing`. Generate `web/dist` before a production Go build so it can be embedded in the binary. The `-tags dev` boundary allows development and corresponding tests without embedded build output.
|
||||
|
||||
按改动风险补充 Go race、Docker 构建及真实浏览器验收。认证与请求变更应覆盖验证码成功/失败/过期、401 与 403、服务端注销以及旧会话响应隔离;编辑器与文件操作应核对原文保存、版本冲突、附件及移动/导入/导出。不用空数据或模拟成功掩盖失败。
|
||||
Add Go race checks, Docker builds, and real-browser acceptance checks according to risk. Authentication and request changes should cover captcha success/failure/expiry, 401 versus 403, server-side logout, and isolation of old-session responses. Editor and file changes should verify original-text preservation, version conflicts, attachments, and move/import/export behavior. Do not hide failures behind empty data or simulated success.
|
||||
|
||||
## 主题、字体与插件
|
||||
## Themes, fonts, and plugins
|
||||
|
||||
内置默认、白色与黑色主题,保留独立明暗模式和 CSS 片段。自定义主题位于数据目录 `themes/<id>/`,包含 `manifest.json` 与 `theme.css`;清单包含 `id`、`name`、`version`,ID 与目录一致,不能覆盖保留的 `default`、`white`、`black`。在外观设置刷新列表后选择。
|
||||
The built-in themes are default, white, and black; separate light/dark mode and CSS snippets are retained. Custom themes live in the data directory's `themes/<id>/` with `manifest.json` and `theme.css`. The manifest includes `id`, `name`, and `version`; the ID must match the directory and cannot override reserved IDs `default`, `white`, or `black`. Refresh the theme list in appearance settings to select one.
|
||||
|
||||
默认字体资源已入库,常规构建无需下载或转换。重新生成时,在独立 Python 环境安装 `fonttools[woff]`,下载 [Maple v7.9 指定字体包](https://github.com/subframe7536/maple-font/releases/download/v7.9/MapleMonoNormalNL-NF-CN.zip),执行:
|
||||
Default font resources are checked in; ordinary builds require no download or conversion. To regenerate them, install `fonttools[woff]` in an isolated Python environment, download the [specified Maple v7.9 archive](https://github.com/subframe7536/maple-font/releases/download/v7.9/MapleMonoNormalNL-NF-CN.zip), and run:
|
||||
|
||||
```sh
|
||||
python3 scripts/prepare-maple-font.py /path/to/MapleMonoNormalNL-NF-CN.zip
|
||||
```
|
||||
|
||||
脚本生成 WOFF2 和 `maple-font.css`,保留上游许可。代码块使用 highlight.js 的固定 Atom One Dark,不能在更新主题时顺带恢复旧高亮实现或配色。
|
||||
The script generates WOFF2 files and `maple-font.css` while retaining the upstream license. Code blocks use highlight.js with fixed Atom One Dark; theme changes must not reintroduce previous highlighters or color schemes.
|
||||
|
||||
插件 SDK 类型见 [common/plugin-api/index.d.ts](../web/src/common/plugin-api/index.d.ts),加载与生命周期实现位于 `common/plugins/`。插件仅在前端运行,安装者必须信任其代码;命名空间、停用及资源版本管理不等于权限沙箱。编辑器扩展故障时保留正文并停用当前页相关扩展。
|
||||
Plugin SDK types are in [common/plugin-api/index.d.ts](../web/src/common/plugin-api/index.d.ts); loading and lifecycle code lives in `common/plugins/`. Plugins run only on the frontend, and installers must trust their code. Namespaces, disabling, and resource versioning do not constitute a permission sandbox. Editor-extension failures preserve document contents and disable the relevant extensions on the current page.
|
||||
|
||||
## 提交改动
|
||||
## Contributing changes
|
||||
|
||||
先阅读 [AGENTS.md](../AGENTS.md),聚焦实际需求,保留必要契约,不机械照搬模板示例。前端目录以 [vue3-starter 固定基线](https://github.com/eezd/vue3-starter/tree/fd41d62ce3f1c8338a478e0be3e2f31b53b7ea5e) 为参考,RawMark 的编辑器、主题和专用交互按业务保留。
|
||||
Read [AGENTS.md](../AGENTS.md) first. Focus on real requirements, preserve necessary contracts, and do not mechanically copy template examples. Frontend organization references the [fixed vue3-starter baseline](https://github.com/eezd/vue3-starter/tree/fd41d62ce3f1c8338a478e0be3e2f31b53b7ea5e); RawMark's editor, themes, and specialized interactions remain where the application needs them.
|
||||
|
||||
提交前运行适用检查,说明实际验证与未验证范围。Commit 使用清晰英文,按功能拆分;不要提交真实笔记、账户数据、密钥或本地交接文件。
|
||||
Run applicable checks before committing and state what was and was not verified. Write clear English commit messages and split commits by function. Do not commit real notes, account data, secrets, or local handoff files.
|
||||
|
||||
## 多语言
|
||||
## Internationalization
|
||||
|
||||
使用 Vue I18n Composition API,支持 `en` 与 `zh-CN`,默认英文。公共字典位于 `web/src/common/i18n/`,模块私有字典位于 `pages/<module>/locales/`,应用 `src/i18n.ts` 装配字典;不要用中文原文作为运行时查找键,也不要从公共模块导入页面字典。模板及命令、设置搜索等长期对象在使用时翻译;日期、数字和排序读取当前语言。
|
||||
Vue I18n Composition API supports `en` and `zh-CN`, defaulting to English. Shared dictionaries live in `web/src/common/i18n/`; module-private dictionaries live in `pages/<module>/locales/`. The application assembles them in `src/i18n.ts`. Do not use Chinese source text as runtime lookup keys or import page dictionaries from shared modules. Translate templates and long-lived objects such as commands and settings search entries at use time. Dates, numbers, and sorting use the current locale.
|
||||
|
||||
账户语言沿用 settings store 的串行写入、服务器设置与事件同步;登录页仅更新本机启动缓存,认证后读取服务器值。CodeMirror 使用 locale Compartment 更新控件,不替换文档、选区或撤销历史。用户正文、现有路径和插件提供的文字保持原样。
|
||||
Account language reuses the settings store's serial writes, server settings, and event synchronization. The sign-in page updates only the local startup cache; authentication loads the server value. CodeMirror updates controls through a locale Compartment without replacing the document, selection, or undo history. User content, existing paths, and plugin-supplied text remain unchanged.
|
||||
|
||||
后端 `internal/i18n/` 保存消息 ID 与参数,错误在 HTTP 边界根据 `Accept-Language` 渲染,并保留 `errors.Is/As` 及原始诊断;日志遵循原有语言。既有索引警告只在需要时重新分析源笔记生成译文,同时更新该条目的完整元数据和版本,不改索引格式;已删除或移动的过期条目跳过,其他读取错误明确返回。新增文案同时补充中英字典与参数,运行字典完整性、设置同步、编辑器和 API 的相应测试。
|
||||
Backend `internal/i18n/` preserves message IDs and parameters. Errors render at the HTTP boundary according to `Accept-Language`, retaining `errors.Is/As` and original diagnostics; logs keep their existing language. Existing index warnings are reanalyzed from source notes only when needed for translation, refreshing the entry's complete metadata and revision without changing the index format. Stale entries for deleted or moved notes are skipped; other read errors fail explicitly. Add both languages and interpolation parameters for new messages and run the corresponding dictionary-completeness, settings-sync, editor, and API tests.
|
||||
Reference in new issue
Block a user