Skip to content

Commit 649db86

Browse files
authored
Merge pull request #35 from objectstack-ai/copilot/refactor-website-documentation
2 parents 42e24fc + 3ad7f0f commit 649db86

File tree

9 files changed

+279
-116
lines changed

9 files changed

+279
-116
lines changed

README.md

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ npx @objectdocs/cli init
6565
```
6666

6767
This will:
68-
- Create `content/package.json` with necessary scripts
69-
- Copy the site engine to `content/.objectdocs`
70-
- Install dependencies in `content/.objectdocs/node_modules`
68+
- Copy the site engine from `@objectdocs/site` to `content/.objectdocs`
69+
- Create `content/package.json` with scripts (`dev`, `build`, `start`)
70+
- Install dependencies in `content/.objectdocs`
7171
- Automatically add `content/.objectdocs` and `content/node_modules` to `.gitignore`
7272
- Keep your project root clean and unpolluted
7373

@@ -99,38 +99,17 @@ cd content && npm run dev
9999

100100
Visit http://localhost:7777 to see your site.
101101

102-
### Option 2: New Standalone Project
102+
### Option 2: Use npm init
103103

104-
For a new dedicated documentation project:
104+
For a quick start with automatic initialization:
105105

106106
```bash
107107
mkdir my-docs
108108
cd my-docs
109-
npm init -y
110-
npm install -D @objectdocs/cli
109+
npm init @objectdocs
111110
```
112111

113-
Add scripts to your root `package.json`:
114-
115-
```json
116-
{
117-
"scripts": {
118-
"dev": "cd content && npm run dev",
119-
"build": "cd content && npm run build",
120-
"start": "cd content && npm run start"
121-
}
122-
}
123-
```
124-
125-
Initialize ObjectDocs:
126-
127-
```bash
128-
npm run init
129-
# or
130-
npx objectdocs init
131-
```
132-
133-
Then follow the same steps as Option 1 to add content.
112+
This runs the init command automatically. Then follow the same steps as Option 1 to add content.
134113

135114
## 🏗️ Project Structure
136115

@@ -139,19 +118,24 @@ ObjectDocs enforces a clear directory structure to ensure maintainability at sca
139118
```text
140119
.
141120
├── content/ # [Data Layer] All documentation files
142-
│ ├── package.json # npm scripts (dev, build, start)
143-
│ ├── .objectdocs/ # Site engine (auto-generated, gitignored)
144-
│ ├── docs.site.json # Global settings (Nav, Logo, Branding)
121+
│ ├── package.json # Scripts: dev, build, start (created by init)
122+
│ ├── .objectdocs/ # Site engine (copied from @objectdocs/site, gitignored)
123+
│ │ ├── node_modules/ # Dependencies (installed during init)
124+
│ │ ├── .next/ # Next.js build cache (development)
125+
│ │ └── out/ # Static build output (production)
126+
│ ├── docs.site.json # Global config (Nav, Logo, Branding, i18n)
145127
│ └── docs/
146-
│ ├── meta.json # Directory structure & sorting control
128+
│ ├── meta.json # Directory structure & page order
147129
│ └── index.mdx # Documentation content
130+
├── out/ # Final build output (copied from content/.objectdocs/out)
148131
├── package.json # (Optional) Root project package.json
149132
└── ...
150133
```
151134

152135
**Key Points:**
153136
- All documentation-related files are in `content/`
154-
- `content/.objectdocs/` is auto-generated and gitignored
137+
- `content/.objectdocs/` contains the complete Next.js site engine (auto-generated, gitignored)
138+
- Build output: `content/.objectdocs/out` → copied to root `out/` directory
155139
- Your project root remains clean
156140
- Perfect for adding docs to any existing project
157141

@@ -161,7 +145,7 @@ ObjectDocs is designed to be "Configuration as Code".
161145

162146
### Global Config (`content/docs.site.json`)
163147

164-
Manage global navigation, branding, and feature flags:
148+
Manage global navigation, branding, i18n, and feature flags:
165149

166150
```json
167151
{
@@ -175,10 +159,19 @@ Manage global navigation, branding, and feature flags:
175159
"links": [
176160
{ "text": "Guide", "url": "/docs" },
177161
{ "text": "GitHub", "url": "https://github.com/objectstack-ai", "icon": "github" }
178-
]
162+
],
163+
"i18n": {
164+
"defaultLanguage": "en",
165+
"languages": ["en", "zh-CN", "ja", "es", "fr", "de", "ko", "ru", "pt", "ar", "hi", "it", "tr", "vi"]
166+
}
179167
}
180168
```
181169

170+
**Supported Features:**
171+
- 14 languages for internationalization
172+
- Automatic config watching and hot reload during development
173+
- Config is copied to `content/.objectdocs` before each build/dev command
174+
182175
### Sidebar Control (`content/**/meta.json`)
183176

184177
Control the sidebar order and structure using local metadata files in each directory:

content/docs/getting-started/architecture.cn.mdx

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,77 @@ ObjectDocs 建立在严格的 **关注点分离 (Separation of Concerns)** 理
3030

3131
## 目录结构
3232

33-
一个标准的 ObjectDocs 项目结构如下
33+
初始化后的标准 ObjectDocs 项目结构
3434

3535
```text
3636
.
37-
├── content/ # [数据层] 原始内容
38-
│ ├── docs.site.json # 全局设置 (导航, Logo, 品牌)
37+
├── content/ # [数据层] 所有文档文件
38+
│ ├── package.json # 脚本: dev, build, start (由 init 创建)
39+
│ ├── .objectdocs/ # 站点引擎 (从 @objectdocs/site 复制, gitignored)
40+
│ │ ├── node_modules/ # 依赖 (初始化时安装)
41+
│ │ ├── .next/ # Next.js 构建缓存 (开发)
42+
│ │ └── out/ # 静态构建输出 (生产)
43+
│ ├── docs.site.json # 全局配置 (导航, Logo, 品牌, i18n)
44+
│ ├── public/ # 静态资源 (在构建/开发时复制到站点)
3945
│ └── docs/
40-
│ ├── meta.json # 目录结构 & 排序控制
46+
│ ├── meta.json # 目录结构 & 页面顺序
4147
│ └── index.mdx # 文档内容
42-
├── package.json
43-
└── public/ # 静态资源 (图片等)
48+
├── out/ # 最终构建输出 (从 content/.objectdocs/out 复制)
49+
├── .gitignore # 自动更新以排除 content/.objectdocs
50+
├── package.json # (可选) 根目录 package.json
51+
└── ...
4452
```
4553

54+
**核心组件:**
55+
- **`content/.objectdocs/`**: 包含来自 `@objectdocs/site` 包的完整 Next.js 站点引擎
56+
- **`content/package.json`**: 由 init 命令创建,包含 dev/build/start 脚本
57+
- **构建流程**: `content/.objectdocs/out``out/` (根目录)
58+
- **环境**: 命令在 `content/.objectdocs` 内运行,`DOCS_DIR` 环境变量指向文档目录
59+
4660
## 数据流向
4761

48-
1. **构建时**: `@objectdocs/site` 读取 `content/` 下的所有 MDX 和 JSON 文件。
49-
2. **解析**: Fumadocs 引擎解析元数据,构建导航树。
50-
3. **渲染**: Next.js (App Router) 将内容渲染为 React Server Components。
51-
4. **交互**: 客户端组件(如 `<Cards>`, `<Steps>`)在浏览器中激活。
62+
### 初始化流程
63+
1. **初始化命令**: `npx @objectdocs/cli init`
64+
2. **包复制**: 整个 `@objectdocs/site` 包 → `content/.objectdocs`
65+
3. **脚本创建**: 创建 `content/package.json` 并添加 dev/build/start 脚本
66+
4. **依赖安装**: 在 `content/.objectdocs` 中运行 `npm install`
67+
5. **Gitignore 更新**: 添加排除生成文件的规则
68+
69+
### 开发流程
70+
1. **启动**: 运行 `cd content && npm run dev`
71+
2. **配置同步**: 复制 `docs.site.json``public/``content/.objectdocs`
72+
3. **环境**: 设置 `DOCS_DIR` 环境变量指向 `content/docs`
73+
4. **监听**: 监控 `docs.site.json` 的变化并自动重启
74+
5. **服务器**: Next.js 开发服务器在端口 7777 上运行(默认)
75+
76+
### 构建流程
77+
1. **构建时**: 运行 `cd content && npm run build`
78+
2. **配置同步**: 复制 `docs.site.json``public/``content/.objectdocs`
79+
3. **环境**: 设置 `DOCS_DIR` 环境变量
80+
4. **MDX 解析**: Fumadocs 从 `DOCS_DIR` 读取所有 `.mdx` 文件
81+
5. **元数据**: 解析 `meta.json` 文件构建导航树
82+
6. **渲染**: Next.js App Router 将内容渲染为 React Server Components
83+
7. **输出**:
84+
- 静态模式: `content/.objectdocs/out``out/` (根目录)
85+
- 动态模式: `content/.objectdocs/.next``.next/` (根目录)
86+
87+
### 运行流程 (静态)
88+
1. **服务**: 从 `out/` 目录提供生产构建
89+
2. **资源**: 静态 HTML、CSS、JS 和图片
90+
3. **CDN**: 可以部署到 Vercel、Netlify 或任何静态托管
91+
92+
### 运行流程 (动态)
93+
1. **启动**: 运行 `cd content && npm run start`
94+
2. **服务器**: 具有 ISR/SSR 功能的 Next.js 生产服务器
95+
3. **交互**: 客户端组件(如 `<Cards>`, `<Steps>`)在浏览器中激活
5296

5397
### 为什么这样设计?
5498

5599
这种架构使得我们能够:
56100

57-
* **多产品支持**: 通过切换不同的 `content` 目录,可以在同一套代码库中支持多个产品的文档。
58-
* **低代码集成**: 因为内容与 UI 分离,我们可以更容易地注入动态的低代码组件演示。
101+
* **清晰分离**: 将文档内容与站点引擎完全分离
102+
* **项目无关**: 可以在任何现有项目中添加文档而不污染根目录
103+
* **版本控制**: 整个站点引擎都被 gitignore,只跟踪内容
104+
* **多产品支持**: 通过切换不同的 `content` 目录,可以支持多个产品的文档
105+
* **低代码集成**: 因为内容与 UI 分离,我们可以更容易地注入动态的低代码组件演示
106+
* **轻松更新**: 通过重新运行 init 或更新 CLI 版本来更新站点引擎

content/docs/getting-started/architecture.mdx

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,77 @@ Each documentation directory is self-contained. If you want to add a new section
3030

3131
## Directory Structure
3232

33-
A standard ObjectDocs project structure looks like this:
33+
A standard ObjectDocs project structure after initialization:
3434

3535
```text
3636
.
37-
├── content/ # [Data Layer] Raw Content
38-
│ ├── docs.site.json # Global settings (Nav, Logo, Branding)
37+
├── content/ # [Data Layer] All documentation files
38+
│ ├── package.json # Scripts: dev, build, start (created by init)
39+
│ ├── .objectdocs/ # Site engine (copied from @objectdocs/site, gitignored)
40+
│ │ ├── node_modules/ # Dependencies (installed during init)
41+
│ │ ├── .next/ # Next.js build cache (development)
42+
│ │ └── out/ # Static build output (production)
43+
│ ├── docs.site.json # Global config (Nav, Logo, Branding, i18n)
44+
│ ├── public/ # Static assets (copied to site during build/dev)
3945
│ └── docs/
40-
│ ├── meta.json # Directory structure & sorting control
46+
│ ├── meta.json # Directory structure & page order
4147
│ └── index.mdx # Documentation content
42-
├── package.json
43-
└── public/ # Static assets (images, etc.)
48+
├── out/ # Final build output (copied from content/.objectdocs/out)
49+
├── .gitignore # Auto-updated to exclude content/.objectdocs
50+
├── package.json # (Optional) Root project package.json
51+
└── ...
4452
```
4553

54+
**Key Components:**
55+
- **`content/.objectdocs/`**: Contains the complete Next.js site engine from `@objectdocs/site` package
56+
- **`content/package.json`**: Created by init command with dev/build/start scripts
57+
- **Build Flow**: `content/.objectdocs/out``out/` (root directory)
58+
- **Environment**: Commands run inside `content/.objectdocs` with `DOCS_DIR` env variable pointing to docs
59+
4660
## Data Flow
4761

48-
1. **Build Time**: `@objectdocs/site` reads all MDX and JSON files under `content/`.
49-
2. **Parsing**: The Fumadocs engine parses metadata and builds the navigation tree.
50-
3. **Rendering**: Next.js (App Router) renders content as React Server Components.
51-
4. **Interaction**: Client components (like `<Cards>`, `<Steps>`) activate in the browser.
62+
### Initialization Flow
63+
1. **Init Command**: `npx @objectdocs/cli init`
64+
2. **Package Copy**: Entire `@objectdocs/site` package → `content/.objectdocs`
65+
3. **Script Creation**: `content/package.json` with dev/build/start scripts
66+
4. **Dependency Install**: `npm install` in `content/.objectdocs`
67+
5. **Gitignore Update**: Add exclusions for generated files
68+
69+
### Development Flow
70+
1. **Start**: Run `cd content && npm run dev`
71+
2. **Config Sync**: Copy `docs.site.json` and `public/` to `content/.objectdocs`
72+
3. **Environment**: Set `DOCS_DIR` env variable to point to `content/docs`
73+
4. **Watch**: Monitor `docs.site.json` for changes and auto-restart
74+
5. **Server**: Next.js dev server runs on port 7777 (default)
75+
76+
### Build Flow
77+
1. **Build Time**: Run `cd content && npm run build`
78+
2. **Config Sync**: Copy `docs.site.json` and `public/` to `content/.objectdocs`
79+
3. **Environment**: Set `DOCS_DIR` env variable
80+
4. **MDX Parsing**: Fumadocs reads all `.mdx` files from `DOCS_DIR`
81+
5. **Metadata**: Parse `meta.json` files to build navigation tree
82+
6. **Rendering**: Next.js App Router renders as React Server Components
83+
7. **Output**:
84+
- Static mode: `content/.objectdocs/out``out/` (root)
85+
- Dynamic mode: `content/.objectdocs/.next``.next/` (root)
86+
87+
### Runtime Flow (Static)
88+
1. **Serve**: Production build served from `out/` directory
89+
2. **Assets**: Static HTML, CSS, JS, and images
90+
3. **CDN**: Can be deployed to Vercel, Netlify, or any static host
91+
92+
### Runtime Flow (Dynamic)
93+
1. **Start**: Run `cd content && npm run start`
94+
2. **Server**: Next.js production server with ISR/SSR capabilities
95+
3. **Interaction**: Client components (like `<Cards>`, `<Steps>`) hydrate in browser
5296

5397
### Why Design It This Way?
5498

5599
This architecture allows us to:
56100

57-
* **Multi-Product Support**: By switching different `content` directories, multiple product documentations can be supported within the same codebase.
58-
* **Low-Code Integration**: Since content is separated from UI, we can more easily inject dynamic low-code component demos.
101+
* **Clean Separation**: Keep the documentation content completely separate from the site engine
102+
* **Project Agnostic**: Add docs to any existing project without polluting the root directory
103+
* **Version Control**: The entire site engine is gitignored, only content is tracked
104+
* **Multi-Product Support**: By switching different `content` directories, multiple product documentations can be supported
105+
* **Low-Code Integration**: Since content is separated from UI, we can more easily inject dynamic low-code component demos
106+
* **Easy Updates**: Update the site engine by re-running init or updating the CLI version

content/docs/getting-started/configuration.cn.mdx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ObjectDocs 遵循 **配置即代码 (Configuration as Code)** 的原则。所有
1313

1414
### docs.site.json
1515

16-
主配置文件位于 `content/docs.site.json`。该文件控制整个文档站点的全局设置。
16+
主配置文件位于 `content/docs.site.json`。该文件控制整个文档站点的全局设置,并在构建和开发期间自动同步到 `content/.objectdocs`
1717

1818
```json
1919
{
@@ -27,17 +27,34 @@ ObjectDocs 遵循 **配置即代码 (Configuration as Code)** 的原则。所有
2727
"links": [
2828
{ "text": "Guide", "url": "/docs" },
2929
{ "text": "GitHub", "url": "https://github.com/objectstack-ai", "icon": "github" }
30-
]
30+
],
31+
"i18n": {
32+
"defaultLanguage": "en",
33+
"languages": ["en", "zh-CN", "ja", "es", "fr", "de", "ko", "ru", "pt", "ar", "hi", "it", "tr", "vi"]
34+
}
3135
}
3236
```
3337

38+
**工作原理:**
39+
- 存储在 `content/docs.site.json` (你的内容目录)
40+
- 在每次 build/dev 命令前复制到 `content/.objectdocs`
41+
- 开发时监听 - 变化会触发服务器自动重启
42+
- 支持 14 种语言的国际化
43+
3444
### 配置项说明
3545

3646
| 属性 | 类型 | 说明 |
3747
| :--- | :--- | :--- |
3848
| `branding.name` | `string` | 站点名称,显示在导航栏左侧。 |
39-
| `branding.logo` | `object` | 站点 Log 图片路径,支持亮色/暗色模式。 |
49+
| `branding.logo` | `object` | 站点 Logo 图片路径,支持亮色/暗色模式。 |
4050
| `links` | `array` | 顶部导航栏链接列表。 |
51+
| `i18n.defaultLanguage` | `string` | 默认语言代码 (例如, "en", "zh-CN")。 |
52+
| `i18n.languages` | `array` | 支持的语言 (14种可选: en, zh-CN, ja, es, fr, de, ko, ru, pt, ar, hi, it, tr, vi)。 |
53+
54+
**开发功能:**
55+
- 配置更改在 `npm run dev` 期间自动检测
56+
- `docs.site.json` 被修改时服务器会重启
57+
- 配置更新无需手动重启
4158

4259
## 目录与导航配置
4360

content/docs/getting-started/configuration.mdx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ObjectDocs follows the **Configuration as Code** principle. All site settings ar
1313

1414
### docs.site.json
1515

16-
The main configuration file is located at `content/docs.site.json`. This file controls the global settings for the entire documentation site.
16+
The main configuration file is located at `content/docs.site.json`. This file controls the global settings for the entire documentation site and is automatically synced to `content/.objectdocs` during build and development.
1717

1818
```json
1919
{
@@ -27,17 +27,34 @@ The main configuration file is located at `content/docs.site.json`. This file co
2727
"links": [
2828
{ "text": "Guide", "url": "/docs" },
2929
{ "text": "GitHub", "url": "https://github.com/objectstack-ai", "icon": "github" }
30-
]
30+
],
31+
"i18n": {
32+
"defaultLanguage": "en",
33+
"languages": ["en", "zh-CN", "ja", "es", "fr", "de", "ko", "ru", "pt", "ar", "hi", "it", "tr", "vi"]
34+
}
3135
}
3236
```
3337

38+
**How it Works:**
39+
- Stored in `content/docs.site.json` (your content directory)
40+
- Copied to `content/.objectdocs` before each build/dev command
41+
- Watched during development - changes trigger automatic server restart
42+
- Supports 14 languages for internationalization
43+
3444
### Configuration Options
3545

3646
| Property | Type | Description |
3747
| :--- | :--- | :--- |
3848
| `branding.name` | `string` | Site name, displayed on the left side of the navbar. |
3949
| `branding.logo` | `object` | Site logo image paths, supports light/dark mode. |
4050
| `links` | `array` | List of links in the top navigation bar. |
51+
| `i18n.defaultLanguage` | `string` | Default language code (e.g., "en", "zh-CN"). |
52+
| `i18n.languages` | `array` | Supported languages (14 available: en, zh-CN, ja, es, fr, de, ko, ru, pt, ar, hi, it, tr, vi). |
53+
54+
**Development Features:**
55+
- Config changes are automatically detected during `npm run dev`
56+
- Server restarts when `docs.site.json` is modified
57+
- No manual restart needed for configuration updates
4158

4259
## Directory & Navigation Configuration
4360

0 commit comments

Comments
 (0)