File tree 3 files changed +20
-9
lines changed
packages/@vuepress/core/src
3 files changed +20
-9
lines changed Original file line number Diff line number Diff line change 1
1
import { globby } from '@vuepress/utils'
2
2
import { createPage } from '../page'
3
- import type { App , Page } from '../types'
3
+ import type { App , Page , PageOptions } from '../types'
4
4
5
5
/**
6
6
* Create pages for vuepress app
7
7
*/
8
8
export const createAppPages = async ( app : App ) : Promise < Page [ ] > => {
9
+ // resolve page file paths according to the page patterns
9
10
const pagePaths = await globby ( app . options . pagePatterns , {
10
11
cwd : app . dir . source ( ) ,
11
12
} )
12
13
13
- // TODO
14
- // may need to limit the max parallel tasks
15
- // or change to serial tasks
14
+ // create pages from files
16
15
const pages = await Promise . all (
17
- pagePaths . map ( ( filePath ) =>
18
- createPage ( app , {
16
+ pagePaths . map ( async ( filePath ) => {
17
+ const pageOptions : PageOptions = { filePath }
18
+
19
+ // plugin hook: extendsPageOptions
20
+ const extendsPageOptions = await app . pluginApi . hooks . extendsPageOptions . process (
19
21
filePath ,
20
- } )
21
- )
22
+ app
23
+ )
24
+ extendsPageOptions . forEach ( ( item ) => Object . assign ( pageOptions , item ) )
25
+
26
+ return createPage ( app , pageOptions )
27
+ } )
22
28
)
23
29
24
30
// if there is no 404 page, add one
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ export const createPluginApiHooks = (): PluginApi['hooks'] => ({
9
9
onGenerated : createHookQueue ( 'onGenerated' ) ,
10
10
11
11
// page hooks
12
+ extendsPageOptions : createHookQueue ( 'extendsPageOptions' ) ,
12
13
extendsPageData : createHookQueue ( 'extendsPageData' ) ,
13
14
14
15
// markdown hooks
Original file line number Diff line number Diff line change 1
1
import type { Markdown } from '@vuepress/markdown'
2
2
import type { App } from '../app'
3
- import type { Page } from '../page'
3
+ import type { Page , PageOptions } from '../page'
4
4
5
5
// util type
6
6
type PromiseOrNot < T > = Promise < T > | T
@@ -42,6 +42,9 @@ export type ReturnObjectHook = Hook<
42
42
export type ExtendsMarkdownHook = Hook < ( md : Markdown , app : App ) => void >
43
43
44
44
// page hook
45
+ export type ExtendsPageOptionsHook = Hook <
46
+ ( filePath : string , app : App ) => PromiseOrNot < PageOptions >
47
+ >
45
48
export type ExtendsPageDataHook = Hook <
46
49
( page : Page , app : App ) => PromiseOrNot < Record < string , any > >
47
50
>
@@ -55,6 +58,7 @@ export interface Hooks {
55
58
onWatched : LifeCycleHook < [ watchers : Closable [ ] , restart : ( ) => Promise < void > ] >
56
59
onGenerated : LifeCycleHook
57
60
extendsMarkdown : ExtendsMarkdownHook
61
+ extendsPageOptions : ExtendsPageOptionsHook
58
62
extendsPageData : ExtendsPageDataHook
59
63
clientAppEnhanceFiles : ClientFilesHook
60
64
clientAppRootComponentFiles : ClientFilesHook
You can’t perform that action at this time.
0 commit comments