Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1077: async function support for additionalPages plugin #1080

Merged
merged 1 commit into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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