Skip to content

Commit 86ab768

Browse files
authored
update vitepress (#2329)
1 parent ac57432 commit 86ab768

File tree

6 files changed

+226
-245
lines changed

6 files changed

+226
-245
lines changed

docs/.vitepress/build-system/build.ts renamed to docs/.vitepress/build-system/build.mts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ import path from 'path'
66
import fs from 'fs'
77
import { fileURLToPath } from 'url'
88

9-
const dirname = path.dirname(
10-
fileURLToPath(
11-
// @ts-expect-error -- Cannot change `module` option
12-
import.meta.url
13-
)
14-
)
9+
const dirname = path.dirname(fileURLToPath(import.meta.url))
1510

1611
build(
1712
path.join(dirname, './src/eslint.mjs'),

docs/.vitepress/config.mts

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
import type { DefaultTheme } from 'vitepress'
2+
import { defineConfig } from 'vitepress'
3+
import path from 'path'
4+
import { fileURLToPath } from 'url'
5+
import { viteCommonjs, vitePluginRequireResolve } from './vite-plugin.mjs'
6+
7+
// Pre-build cjs packages that cannot be bundled well.
8+
import './build-system/build.mjs'
9+
10+
const dirname = path.dirname(fileURLToPath(import.meta.url))
11+
12+
export default async () => {
13+
const rulesPath = '../../tools/lib/rules.js' // Avoid bundle
14+
const rules: typeof import('../../tools/lib/rules.js') = await import(
15+
rulesPath
16+
).then((mod) => mod.default || mod)
17+
const uncategorizedRules = rules.filter(
18+
(rule) =>
19+
!rule.meta.docs.categories &&
20+
!rule.meta.docs.extensionRule &&
21+
!rule.meta.deprecated
22+
)
23+
const uncategorizedExtensionRule = rules.filter(
24+
(rule) =>
25+
!rule.meta.docs.categories &&
26+
rule.meta.docs.extensionRule &&
27+
!rule.meta.deprecated
28+
)
29+
const deprecatedRules = rules.filter((rule) => rule.meta.deprecated)
30+
31+
const sidebarCategories = [
32+
{ title: 'Base Rules', categoryIds: ['base'] },
33+
{
34+
title: 'Priority A: Essential',
35+
categoryIds: ['vue3-essential', 'essential']
36+
},
37+
{
38+
title: 'Priority A: Essential for Vue.js 3.x',
39+
categoryIds: ['vue3-essential']
40+
},
41+
{
42+
title: 'Priority A: Essential for Vue.js 2.x',
43+
categoryIds: ['essential']
44+
},
45+
{
46+
title: 'Priority B: Strongly Recommended',
47+
categoryIds: ['vue3-strongly-recommended', 'strongly-recommended']
48+
},
49+
{
50+
title: 'Priority B: Strongly Recommended for Vue.js 3.x',
51+
categoryIds: ['vue3-strongly-recommended']
52+
},
53+
{
54+
title: 'Priority B: Strongly Recommended for Vue.js 2.x',
55+
categoryIds: ['strongly-recommended']
56+
},
57+
{
58+
title: 'Priority C: Recommended',
59+
categoryIds: ['vue3-recommended', 'recommended']
60+
},
61+
{
62+
title: 'Priority C: Recommended for Vue.js 3.x',
63+
categoryIds: ['vue3-recommended']
64+
},
65+
{
66+
title: 'Priority C: Recommended for Vue.js 2.x',
67+
categoryIds: ['recommended']
68+
}
69+
]
70+
71+
const categorizedRules: DefaultTheme.SidebarItem[] = []
72+
for (const { title, categoryIds } of sidebarCategories) {
73+
const categoryRules = rules
74+
.filter((rule) => rule.meta.docs.categories && !rule.meta.deprecated)
75+
.filter((rule) =>
76+
categoryIds.every((categoryId) =>
77+
rule.meta.docs.categories.includes(categoryId)
78+
)
79+
)
80+
const children: DefaultTheme.SidebarItem[] = categoryRules
81+
.filter(({ ruleId }) => {
82+
const exists = categorizedRules.some(
83+
({ items }) =>
84+
items &&
85+
items.some(({ text: alreadyRuleId }) => alreadyRuleId === ruleId)
86+
)
87+
return !exists
88+
})
89+
.map(({ ruleId, name }) => {
90+
return {
91+
text: ruleId,
92+
link: `/rules/${name}`
93+
}
94+
})
95+
96+
if (children.length === 0) {
97+
continue
98+
}
99+
categorizedRules.push({
100+
text: title,
101+
collapsed: false,
102+
items: children
103+
})
104+
}
105+
106+
const extraCategories: DefaultTheme.SidebarItem[] = []
107+
if (uncategorizedRules.length > 0) {
108+
extraCategories.push({
109+
text: 'Uncategorized',
110+
collapsed: false,
111+
items: uncategorizedRules.map(({ ruleId, name }) => ({
112+
text: ruleId,
113+
link: `/rules/${name}`
114+
}))
115+
})
116+
}
117+
if (uncategorizedExtensionRule.length > 0) {
118+
extraCategories.push({
119+
text: 'Extension Rules',
120+
collapsed: false,
121+
items: uncategorizedExtensionRule.map(({ ruleId, name }) => ({
122+
text: ruleId,
123+
link: `/rules/${name}`
124+
}))
125+
})
126+
}
127+
if (deprecatedRules.length > 0) {
128+
extraCategories.push({
129+
text: 'Deprecated',
130+
collapsed: false,
131+
items: deprecatedRules.map(({ ruleId, name }) => ({
132+
text: ruleId,
133+
link: `/rules/${name}`
134+
}))
135+
})
136+
}
137+
return defineConfig({
138+
base: '/',
139+
title: 'eslint-plugin-vue',
140+
description: 'Official ESLint plugin for Vue.js',
141+
head: [['link', { rel: 'icon', href: '/favicon.png' }]],
142+
143+
vite: {
144+
publicDir: path.resolve(dirname, './public'),
145+
plugins: [vitePluginRequireResolve(), viteCommonjs()],
146+
resolve: {
147+
alias: {
148+
eslint: path.join(dirname, './build-system/shim/eslint.mjs'),
149+
assert: path.join(dirname, './build-system/shim/assert.mjs'),
150+
path: path.join(dirname, './build-system/shim/path.mjs'),
151+
152+
tslib: path.join(dirname, '../../node_modules/tslib/tslib.es6.js'),
153+
esquery: path.join(dirname, './build-system/shim/esquery.mjs'),
154+
globby: path.join(dirname, './build-system/shim/globby.mjs')
155+
}
156+
},
157+
define: {
158+
'process.env.NODE_DEBUG': 'false',
159+
'require.cache': '{}'
160+
}
161+
},
162+
163+
lastUpdated: true,
164+
themeConfig: {
165+
editLink: {
166+
pattern:
167+
'https://github.com/vuejs/eslint-plugin-vue/edit/master/docs/:path'
168+
},
169+
socialLinks: [
170+
{
171+
icon: 'github',
172+
link: 'https://github.com/vuejs/eslint-plugin-vue'
173+
}
174+
],
175+
176+
nav: [
177+
{ text: 'User Guide', link: '/user-guide/' },
178+
{ text: 'Developer Guide', link: '/developer-guide/' },
179+
{ text: 'Rules', link: '/rules/' },
180+
{
181+
text: 'Demo',
182+
link: 'https://ota-meshi.github.io/eslint-plugin-vue-demo/'
183+
}
184+
],
185+
186+
sidebar: {
187+
'/rules/': [
188+
{
189+
text: 'Rules',
190+
items: [{ text: 'Available Rules', link: '/rules/' }]
191+
},
192+
193+
// Rules in each category.
194+
...categorizedRules,
195+
196+
// Rules in no category.
197+
...extraCategories
198+
],
199+
200+
'/': [
201+
{
202+
text: 'Guide',
203+
items: [
204+
{ text: 'Introduction', link: '/' },
205+
{ text: 'User Guide', link: '/user-guide/' },
206+
{ text: 'Developer Guide', link: '/developer-guide/' },
207+
{ text: 'Rules', link: '/rules/' }
208+
]
209+
}
210+
]
211+
},
212+
213+
algolia: {
214+
appId: '2L4MGZSULB',
215+
apiKey: 'fdf57932b27a6c230d01a890492ab76d',
216+
indexName: 'eslint-plugin-vue'
217+
}
218+
}
219+
})
220+
}

0 commit comments

Comments
 (0)