Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 7eb1ef4

Browse files
committed
feat: more abstract $frontmatterKey to yield multiple frontmatter classifiers
1 parent d912eae commit 7eb1ef4

File tree

4 files changed

+39
-14
lines changed

4 files changed

+39
-14
lines changed

Diff for: docs/client-api/README.md

+14-6
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ You can use this function to custom the pagination component as the internal
5959
:::
6060

6161

62-
## `$${FCID}`
62+
## $frontmatterKey
6363

64-
FCID, i.e the id of [Frontmatter Classifier](../guide/getting-started.md#frontmatter-classifier), if you create a
65-
[Frontmatter Classifier](../guide/getting-started.md#frontmatter-classifier) as follows:
64+
if you create a [Frontmatter Classifier](../guide/getting-started.md#frontmatter-classifier) as follows:
6665

6766
```js
6867
module.exports = {
@@ -88,17 +87,17 @@ module.exports = {
8887
}
8988
```
9089

91-
Then this plugin will inject a `$tag` object to the prototype of Vue, so you can use it directly at your
90+
Then this plugin will inject a `$frontmatterKey` object to the prototype of Vue, so you can use it directly at your
9291
layout component (`<Tag />`).
9392

94-
### `$${FCID}.list`
93+
### `$frontmatterKey.list`
9594

9695
Get the list of matched frontmatter classifier types.
9796

9897
The interface is as follows:
9998

10099
```typescript
101-
type FCID = Array<{
100+
type FrontmatterKeyList = Array<{
102101
name: string;
103102
path: string;
104103
pages: Array<VuePressPage>;
@@ -107,3 +106,12 @@ type FCID = Array<{
107106
108107
You can re-read the [Frontmatter Classifier](../guide/getting-started.md#frontmatter-classifier) to see the live
109108
example of `tag`.
109+
110+
::: tip Multiple Frontmatter Classifiers
111+
112+
If you create two frontmatter classifiers, e.g. `tag` and `category`, then in `/tag/` route, the `$frontmatterKey` will
113+
automatically point to `tag`, while in `/category/`, it will point to `category`.
114+
115+
This variable is essentially designed to generalize the list page of frontmatter keys
116+
117+
:::

Diff for: docs/guide/getting-started.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ the data structure of `$page` at the [official documentation](https://v1.vuepres
200200

201201
- [Pagination Config](../pagination/README.md)
202202

203-
### Frontmatter Classifier
203+
## Frontmatter Classifier
204204

205205
Frontmatter Classifier, which classifies pages that have the same frontmatter key values.
206206

@@ -261,11 +261,14 @@ the corresponding layout:
261261

262262
| url | layout |
263263
| ----------- | ---------------------------------- |
264-
| `/tag/` | `Tag` |
265-
| `/tag/vue/` | `FrontmatterPagination` / `Layout` |
266-
| `/tag/js/` | `FrontmatterPagination` / `Layout` |
264+
| `/tag/` | `Tag` (fallback to `FrontmatterKey` if not exist) |
265+
| `/tag/vue/` | `FrontmatterPagination` (fallback to `Layout` if not exist) |
266+
| `/tag/js/` | `FrontmatterPagination` (fallback to `Layout` if not exist) |
267267

268-
In the `<Tag />` component, you can use `this.$tag.list` to get the tag list. The value would be like:
268+
In the `<Tag />` component, you can use [this.$frontmatterKey.list](../client-api/README.md#frontmatterkey) to get the
269+
tag
270+
list. The value
271+
would be like:
269272

270273
```json
271274
[
@@ -287,7 +290,8 @@ In the `<Tag />` component, you can use `this.$tag.list` to get the tag list. Th
287290
]
288291
```
289292

290-
In the `FrontmatterPagination` component, you can use `this.$pagination.pages` to get the matched pages in current tag
293+
In the `FrontmatterPagination` component, you can use
294+
[this.$pagination.pages](../client-api/README.md#pagination) to get the matched pages in current tag
291295
classification:
292296

293297
- If you visit `/tag/vue/`, the `this.$pagination.pages` will be:
@@ -319,7 +323,7 @@ create a blog theme:
319323

320324
- Layout
321325
- Post
322-
- Tag (Only required when you set up a `tag` frontmatter classification.)
326+
- FrontmatterKey (Only required when you set up a frontmatter classification.)
323327

324328
Here are two official examples (A simple & a complex) for you:
325329

Diff for: src/client/classification.ts

+9
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ export default ({ Vue }) => {
7676
return map
7777
}, {})
7878

79+
computed.$frontmatterKey = function() {
80+
// @ts-ignore
81+
const target = this[`$${this.$route.meta.id}`]
82+
if (target) {
83+
return target
84+
}
85+
return null
86+
}
87+
7988
Vue.mixin({
8089
computed,
8190
})

Diff for: src/node/handleOptions.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,14 @@ export function handleOptions(
130130
permalink: indexPath,
131131
frontmatter: {
132132
// Set layout for index page.
133-
layout: ctx.getLayout(indexLayout),
133+
layout: ctx.getLayout(indexLayout, 'FrontmatterKey'),
134134
title: `${UpperFirstChar(id)}`,
135135
...frontmatter,
136136
},
137+
meta: {
138+
pid: id,
139+
id,
140+
},
137141
})
138142

139143
const map = {} as FrontmatterTempMap

0 commit comments

Comments
 (0)