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

Commit 3dd3a57

Browse files
yangbillyyyyy3320
yang
authored andcommitted
feat: Support configuring frontmatter classifiers scope layout (#24)
* feat($core): support configure frontmatter classifier scope layout * docs: update documentation * feat: change fallback layout * docs: update documentation
1 parent 996e759 commit 3dd3a57

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

Diff for: docs/config/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ Entry page for current classifier, e.g. `/` or `/post/`.
154154

155155
Layout component name for entry page.
156156

157+
### scopeLayout
158+
159+
- Type: `string`
160+
- Default: `undefined`
161+
- Required: `false`
162+
163+
Layout component name for scope page.
157164

158165
### frontmatter
159166

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

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Getting Started
22

33
::: tip
4-
This section is a step-by-step tutorial with some concepts, and we recommend that you read it completely before using
4+
This section is a step-by-step tutorial with some concepts, and we recommend that you read it completely before using
55
this plugin.
66
:::
77

@@ -24,8 +24,8 @@ Suppose you have the following files structure:
2424

2525
```vue
2626
.
27-
└── _posts   
28-
├── 2018-4-4-intro-to-vuepress.md   
27+
└── _posts   
28+
├── 2018-4-4-intro-to-vuepress.md   
2929
└── 2019-6-8-intro-to-vuepress-next.md
3030
```
3131

@@ -247,7 +247,9 @@ module.exports = {
247247
// Path of the `entry page` (or `list page`)
248248
path: '/tag/',
249249
// Layout of the `entry page`
250-
layout: 'Tag',
250+
layout: 'Tags',
251+
// Layout of the `scope page`
252+
scopeLayout: 'Tag'
251253
},
252254
],
253255
},
@@ -261,13 +263,13 @@ the corresponding layout:
261263

262264
| url | layout |
263265
| ----------- | ---------------------------------- |
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) |
266+
| `/tag/` | `Tags` (fallback to `FrontmatterKey` if not exist) |
267+
| `/tag/vue/` | `Tag` (fallback to `FrontmatterPagination` if not exist) |
268+
| `/tag/js/` | `Tag` (fallback to `FrontmatterPagination` if not exist) |
267269

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
270+
In the `<Tags />` component, you can use [this.$frontmatterKey.list](../client-api/README.md#frontmatterkey) to get the
271+
tag
272+
list. The value
271273
would be like:
272274

273275
```json
@@ -290,7 +292,7 @@ would be like:
290292
]
291293
```
292294

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

@@ -318,7 +320,7 @@ classification:
318320

319321
## Writing a blog theme
320322

321-
If everything is ok, you can start to write a blog theme. Actually, there are only 2 necessary layout components to
323+
If everything is ok, you can start to write a blog theme. Actually, there are only 2 necessary layout components to
322324
create a blog theme:
323325

324326
- Layout
@@ -329,4 +331,3 @@ Here are two official examples (A simple & a complex) for you:
329331

330332
- [70-lines-of-vuepress-blog-theme](https://github.com/ulivz/70-lines-of-vuepress-blog-theme): A VuePress Blog Theme implemented in around 70 lines.
331333
- [@vuepress/theme-blog](https://github.com/ulivz/vuepress-theme-blog): Default blog theme for VuePress.
332-

Diff for: src/node/handleOptions.ts

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export function handleOptions(
133133
keys,
134134
path: indexPath,
135135
layout: indexLayout,
136+
scopeLayout,
136137
frontmatter,
137138
pagination = {
138139
lengthPerPage: 10,
@@ -164,6 +165,7 @@ export function handleOptions(
164165
pagination,
165166
keys,
166167
map,
168+
scopeLayout,
167169
_handler: curryFrontmatterHandler(id, map),
168170
})
169171
}

Diff for: src/node/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
9595
...extraPages,
9696
...frontmatterClassificationPages
9797
.map(frontmatterClassifiedPage => {
98-
const { map, pagination, keys } = frontmatterClassifiedPage
98+
const { map, pagination, keys, scopeLayout } = frontmatterClassifiedPage
9999
return Object.keys(map).map(key => {
100100
const { path, scope } = map[key]
101101

@@ -129,7 +129,7 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
129129
pid: scope,
130130
id: key,
131131
frontmatter: {
132-
layout: DefaultLayoutEnum.FrontmatterPagination,
132+
layout: ctx.getLayout(scopeLayout, DefaultLayoutEnum.FrontmatterPagination),
133133
title: `${key} ${scope}`,
134134
},
135135
}

Diff for: src/node/interface/Frontmatter.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface FrontmatterClassificationPage {
55
id: string;
66
pagination: PaginationConfig;
77
keys: string[];
8+
scopeLayout?: string;
89
map: Record<string, any>;
910
_handler: FrontmatterHandler;
1011
}

Diff for: src/node/interface/Options.ts

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ export interface FrontmatterClassifier {
6161
* Layout for index page.
6262
*/
6363
layout?: string;
64+
/**
65+
* Layout for scope page.
66+
* e.g. {id: 'tag', keys: ['tag'], scopeLayout: 'Foo'}
67+
* `/tag/vue` will use `Foo.vue` as the layout
68+
*/
69+
scopeLayout?: string;
6470
/**
6571
* Frontmatter for index page.
6672
*/

0 commit comments

Comments
 (0)