docmk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/.claude/skills/pdf/SKILL.md +89 -0
  2. package/.claude/skills/web-scraping/SKILL.md +78 -0
  3. package/CLAUDE.md +90 -0
  4. package/bin/docmk.js +3 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +636 -0
  7. package/dist/index.js.map +1 -0
  8. package/final-site/assets/main-B4orIFxK.css +1 -0
  9. package/final-site/assets/main-CSoKXua6.js +25 -0
  10. package/final-site/favicon.svg +4 -0
  11. package/final-site/index.html +26 -0
  12. package/final-site/robots.txt +4 -0
  13. package/final-site/sitemap.xml +14 -0
  14. package/my-docs/api/README.md +152 -0
  15. package/my-docs/api/advanced.md +260 -0
  16. package/my-docs/getting-started/README.md +24 -0
  17. package/my-docs/tutorials/README.md +272 -0
  18. package/my-docs/tutorials/customization.md +492 -0
  19. package/package.json +59 -0
  20. package/postcss.config.js +6 -0
  21. package/site/assets/main-BZUsYUCF.css +1 -0
  22. package/site/assets/main-q6laQtCD.js +114 -0
  23. package/site/favicon.svg +4 -0
  24. package/site/index.html +23 -0
  25. package/site/robots.txt +4 -0
  26. package/site/sitemap.xml +34 -0
  27. package/site-output/assets/main-B4orIFxK.css +1 -0
  28. package/site-output/assets/main-CSoKXua6.js +25 -0
  29. package/site-output/favicon.svg +4 -0
  30. package/site-output/index.html +26 -0
  31. package/site-output/robots.txt +4 -0
  32. package/site-output/sitemap.xml +14 -0
  33. package/src/builder/index.ts +189 -0
  34. package/src/builder/vite-dev.ts +117 -0
  35. package/src/cli/commands/build.ts +48 -0
  36. package/src/cli/commands/dev.ts +53 -0
  37. package/src/cli/commands/preview.ts +57 -0
  38. package/src/cli/index.ts +42 -0
  39. package/src/client/App.vue +15 -0
  40. package/src/client/components/SearchBox.vue +204 -0
  41. package/src/client/components/Sidebar.vue +18 -0
  42. package/src/client/components/SidebarItem.vue +108 -0
  43. package/src/client/index.html +21 -0
  44. package/src/client/layouts/AppLayout.vue +99 -0
  45. package/src/client/lib/utils.ts +6 -0
  46. package/src/client/main.ts +42 -0
  47. package/src/client/pages/Home.vue +279 -0
  48. package/src/client/pages/SkillPage.vue +565 -0
  49. package/src/client/router.ts +16 -0
  50. package/src/client/styles/global.css +92 -0
  51. package/src/client/utils/routes.ts +69 -0
  52. package/src/parser/index.ts +253 -0
  53. package/src/scanner/index.ts +127 -0
  54. package/src/types/index.ts +45 -0
  55. package/tailwind.config.js +65 -0
  56. package/test-build/assets/main-C2ARPC0e.css +1 -0
  57. package/test-build/assets/main-CHIQpV3B.js +25 -0
  58. package/test-build/favicon.svg +4 -0
  59. package/test-build/index.html +47 -0
  60. package/test-build/robots.txt +4 -0
  61. package/test-build/sitemap.xml +19 -0
  62. package/test-dist/assets/main-B4orIFxK.css +1 -0
  63. package/test-dist/assets/main-CSoKXua6.js +25 -0
  64. package/test-dist/favicon.svg +4 -0
  65. package/test-dist/index.html +26 -0
  66. package/test-dist/robots.txt +4 -0
  67. package/test-dist/sitemap.xml +14 -0
  68. package/tsconfig.json +30 -0
  69. package/tsup.config.ts +13 -0
  70. package/vite.config.ts +21 -0
@@ -0,0 +1,152 @@
1
+ ---
2
+ title: API 参考
3
+ description: DocGen API 完整参考文档
4
+ ---
5
+
6
+ # API 参考
7
+
8
+ DocGen 提供了简洁而强大的 API,用于生成和管理文档站点。
9
+
10
+ ## 核心 API
11
+
12
+ ### scanSkillsDirectory()
13
+
14
+ 扫描指定目录,收集所有 Markdown 文件。
15
+
16
+ ```typescript
17
+ async function scanSkillsDirectory(dirPath: string): Promise<SkillDirectory[]>
18
+ ```
19
+
20
+ **参数:**
21
+ - `dirPath` (string): 要扫描的目录路径
22
+
23
+ **返回值:**
24
+ - `Promise<SkillDirectory[]>`: 目录结构数组
25
+
26
+ **示例:**
27
+
28
+ ```typescript
29
+ import { scanSkillsDirectory } from 'docgen'
30
+
31
+ const directories = await scanSkillsDirectory('./docs')
32
+ console.log(`找到 ${directories.length} 个目录`)
33
+ ```
34
+
35
+ ### parseSkillsToConfig()
36
+
37
+ 将扫描的目录结构解析为配置对象。
38
+
39
+ ```typescript
40
+ async function parseSkillsToConfig(
41
+ directories: SkillDirectory[],
42
+ siteConfig: SiteConfig
43
+ ): Promise<DocGenConfig>
44
+ ```
45
+
46
+ **参数:**
47
+ - `directories` (SkillDirectory[]): 目录结构数组
48
+ - `siteConfig` (SiteConfig): 站点配置对象
49
+
50
+ **返回值:**
51
+ - `Promise<DocGenConfig>`: 完整的文档配置
52
+
53
+ **示例:**
54
+
55
+ ```typescript
56
+ const config = await parseSkillsToConfig(directories, {
57
+ title: '我的文档',
58
+ description: '项目文档站点',
59
+ baseUrl: '/',
60
+ skillsDir: './docs',
61
+ outputDir: './dist'
62
+ })
63
+ ```
64
+
65
+ ## 类型定义
66
+
67
+ ### SkillFile
68
+
69
+ 表示单个 Markdown 文件。
70
+
71
+ ```typescript
72
+ interface SkillFile {
73
+ path: string // 文件绝对路径
74
+ name: string // 文件名
75
+ title?: string // 文档标题
76
+ description?: string // 文档描述
77
+ content: string // Markdown 内容
78
+ frontmatter: Record<string, any> // 前置元数据
79
+ lastModified: number // 最后修改时间戳
80
+ }
81
+ ```
82
+
83
+ ### SiteConfig
84
+
85
+ 站点配置对象。
86
+
87
+ ```typescript
88
+ interface SiteConfig {
89
+ title: string // 站点标题
90
+ description: string // 站点描述
91
+ baseUrl: string // 基础 URL
92
+ skillsDir: string // 源文件目录
93
+ outputDir: string // 输出目录
94
+ }
95
+ ```
96
+
97
+ ## CLI 命令
98
+
99
+ ### dev
100
+
101
+ 启动开发服务器。
102
+
103
+ ```bash
104
+ docgen dev [options]
105
+ ```
106
+
107
+ **选项:**
108
+ - `--dir <path>`: 源文件目录(默认:`./docs`)
109
+ - `--port <number>`: 端口号(默认:`3000`)
110
+
111
+ ### build
112
+
113
+ 构建静态站点。
114
+
115
+ ```bash
116
+ docgen build [options]
117
+ ```
118
+
119
+ **选项:**
120
+ - `--dir <path>`: 源文件目录(默认:`./docs`)
121
+ - `--output <path>`: 输出目录(默认:`./dist`)
122
+
123
+ ### preview
124
+
125
+ 预览构建后的站点。
126
+
127
+ ```bash
128
+ docgen preview [options]
129
+ ```
130
+
131
+ **选项:**
132
+ - `--output <path>`: 站点目录(默认:`./dist`)
133
+ - `--port <number>`: 端口号(默认:`4173`)
134
+
135
+ ## 错误处理
136
+
137
+ 所有异步函数都会抛出错误,建议使用 try-catch 处理:
138
+
139
+ ```typescript
140
+ try {
141
+ const directories = await scanSkillsDirectory('./docs')
142
+ } catch (error) {
143
+ console.error('扫描失败:', error)
144
+ }
145
+ ```
146
+
147
+ ## 最佳实践
148
+
149
+ 1. **使用 TypeScript**:获得完整的类型提示
150
+ 2. **错误处理**:始终捕获异步操作的错误
151
+ 3. **路径规范**:使用绝对路径避免路径问题
152
+ 4. **配置验证**:构建前验证配置对象的完整性
@@ -0,0 +1,260 @@
1
+ ---
2
+ title: 高级用法
3
+ description: DocGen 高级功能和自定义选项
4
+ ---
5
+
6
+ # 高级用法
7
+
8
+ 深入了解 DocGen 的高级功能和自定义选项。
9
+
10
+ ## 自定义主题
11
+
12
+ ### CSS 变量
13
+
14
+ DocGen 使用 CSS 变量系统,可以轻松自定义主题:
15
+
16
+ ```css
17
+ :root {
18
+ --color-primary: #0a0a0a;
19
+ --color-background: #ffffff;
20
+ --font-sans: -apple-system, sans-serif;
21
+ --spacing-md: 1rem;
22
+ --radius-lg: 0.75rem;
23
+ }
24
+ ```
25
+
26
+ ### 深色模式
27
+
28
+ 系统自动支持深色模式,基于用户系统偏好:
29
+
30
+ ```css
31
+ @media (prefers-color-scheme: dark) {
32
+ :root {
33
+ --color-background: #0a0a0a;
34
+ --color-foreground: #fafafa;
35
+ }
36
+ }
37
+ ```
38
+
39
+ ## 插件系统
40
+
41
+ ### Vite 插件集成
42
+
43
+ DocGen 基于 Vite 构建,可以使用任何 Vite 插件:
44
+
45
+ ```typescript
46
+ import { defineConfig } from 'vite'
47
+ import vue from '@vitejs/plugin-vue'
48
+ import markdown from 'vite-plugin-markdown'
49
+
50
+ export default defineConfig({
51
+ plugins: [
52
+ vue(),
53
+ markdown()
54
+ ]
55
+ })
56
+ ```
57
+
58
+ ### Markdown-it 扩展
59
+
60
+ 自定义 Markdown 渲染器:
61
+
62
+ ```typescript
63
+ import MarkdownIt from 'markdown-it'
64
+ import anchor from 'markdown-it-anchor'
65
+ import toc from 'markdown-it-toc-done-right'
66
+
67
+ const md = new MarkdownIt({
68
+ html: true,
69
+ linkify: true,
70
+ typographer: true
71
+ })
72
+ .use(anchor)
73
+ .use(toc)
74
+ ```
75
+
76
+ ## 性能优化
77
+
78
+ ### 代码分割
79
+
80
+ 使用动态导入优化加载性能:
81
+
82
+ ```typescript
83
+ const Home = () => import('./pages/Home.vue')
84
+ const SkillPage = () => import('./pages/SkillPage.vue')
85
+ ```
86
+
87
+ ### 图片优化
88
+
89
+ 建议使用 WebP 格式和响应式图片:
90
+
91
+ ```markdown
92
+ ![示例图片](./image.webp)
93
+ ```
94
+
95
+ ### 懒加载
96
+
97
+ 对大型文档启用懒加载:
98
+
99
+ ```typescript
100
+ const observer = new IntersectionObserver((entries) => {
101
+ entries.forEach(entry => {
102
+ if (entry.isIntersecting) {
103
+ // 加载内容
104
+ }
105
+ })
106
+ })
107
+ ```
108
+
109
+ ## 部署选项
110
+
111
+ ### Netlify
112
+
113
+ ```toml
114
+ [build]
115
+ command = "docgen build --dir ./docs --output ./dist"
116
+ publish = "dist"
117
+
118
+ [[redirects]]
119
+ from = "/*"
120
+ to = "/index.html"
121
+ status = 200
122
+ ```
123
+
124
+ ### Vercel
125
+
126
+ ```json
127
+ {
128
+ "buildCommand": "docgen build --dir ./docs --output ./dist",
129
+ "outputDirectory": "dist",
130
+ "rewrites": [
131
+ { "source": "/(.*)", "destination": "/index.html" }
132
+ ]
133
+ }
134
+ ```
135
+
136
+ ### GitHub Pages
137
+
138
+ ```yaml
139
+ name: Deploy
140
+ on:
141
+ push:
142
+ branches: [main]
143
+ jobs:
144
+ deploy:
145
+ runs-on: ubuntu-latest
146
+ steps:
147
+ - uses: actions/checkout@v2
148
+ - run: npm install
149
+ - run: docgen build --dir ./docs --output ./dist
150
+ - uses: peaceiris/actions-gh-pages@v3
151
+ with:
152
+ github_token: ${{ secrets.GITHUB_TOKEN }}
153
+ publish_dir: ./dist
154
+ ```
155
+
156
+ ## 搜索优化
157
+
158
+ ### 全文搜索
159
+
160
+ 实现基于 Fuse.js 的全文搜索:
161
+
162
+ ```typescript
163
+ import Fuse from 'fuse.js'
164
+
165
+ const fuse = new Fuse(files, {
166
+ keys: ['title', 'content', 'description'],
167
+ threshold: 0.3
168
+ })
169
+
170
+ const results = fuse.search(query)
171
+ ```
172
+
173
+ ### SEO 优化
174
+
175
+ 生成 sitemap 和 robots.txt:
176
+
177
+ ```typescript
178
+ // sitemap.xml
179
+ const urls = files.map(file => ({
180
+ loc: `${baseUrl}${getFileRoute(file)}`,
181
+ lastmod: new Date(file.lastModified).toISOString()
182
+ }))
183
+ ```
184
+
185
+ ## 国际化
186
+
187
+ ### 多语言支持
188
+
189
+ 组织多语言文档:
190
+
191
+ ```
192
+ docs/
193
+ en/
194
+ getting-started/
195
+ README.md
196
+ zh/
197
+ getting-started/
198
+ README.md
199
+ ```
200
+
201
+ ### 语言切换
202
+
203
+ ```typescript
204
+ const locale = ref('zh')
205
+
206
+ function switchLocale(newLocale: string) {
207
+ locale.value = newLocale
208
+ // 重新加载文档
209
+ }
210
+ ```
211
+
212
+ ## 安全性
213
+
214
+ ### 内容安全策略
215
+
216
+ 配置 CSP 头:
217
+
218
+ ```html
219
+ <meta http-equiv="Content-Security-Policy"
220
+ content="default-src 'self'; script-src 'self' 'unsafe-inline'">
221
+ ```
222
+
223
+ ### XSS 防护
224
+
225
+ Markdown 渲染时自动转义 HTML:
226
+
227
+ ```typescript
228
+ const md = new MarkdownIt({
229
+ html: false // 禁用原始 HTML
230
+ })
231
+ ```
232
+
233
+ ## 监控和分析
234
+
235
+ ### Google Analytics
236
+
237
+ ```html
238
+ <script async src="https://www.googletagmanager.com/gtag/js?id=GA_ID"></script>
239
+ <script>
240
+ window.dataLayer = window.dataLayer || [];
241
+ function gtag(){dataLayer.push(arguments);}
242
+ gtag('js', new Date());
243
+ gtag('config', 'GA_ID');
244
+ </script>
245
+ ```
246
+
247
+ ### 错误追踪
248
+
249
+ 集成 Sentry:
250
+
251
+ ```typescript
252
+ import * as Sentry from '@sentry/vue'
253
+
254
+ Sentry.init({
255
+ app,
256
+ dsn: 'YOUR_DSN',
257
+ integrations: [new Sentry.BrowserTracing()],
258
+ tracesSampleRate: 1.0
259
+ })
260
+ ```
@@ -0,0 +1,24 @@
1
+ ---
2
+ title: 快速开始
3
+ description: DocGen 快速入门指南
4
+ ---
5
+
6
+ # 快速开始
7
+
8
+ 欢迎使用 DocGen!这是一个用于生成文档网站的工具。
9
+
10
+ ## 安装
11
+
12
+ ```bash
13
+ npm install -g docgen
14
+ ```
15
+
16
+ ## 基本使用
17
+
18
+ 创建你的文档目录结构,然后运行:
19
+
20
+ ```bash
21
+ docgen dev --dir ./my-docs
22
+ ```
23
+
24
+ 就这么简单!
@@ -0,0 +1,272 @@
1
+ ---
2
+ title: 教程指南
3
+ description: 从零开始学习使用 DocGen
4
+ ---
5
+
6
+ # 教程指南
7
+
8
+ 通过实际示例学习如何使用 DocGen 构建文档站点。
9
+
10
+ ## 第一步:创建项目
11
+
12
+ ### 1. 安装 DocGen
13
+
14
+ 首先安装 DocGen CLI 工具:
15
+
16
+ ```bash
17
+ npm install -g docgen
18
+ ```
19
+
20
+ 验证安装:
21
+
22
+ ```bash
23
+ docgen --version
24
+ ```
25
+
26
+ ### 2. 创建文档目录
27
+
28
+ 创建你的文档项目结构:
29
+
30
+ ```bash
31
+ mkdir my-documentation
32
+ cd my-documentation
33
+ mkdir docs
34
+ ```
35
+
36
+ ### 3. 编写第一个文档
37
+
38
+ 创建 `docs/getting-started/README.md`:
39
+
40
+ ```markdown
41
+ ---
42
+ title: 快速开始
43
+ description: 开始使用我们的产品
44
+ ---
45
+
46
+ # 快速开始
47
+
48
+ 欢迎使用我们的产品!
49
+
50
+ ## 安装
51
+
52
+ \`\`\`bash
53
+ npm install my-product
54
+ \`\`\`
55
+
56
+ ## 基本用法
57
+
58
+ \`\`\`javascript
59
+ import { MyProduct } from 'my-product'
60
+
61
+ const product = new MyProduct()
62
+ product.start()
63
+ \`\`\`
64
+ ```
65
+
66
+ ## 第二步:启动开发服务器
67
+
68
+ ### 实时预览
69
+
70
+ 启动开发服务器查看效果:
71
+
72
+ ```bash
73
+ docgen dev --dir ./docs
74
+ ```
75
+
76
+ 访问 `http://localhost:3000` 查看你的文档站点。
77
+
78
+ ### 热更新
79
+
80
+ 修改任何 Markdown 文件,浏览器会自动刷新显示最新内容。
81
+
82
+ ### 调试技巧
83
+
84
+ 1. **检查控制台**:打开浏览器开发者工具查看错误
85
+ 2. **验证路径**:确保文件路径正确
86
+ 3. **清理缓存**:遇到问题时清理 `node_modules/.vite`
87
+
88
+ ## 第三步:组织文档结构
89
+
90
+ ### 推荐目录结构
91
+
92
+ ```
93
+ docs/
94
+ ├── getting-started/
95
+ │ ├── README.md
96
+ │ ├── installation.md
97
+ │ └── quick-start.md
98
+ ├── guides/
99
+ │ ├── README.md
100
+ │ ├── basic-usage.md
101
+ │ └── advanced-features.md
102
+ ├── api/
103
+ │ ├── README.md
104
+ │ ├── core-api.md
105
+ │ └── utilities.md
106
+ └── faq/
107
+ └── README.md
108
+ ```
109
+
110
+ ### 文件命名规范
111
+
112
+ - 使用小写字母和连字符
113
+ - `README.md` 作为目录首页
114
+ - 描述性文件名:`user-authentication.md`
115
+
116
+ ### Frontmatter 最佳实践
117
+
118
+ 每个文档都应包含 frontmatter:
119
+
120
+ ```yaml
121
+ ---
122
+ title: 页面标题
123
+ description: 页面描述(用于 SEO)
124
+ author: 作者名称
125
+ date: 2026-01-19
126
+ tags: [tutorial, beginner]
127
+ ---
128
+ ```
129
+
130
+ ## 第四步:添加代码示例
131
+
132
+ ### 语法高亮
133
+
134
+ 使用语言标识符启用语法高亮:
135
+
136
+ ````markdown
137
+ ```javascript
138
+ function hello() {
139
+ console.log('Hello, World!')
140
+ }
141
+ ```
142
+
143
+ ```python
144
+ def hello():
145
+ print("Hello, World!")
146
+ ```
147
+
148
+ ```bash
149
+ echo "Hello, World!"
150
+ ```
151
+ ````
152
+
153
+ ### 代码注释
154
+
155
+ 添加注释说明关键代码:
156
+
157
+ ```javascript
158
+ // 初始化应用
159
+ const app = createApp()
160
+
161
+ // 配置路由
162
+ app.use(router)
163
+
164
+ // 启动应用
165
+ app.mount('#app')
166
+ ```
167
+
168
+ ### 可运行示例
169
+
170
+ 提供完整的可运行代码:
171
+
172
+ ```javascript
173
+ // 完整示例:用户认证
174
+ import { authenticate } from './auth'
175
+
176
+ async function login(username, password) {
177
+ try {
178
+ const user = await authenticate(username, password)
179
+ console.log('登录成功:', user)
180
+ return user
181
+ } catch (error) {
182
+ console.error('登录失败:', error)
183
+ throw error
184
+ }
185
+ }
186
+
187
+ // 使用示例
188
+ login('user@example.com', 'password123')
189
+ ```
190
+
191
+ ## 第五步:构建生产版本
192
+
193
+ ### 构建站点
194
+
195
+ 生成静态文件:
196
+
197
+ ```bash
198
+ docgen build --dir ./docs --output ./dist
199
+ ```
200
+
201
+ ### 验证构建
202
+
203
+ 预览构建后的站点:
204
+
205
+ ```bash
206
+ docgen preview --output ./dist
207
+ ```
208
+
209
+ ### 优化建议
210
+
211
+ 1. **压缩图片**:使用 WebP 格式
212
+ 2. **代码分割**:大型文档分成多个文件
213
+ 3. **缓存策略**:配置适当的缓存头
214
+
215
+ ## 第六步:部署上线
216
+
217
+ ### 部署到 Netlify
218
+
219
+ 1. 连接 Git 仓库
220
+ 2. 配置构建命令:`docgen build --dir ./docs --output ./dist`
221
+ 3. 设置发布目录:`dist`
222
+ 4. 点击部署
223
+
224
+ ### 部署到 Vercel
225
+
226
+ ```bash
227
+ npm install -g vercel
228
+ vercel --prod
229
+ ```
230
+
231
+ ### 自定义域名
232
+
233
+ 在部署平台配置自定义域名:
234
+
235
+ 1. 添加 CNAME 记录
236
+ 2. 配置 SSL 证书
237
+ 3. 等待 DNS 生效
238
+
239
+ ## 常见问题
240
+
241
+ ### 样式不显示?
242
+
243
+ 清理缓存并重新构建:
244
+
245
+ ```bash
246
+ rm -rf node_modules/.vite
247
+ docgen build --dir ./docs --output ./dist
248
+ ```
249
+
250
+ ### 路由 404 错误?
251
+
252
+ 确保服务器配置了 SPA 回退:
253
+
254
+ ```nginx
255
+ location / {
256
+ try_files $uri $uri/ /index.html;
257
+ }
258
+ ```
259
+
260
+ ### 搜索不工作?
261
+
262
+ 检查文件是否正确扫描:
263
+
264
+ ```bash
265
+ docgen build --dir ./docs --output ./dist --verbose
266
+ ```
267
+
268
+ ## 下一步
269
+
270
+ - 阅读 [API 参考](../api/README.md)
271
+ - 查看 [配置选项](../configuration/README.md)
272
+ - 浏览 [FAQ](../faq/README.md)