Skip to content

Commit f2ed62c

Browse files
yuyinwsposva
authored andcommitted
docs: enhance code block & code group
1 parent bb3b721 commit f2ed62c

File tree

18 files changed

+136
-41
lines changed

18 files changed

+136
-41
lines changed

packages/docs/.vitepress/config/shared.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { defineConfig, HeadConfig } from 'vitepress'
22
import { zhSearch } from './zh'
3+
import {
4+
groupIconMdPlugin,
5+
groupIconVitePlugin,
6+
} from 'vitepress-plugin-group-icons'
37

48
// TODO:
59
// export const META_IMAGE = 'https://router.vuejs.org/social.png'
@@ -60,6 +64,9 @@ export const sharedConfig = defineConfig({
6064
anchor: {
6165
slugify,
6266
},
67+
config: md => {
68+
md.use(groupIconMdPlugin)
69+
},
6370
},
6471

6572
head: [
@@ -161,4 +168,7 @@ export const sharedConfig = defineConfig({
161168
placement: 'routervuejsorg',
162169
},
163170
},
171+
vite: {
172+
plugins: [groupIconVitePlugin()],
173+
},
164174
})

packages/docs/.vitepress/theme/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import VueSchoolLink from './components/VueSchoolLink.vue'
99
import VueMasteryLogoLink from './components/VueMasteryLogoLink.vue'
1010
import status from '../translation-status.json'
1111
import RuleKitLink from './components/RuleKitLink.vue'
12+
import 'virtual:group-icons.css'
1213

1314
const i18nLabels = {
1415
zh: '该翻译已同步到了 ${date} 的版本,其对应的 commit hash 是 <code>${hash}</code>。',

packages/docs/guide/advanced/lazy-loading.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ webpack will group any async module with the same chunk name into the same async
6767

6868
In Vite you can define the chunks under the [`rollupOptions`](https://vite.dev/config/build-options.html#build-rollupoptions):
6969

70-
```js
71-
// vite.config.js
70+
```js [vite.config.js]
7271
export default defineConfig({
7372
build: {
7473
rollupOptions: {

packages/docs/guide/advanced/navigation-guards.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ Learn more about navigation failures on [its guide](./navigation-failures.md).
140140

141141
Since Vue 3.3, it is possible to use `inject()` within navigation guards. This is useful for injecting global properties like the [pinia stores](https://pinia.vuejs.org). Anything that is provided with `app.provide()` is also accessible within `router.beforeEach()`, `router.beforeResolve()`, `router.afterEach()`:
142142

143-
```ts
144-
// main.ts
143+
```ts [main.ts]
145144
const app = createApp(App)
146145
app.provide('global', 'hello injections')
147146

packages/docs/guide/essentials/history-mode.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ For Node.js/Express, consider using [connect-history-api-fallback middleware](ht
128128
1. Install [IIS UrlRewrite](https://www.iis.net/downloads/microsoft/url-rewrite)
129129
2. Create a `web.config` file in the root directory of your site with the following:
130130

131-
```xml
131+
```xml [web.config ~vscode-icons:file-type-xml~]
132132
<?xml version="1.0" encoding="UTF-8"?>
133133
<configuration>
134134
<system.webServer>
@@ -167,7 +167,7 @@ rewrite {
167167

168168
Add this to your `firebase.json`:
169169

170-
```json
170+
```json [firebase.json ~vscode-icons:file-type-firebase~]
171171
{
172172
"hosting": {
173173
"public": "dist",
@@ -197,7 +197,7 @@ You can read more about the syntax on [Netlify documentation](https://docs.netli
197197

198198
Create a `vercel.json` file under the root directory of your project with the following:
199199

200-
```json
200+
```json [vercel.json ~vscode-icons:file-type-light-vercel~]
201201
{
202202
"rewrites": [{ "source": "/:path*", "destination": "/index.html" }]
203203
}

packages/docs/guide/essentials/named-views.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ It is possible to create complex layouts using named views with nested views. Wh
6161

6262
The `<template>` section for `UserSettings` component in the above layout would look something like this:
6363

64-
```vue-html
65-
<!-- UserSettings.vue -->
64+
```vue-html [UserSettings.vue]
6665
<div>
6766
<h1>User Settings</h1>
6867
<NavBar />

packages/docs/guide/essentials/nested-routes.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ With Vue Router, you can express this relationship using nested route configurat
2222

2323
Given the app we created in the last chapter:
2424

25-
```vue
26-
<!-- App.vue -->
25+
```vue [App.vue]
2726
<template>
2827
<router-view />
2928
</template>
3029
```
3130

32-
```vue
33-
<!-- User.vue -->
31+
```vue [User.vue]
3432
<template>
3533
<div>
3634
User {{ $route.params.id }}
@@ -47,8 +45,7 @@ const routes = [{ path: '/user/:id', component: User }]
4745

4846
The `<router-view>` here is a top-level `router-view`. It renders the component matched by a top level route. Similarly, a rendered component can also contain its own, nested `<router-view>`. For example, if we add one inside the `User` component's template:
4947

50-
```vue
51-
<!-- User.vue -->
48+
```vue [User.vue]
5249
<template>
5350
<div class="user">
5451
<h2>User {{ $route.params.id }}</h2>

packages/docs/guide/essentials/passing-props.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ Using `$route` or `useRoute()` in your component creates a tight coupling with t
99

1010
Let's return to our earlier example:
1111

12-
```vue
13-
<!-- User.vue -->
12+
```vue [User.vue]
1413
<template>
1514
<div>
1615
User {{ $route.params.id }}

packages/docs/guide/index.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ To introduce some of the main ideas, we're going to consider this example:
2222

2323
Let's start by looking at the root component, `App.vue`.
2424

25-
### App.vue
26-
27-
```vue
25+
```vue [App.vue]
2826
<template>
2927
<h1>Hello App!</h1>
3028
<p><strong>Current route path:</strong> {{ $route.fullPath }}</p>

packages/docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"typedoc-vitepress-theme": "^1.1.2",
1818
"vitepress": "1.6.4",
1919
"vitepress-translation-helper": "^0.2.2",
20+
"vitepress-plugin-group-icons": "^1.6.1",
2021
"vue-router": "workspace:*"
2122
}
2223
}

0 commit comments

Comments
 (0)