Skip to content

Commit f4e6521

Browse files
committed
docs: update vitepress and improve docs
1 parent 37db2d0 commit f4e6521

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1019
-924
lines changed

docs/.vitepress/config.ts

Lines changed: 35 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
import type { DefaultTheme, UserConfig } from 'vitepress'
2+
import process from 'node:process'
23
import { defineConfig } from 'vitepress'
3-
import { version } from '../../package.json'
4+
import {
5+
groupIconMdPlugin,
6+
groupIconVitePlugin,
7+
} from 'vitepress-plugin-group-icons'
8+
import llmstxt from 'vitepress-plugin-llms'
9+
10+
const prod = !!process.env.NETLIFY
411

512
const vitepressConfig: UserConfig<DefaultTheme.Config> = defineConfig({
6-
lang: 'zh-CN',
713
title: 'Mock-Dev-Server',
8-
description: 'Mock-dev-server is injected into the Vite development environment to simulate API request and response data.',
914
lastUpdated: true,
1015
cleanUrls: true,
16+
metaChunk: true,
17+
18+
rewrites: {
19+
'en/:rest*': ':rest*',
20+
},
21+
1122
markdown: {
1223
theme: { light: 'github-light', dark: 'github-dark' },
1324
headers: { level: [2, 3] },
25+
codeTransformers: [
26+
{
27+
postprocess(code) {
28+
return code.replace(/\[!!code/g, '[!code')
29+
},
30+
},
31+
],
32+
config(md) {
33+
md.use(groupIconMdPlugin)
34+
},
1435
},
1536
head: [
1637
['link', { rel: 'icon', type: 'image/svg', href: '/logo.svg' }],
@@ -28,187 +49,18 @@ const vitepressConfig: UserConfig<DefaultTheme.Config> = defineConfig({
2849
],
2950
search: { provider: 'local' },
3051
},
52+
vite: {
53+
plugins: [
54+
groupIconVitePlugin(),
55+
prod && llmstxt({
56+
workDir: 'en',
57+
ignoreFiles: ['index.md'],
58+
}),
59+
],
60+
},
3161
locales: {
32-
root: {
33-
label: '简体中文',
34-
lang: 'zh-CN',
35-
themeConfig: {
36-
editLink: {
37-
pattern: 'https://github.com/pengzhanbo/vite-plugin-mock-dev-server/edit/main/docs/:path',
38-
text: '在Github编辑此页',
39-
},
40-
footer: {
41-
message: 'Released under the MIT License.',
42-
copyright: 'Copyright © 2022-present pengzhanbo',
43-
},
44-
docFooter: {
45-
prev: '上一页',
46-
next: '下一页',
47-
},
48-
nav: [
49-
{
50-
text: '使用指南',
51-
link: '/guide/introduce',
52-
activeMatch: '/guide/',
53-
},
54-
{
55-
text: '使用示例',
56-
link: '/examples/basic',
57-
activeMatch: '/examples/',
58-
},
59-
{ text: `version ${version}`, link: '/', activeMatch: '!' },
60-
],
61-
sidebar: {
62-
'/guide/': [
63-
{
64-
text: '快速开始',
65-
items: [
66-
{ text: '介绍', link: '/guide/introduce' },
67-
{ text: '安装', link: '/guide/install' },
68-
{ text: '使用', link: '/guide/usage' },
69-
],
70-
},
71-
{
72-
text: 'API',
73-
items: [
74-
{ text: 'mockDevServerPlugin', link: '/guide/mock-plugin' },
75-
{ text: 'defineMock', link: '/guide/define-mock' },
76-
{ text: 'createDefineMock', link: '/guide/create-define-mock' },
77-
{ text: 'defineMockData', link: '/guide/define-mock-data' },
78-
{ text: 'createSSEStream', link: '/guide/create-sse-stream' },
79-
],
80-
},
81-
{
82-
text: '配置',
83-
items: [
84-
{ text: 'pluginConfig', link: '/guide/plugin-config' },
85-
{ text: 'mockConfig', link: '/guide/mock-config' },
86-
],
87-
},
88-
{
89-
text: '实践建议',
90-
items: [
91-
{ text: '目录文件管理', link: '/guide/file-management' },
92-
{ text: '共享内容', link: '/guide/shared' },
93-
{ text: '共享可变数据', link: '/guide/shared-data' },
94-
{ text: '文件上传', link: '/guide/upload' },
95-
{ text: '团队协作', link: '/guide/teamwork' },
96-
{ text: 'mock服务部署', link: '/guide/mock-service' },
97-
],
98-
},
99-
],
100-
'/examples/': [
101-
{ text: '基础示例', link: '/examples/basic' },
102-
{ text: '类型格式', link: '/examples/format-extension' },
103-
{ text: '自定义响应头', link: '/examples/header' },
104-
{ text: 'cookies', link: '/examples/cookies' },
105-
{ text: '自定义响应体', link: '/examples/body' },
106-
{ text: '自定义响应内容', link: '/examples/response' },
107-
{ text: '文件上传/下载', link: '/examples/file' },
108-
{ text: '静态资源服务', link: '/examples/static' },
109-
{ text: '请求验证器', link: '/examples/validator' },
110-
{ text: '使用mockjs库', link: '/examples/mockjs' },
111-
{ text: '使用faker-js库', link: '/examples/faker' },
112-
{ text: 'Graphql', link: '/examples/graphql' },
113-
{ text: 'Websocket', link: '/examples/websocket' },
114-
{ text: 'EventSource', link: '/examples/event-source' },
115-
],
116-
},
117-
},
118-
},
119-
en: {
120-
label: 'English',
121-
lang: 'en-US',
122-
themeConfig: {
123-
editLink: {
124-
pattern: 'https://github.com/pengzhanbo/vite-plugin-mock-dev-server/edit/main/docs/:path',
125-
text: 'Edit this page on Github',
126-
},
127-
footer: {
128-
message: 'Released under the MIT License.',
129-
copyright: 'Copyright © 2022-present pengzhanbo',
130-
},
131-
docFooter: {
132-
prev: 'Prev Page',
133-
next: 'Next Page',
134-
},
135-
nav: [
136-
{
137-
text: 'Guide',
138-
link: '/en/guide/introduce',
139-
activeMatch: '/en/guide/',
140-
},
141-
{
142-
text: 'Examples',
143-
link: '/en/examples/basic',
144-
activeMatch: '/en/examples/',
145-
},
146-
{ text: `version ${version}`, link: '/en/', activeMatch: '!' },
147-
],
148-
sidebar: {
149-
'/en/guide/': [
150-
{
151-
text: 'Quick Start',
152-
items: [
153-
{ text: 'Introduce', link: '/en/guide/introduce' },
154-
{ text: 'Install', link: '/en/guide/install' },
155-
{ text: 'Usage', link: '/en/guide/usage' },
156-
],
157-
},
158-
{
159-
text: 'API',
160-
items: [
161-
{ text: 'mockDevServerPlugin', link: '/en/guide/mock-plugin' },
162-
{ text: 'defineMock', link: '/en/guide/define-mock' },
163-
{ text: 'createDefineMock', link: '/en/guide/create-define-mock' },
164-
{ text: 'defineMockData', link: '/en/guide/define-mock-data' },
165-
{ text: 'createSSEStream', link: '/en/guide/create-sse-stream' },
166-
],
167-
},
168-
{
169-
text: 'Configuration',
170-
items: [
171-
{ text: 'pluginConfig', link: '/en/guide/plugin-config' },
172-
{ text: 'mockConfig', link: '/en/guide/mock-config' },
173-
],
174-
},
175-
{
176-
text: 'Practical suggestion',
177-
items: [
178-
{
179-
text: 'Directory file management',
180-
link: '/en/guide/file-management',
181-
},
182-
{ text: 'Share Content', link: '/en/guide/shared' },
183-
{ text: 'Shared', link: '/en/guide/shared-data' },
184-
{ text: 'File Upload', link: '/en/guide/upload' },
185-
{ text: 'Teamwork', link: '/en/guide/teamwork' },
186-
{
187-
text: 'Mock Service Deployment',
188-
link: '/en/guide/mock-service',
189-
},
190-
],
191-
},
192-
],
193-
'/en/examples/': [
194-
{ text: 'Basic example', link: '/en/examples/basic' },
195-
{ text: 'Format extension', link: '/en/examples/format-extension' },
196-
{ text: 'Custom header', link: '/en/examples/header' },
197-
{ text: 'cookies', link: '/en/examples/cookies' },
198-
{ text: 'Custom body', link: '/en/examples/body' },
199-
{ text: 'Custom response', link: '/en/examples/response' },
200-
{ text: 'File upload/download', link: '/en/examples/file' },
201-
{ text: 'Static resources', link: '/en/examples/static' },
202-
{ text: 'Request validator', link: '/en/examples/validator' },
203-
{ text: 'Use mockjs', link: '/en/examples/mockjs' },
204-
{ text: 'Use faker-js', link: '/en/examples/faker' },
205-
{ text: 'Graphql', link: '/en/examples/graphql' },
206-
{ text: 'Websocket', link: '/en/examples/websocket' },
207-
{ text: 'EventSource', link: '/en/examples/event-source' },
208-
],
209-
},
210-
},
211-
},
62+
root: { label: 'English' },
63+
zh: { label: '简体中文' },
21264
},
21365
})
21466
export default vitepressConfig

docs/.vitepress/theme/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import DefaultTheme from 'vitepress/theme'
2+
import 'virtual:group-icons.css'
23
import './style.css'
34

45
export default DefaultTheme

docs/config.ts

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import type { DefaultTheme } from 'vitepress'
2+
import { defineAdditionalConfig } from 'vitepress'
3+
import { version } from './package.json'
4+
5+
export default defineAdditionalConfig({
6+
lang: 'en-US',
7+
description: 'Mock-dev-server is injected into the Vite development environment to simulate API request and response data.',
8+
9+
themeConfig: {
10+
editLink: {
11+
pattern: 'https://github.com/pengzhanbo/vite-plugin-mock-dev-server/edit/main/docs/:path',
12+
text: 'Edit this page on Github',
13+
},
14+
footer: {
15+
message: 'Released under the MIT License.',
16+
copyright: `Copyright © 2022-${new Date().getFullYear()} pengzhanbo`,
17+
},
18+
docFooter: {
19+
prev: 'Prev Page',
20+
next: 'Next Page',
21+
},
22+
nav: nav(),
23+
24+
sidebar: {
25+
'/guide/': { base: '/guide/', items: sidebarGuide() },
26+
'/examples/': { base: '/examples/', items: sidebarExamples() },
27+
},
28+
},
29+
})
30+
31+
function nav(): DefaultTheme.NavItem[] {
32+
return [
33+
{
34+
text: 'Guide',
35+
link: '/guide/introduce',
36+
activeMatch: '/guide/',
37+
},
38+
{
39+
text: 'Examples',
40+
link: '/examples/basic',
41+
activeMatch: '/examples/',
42+
},
43+
{
44+
text: `v${version}`,
45+
items: [
46+
{ text: 'Changelog', link: 'https://github.com/pengzhanbo/vite-plugin-mock-dev-server/blob/main/CHANGELOG.md' },
47+
],
48+
},
49+
]
50+
}
51+
52+
function sidebarGuide(): DefaultTheme.SidebarItem[] {
53+
return [
54+
{
55+
text: 'Quick Start',
56+
items: [
57+
{ text: 'Introduce', link: 'introduce' },
58+
{ text: 'Install', link: 'install' },
59+
{ text: 'Usage', link: 'usage' },
60+
],
61+
},
62+
{
63+
text: 'API',
64+
items: [
65+
{ text: 'mockDevServerPlugin', link: 'mock-plugin' },
66+
{ text: 'defineMock', link: 'define-mock' },
67+
{ text: 'createDefineMock', link: 'create-define-mock' },
68+
{ text: 'defineMockData', link: 'define-mock-data' },
69+
{ text: 'createSSEStream', link: 'create-sse-stream' },
70+
],
71+
},
72+
{
73+
text: 'Configuration',
74+
items: [
75+
{ text: 'pluginConfig', link: 'plugin-config' },
76+
{ text: 'mockConfig', link: 'mock-config' },
77+
],
78+
},
79+
{
80+
text: 'Practical suggestion',
81+
items: [
82+
{
83+
text: 'Directory file management',
84+
link: 'file-management',
85+
},
86+
{ text: 'Share Content', link: 'shared' },
87+
{ text: 'Shared', link: 'shared-data' },
88+
{ text: 'File Upload', link: 'upload' },
89+
{ text: 'Teamwork', link: 'teamwork' },
90+
{
91+
text: 'Mock Service Deployment',
92+
link: 'mock-service',
93+
},
94+
],
95+
},
96+
]
97+
}
98+
99+
function sidebarExamples(): DefaultTheme.SidebarItem[] {
100+
return [
101+
{ text: 'Basic example', link: 'basic' },
102+
{ text: 'Format extension', link: 'format-extension' },
103+
{ text: 'Custom header', link: 'header' },
104+
{ text: 'cookies', link: 'cookies' },
105+
{ text: 'Custom body', link: 'body' },
106+
{ text: 'Custom response', link: 'response' },
107+
{ text: 'File upload/download', link: 'file' },
108+
{ text: 'Static resources', link: 'static' },
109+
{ text: 'Request validator', link: 'validator' },
110+
{ text: 'Use mockjs', link: 'mockjs' },
111+
{ text: 'Use faker-js', link: 'faker' },
112+
{ text: 'Graphql', link: 'graphql' },
113+
{ text: 'Websocket', link: 'websocket' },
114+
{ text: 'EventSource', link: 'event-source' },
115+
]
116+
}

0 commit comments

Comments
 (0)