Skip to content

Commit

Permalink
fix: async function support for additionalPages plugin (close: #1077)(#…
Browse files Browse the repository at this point in the history
  • Loading branch information
janvennemann authored and ulivz committed Dec 7, 2018
1 parent 172afa3 commit 3095106
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

const AsyncOption = require('../abstract/AsyncOption')

/**
* additionalPages option.
*/

module.exports = class AdditionalPagesOption extends AsyncOption {
async apply (ctx) {
await super.asyncApply()

await Promise.all(
this.appliedValues.map(async (options) => {
await ctx.addPage(options)
})
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const ClientDynamicModulesOption = require('./ClientDynamicModulesOption')
const GlobalUIComponentsOption = require('./GlobalUIComponentsOption')
const DefineOption = require('./DefineOption')
const AliasOption = require('./AliasOption')
const AdditionalPagesOption = require('./AdditionalPagesOption')
const Option = require('../abstract/Option')
const { PLUGIN_OPTION_MAP } = require('../constants')

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

case PLUGIN_OPTION_MAP.ADDITIONAL_PAGES.name:
return new AdditionalPagesOption(name)

default: return new Option(name)
}
}
6 changes: 1 addition & 5 deletions packages/@vuepress/core/lib/prepare/AppContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ module.exports = class AppContext {
this.markdown = createMarkdown(this)

await this.resolvePages()
await Promise.all(
this.pluginAPI.options.additionalPages.values.map(async (options) => {
await this.addPage(options)
})
)
await this.pluginAPI.options.additionalPages.apply(this)

await this.pluginAPI.options.ready.apply()
await Promise.all([
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/docs/plugin/option-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export default {

## additionalPages

- Type: `Array|Function`
- Type: `Array|AsyncFunction`
- Default: `undefined`

Add a page pointing to a markdown file:
Expand Down

0 comments on commit 3095106

Please sign in to comment.