Skip to content

Commit 2428dca

Browse files
Add vitepress-plugin-group-icons (#46)
1 parent 23e44a5 commit 2428dca

9 files changed

+197
-34
lines changed

docs/.vitepress/config.mts

+18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineConfig } from 'vitepress'
2+
import { groupIconMdPlugin, groupIconVitePlugin } from 'vitepress-plugin-group-icons'
23

34
export default defineConfig({
45
title: 'Vue Land FAQ',
@@ -21,6 +22,23 @@ export default defineConfig({
2122
}
2223
},
2324

25+
markdown: {
26+
config(md) {
27+
md.use(groupIconMdPlugin)
28+
},
29+
},
30+
31+
vite: {
32+
plugins: [
33+
groupIconVitePlugin({
34+
customIcon: {
35+
'.vue': 'vscode-icons:file-type-vue',
36+
'vue': 'vscode-icons:file-type-js'
37+
}
38+
})
39+
],
40+
},
41+
2442
themeConfig: {
2543
logo: '/logo.svg',
2644

docs/.vitepress/theme/custom.css

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ html:not(.dark) {
4747
border-top: 0 none;
4848
}
4949

50+
.vp-code-block-title-bar {
51+
border: 1px solid var(--vue-land-code-block-border);
52+
border-bottom: 0 none;
53+
box-shadow: none;
54+
}
55+
5056
/* Inline code in a custom block looks too much like a link */
5157
.custom-block.info code, .custom-block.tip code {
5258
color: var(--vp-code-color);

docs/.vitepress/theme/index.ts

+1
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 './custom.css'
34

45
export default DefaultTheme

docs/faq/accessing-the-route.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ It is still possible to access `useRoute()` or `this.$route` during that initial
5858

5959
Consider the following example. It tries to use the current route in `App.vue` to decide which layout to wrap around the `RouterView`:
6060

61-
```vue
62-
<!-- App.vue -->
61+
```vue [App.vue]
6362
<script setup>
6463
import DefaultLayout from './layouts/DefaultLayout.vue'
6564
</script>
@@ -79,10 +78,7 @@ There are a few ways we might fix this problem.
7978

8079
Vue Router provides the method [`isReady()`](https://router.vuejs.org/api/interfaces/Router.html#isReady), which can be used to wait until it has resolved the route. We could use it to defer mounting the application until the route is ready:
8180

82-
```js
83-
// main.js or main.ts
84-
// ...
85-
81+
```js [main.js]
8682
const app = createApp(App)
8783

8884
app.use(router)
@@ -102,8 +98,7 @@ Depending on your application, that might not matter. A brief pause before the p
10298

10399
With a bit of extra effort, we could show a loading indicator if the route isn't resolved yet. There are a few ways we might implement this. One approach would be to use `router.isReady()` inside `App.vue` to track when the router is ready. e.g.:
104100

105-
```vue
106-
<!-- App.vue -->
101+
```vue [App.vue]
107102
<script setup>
108103
import { shallowRef } from 'vue'
109104
import { useRouter } from 'vue-router'
@@ -128,8 +123,7 @@ Here we're using the `LoadingIndicator` component in place of the layout. The `L
128123

129124
We could also implement this using the slot of `RouterView`:
130125

131-
```vue
132-
<!-- App.vue -->
126+
```vue [App.vue]
133127
<script setup>
134128
import DefaultLayout from './layouts/DefaultLayout.vue'
135129
import LoadingIndicator from './components/LoadingIndicator.vue'

docs/faq/blank-page-in-production.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Usually it's fairly obvious when this is happening, as the rest of the page rend
121121

122122
However, it can be tricky to tell whether routing is the problem if `App.vue` doesn't contain anything else. For example, imagine that `App.vue` just contains this:
123123

124-
```vue
124+
```vue [App.vue]
125125
<template>
126126
<RouterView />
127127
</template>
@@ -131,7 +131,7 @@ As `App.vue` only renders `<RouterView />`, we can't easily tell whether the pro
131131

132132
To help isolate the source of the problem, it is worth adding some extra temporary code to `App.vue`, to confirm that it is rendering correctly. For example:
133133

134-
```vue
134+
```vue [App.vue]
135135
<template>
136136
<h1>Hello world!</h1>
137137
<RouterView />

docs/faq/no-active-pinia.md

+12-20
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,13 @@ The error is shown when step 3 occurs before step 2. The Pinia instance must be
189189

190190
But, in practice, it probably isn't that simple. In a real application, those 3 steps usually don't sit in the same file. More likely, they're in 3 separate files, something like this:
191191

192-
```js
193-
// useProductsStore.js
192+
```js [useProductsStore.js]
194193
export const useProductsStore = defineStore('products', {
195194
// ...
196195
})
197196
```
198197

199-
```js
200-
// main.js
198+
```js [main.js]
201199
import { createApp } from 'vue'
202200
import { createPinia } from 'pinia'
203201
import App from 'App.vue'
@@ -221,15 +219,13 @@ To understand that, we first need to understand `import`, and specifically how J
221219

222220
Let's start with a plain `.js` example. It works much the same way with `.ts` and we'll stick to `.js` throughout this page. It's a bit more complicated with `.vue` files, but we'll cover those later.
223221

224-
```js
225-
// main.js
222+
```js [main.js]
226223
import { data } from './store.js'
227224

228225
console.log('main.js', data)
229226
```
230227

231-
```js
232-
// store.js
228+
```js [store.js]
233229
const data = { name: 'Vue' }
234230

235231
console.log('store.js', data)
@@ -382,8 +378,7 @@ Generally speaking, you shouldn't be trying to access the store in top-level cod
382378

383379
Let's say we have some code like this:
384380

385-
```js
386-
// product-utils.js
381+
```js [product-utils.js]
387382
import { useProductsStore } from '@/stores/products'
388383

389384
const products = useProductsStore()
@@ -401,8 +396,7 @@ When exactly this happens will depend on exactly where this file is imported. If
401396

402397
In the example above, we might fix it by moving the call to `useProductsStore()` inside `fetchProduct()`:
403398

404-
```js
405-
// product-utils.js
399+
```js [product-utils.js]
406400
import { useProductsStore } from '@/stores/products'
407401

408402
export function fetchProduct(id) {
@@ -572,8 +566,7 @@ This can cause a lot of confusion, as top-level code can appear to work in some
572566

573567
Let's revisit an example we saw earlier:
574568

575-
```js
576-
// product-utils.js
569+
```js [product-utils.js]
577570
import { useProductsStore } from '@/stores/products'
578571

579572
const products = useProductsStore()
@@ -607,7 +600,7 @@ The Pinia instance will be created when the page first loads. If you edit one of
607600

608601
Let's imagine we have code like this in our `main.js`:
609602

610-
```js
603+
```js [main.js]
611604
import { createApp } from 'vue'
612605
import { createPinia } from 'pinia'
613606
import App from './App.vue'
@@ -630,7 +623,7 @@ Yes, we can. This almost certainly isn't a good idea, but it can work.
630623

631624
For example, let's move some of the code above into a file called `app-create.js`:
632625

633-
```js
626+
```js [app-create.js]
634627
import { createApp } from 'vue'
635628
import { createPinia } from 'pinia'
636629
import App from './App.vue'
@@ -643,7 +636,7 @@ export { app }
643636

644637
Then, we could change our `main.js` to this:
645638

646-
```js
639+
```js [main.js]
647640
import { app } from './app-create'
648641
import router from './router'
649642

@@ -664,8 +657,7 @@ In the case of Pinia, it aims to be global in the same way that [`app.config.glo
664657

665658
Let's imagine you choose not to use Pinia and instead do something like this:
666659

667-
```js
668-
// store.js
660+
```js [store.js]
669661
import { reactive } from 'vue'
670662

671663
export const state = reactive({})
@@ -731,7 +723,7 @@ import { loadProducts } from './products'
731723

732724
So far, no store. Now let's take a look at `products.js`:
733725

734-
```js
726+
```js [products.js]
735727
import { useProductsStore } from '@/stores/products'
736728

737729
export async function loadProducts() {

docs/faq/unique-element-ids.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ In many cases, it's sufficient to use a simple counter to generate a suitable `i
1010

1111
Put something like this in a `.js` file:
1212

13-
```js
13+
```js [utils/id.js]
1414
let count = 0
1515

1616
export function newId(prefix = 'id-') {

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"devDependencies": {
1010
"rimraf": "^6.0.1",
11-
"vitepress": "^1.4.3"
11+
"vitepress": "^1.4.3",
12+
"vitepress-plugin-group-icons": "^1.3.3"
1213
}
1314
}

0 commit comments

Comments
 (0)