Skip to content

Commit 3095106

Browse files
janvennemannulivz
authored andcommitted
fix: async function support for additionalPages plugin (close: #1077)(#1080)
1 parent 172afa3 commit 3095106

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
3+
const AsyncOption = require('../abstract/AsyncOption')
4+
5+
/**
6+
* additionalPages option.
7+
*/
8+
9+
module.exports = class AdditionalPagesOption extends AsyncOption {
10+
async apply (ctx) {
11+
await super.asyncApply()
12+
13+
await Promise.all(
14+
this.appliedValues.map(async (options) => {
15+
await ctx.addPage(options)
16+
})
17+
)
18+
}
19+
}

packages/@vuepress/core/lib/plugin-api/override/instantiateOption.js

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const ClientDynamicModulesOption = require('./ClientDynamicModulesOption')
33
const GlobalUIComponentsOption = require('./GlobalUIComponentsOption')
44
const DefineOption = require('./DefineOption')
55
const AliasOption = require('./AliasOption')
6+
const AdditionalPagesOption = require('./AdditionalPagesOption')
67
const Option = require('../abstract/Option')
78
const { PLUGIN_OPTION_MAP } = require('../constants')
89

@@ -23,6 +24,9 @@ module.exports = function instantiateOption (name) {
2324
case PLUGIN_OPTION_MAP.ALIAS.name:
2425
return new AliasOption(name)
2526

27+
case PLUGIN_OPTION_MAP.ADDITIONAL_PAGES.name:
28+
return new AdditionalPagesOption(name)
29+
2630
default: return new Option(name)
2731
}
2832
}

packages/@vuepress/core/lib/prepare/AppContext.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,7 @@ module.exports = class AppContext {
103103
this.markdown = createMarkdown(this)
104104

105105
await this.resolvePages()
106-
await Promise.all(
107-
this.pluginAPI.options.additionalPages.values.map(async (options) => {
108-
await this.addPage(options)
109-
})
110-
)
106+
await this.pluginAPI.options.additionalPages.apply(this)
111107

112108
await this.pluginAPI.options.ready.apply()
113109
await Promise.all([

packages/docs/docs/plugin/option-api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export default {
354354

355355
## additionalPages
356356

357-
- Type: `Array|Function`
357+
- Type: `Array|AsyncFunction`
358358
- Default: `undefined`
359359

360360
Add a page pointing to a markdown file:

0 commit comments

Comments
 (0)