Skip to content

Commit 379ca9b

Browse files
committed
Merge branch 'master' into register-command-plugin-api
2 parents 30b697f + 5ee2b2b commit 379ca9b

File tree

13 files changed

+61
-65
lines changed

13 files changed

+61
-65
lines changed

Diff for: README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ yarn add vuepress@next -D # Install next.
5252

5353
**Vue-powered custom theme system**
5454

55-
* [Metadata](https://vuepress.vuejs.org/guide/custom-themes.html#site-and-page-metadata)
56-
* [Content Excerpt](https://vuepress.vuejs.org/guide/custom-themes.html#content-excerpt)
55+
* [Metadata](https://vuepress.vuejs.org/theme/writing-a-theme.html#site-and-page-metadata)
56+
* [Content Excerpt](https://vuepress.vuejs.org/theme/writing-a-theme.html#content-excerpt)
5757

5858
**Default theme**
5959

6060
* Responsive layout
61-
* [Optional Homepage](https://vuepress.vuejs.org/default-theme-config/#homepage)
62-
* [Simple out-of-the-box header-based search](https://vuepress.vuejs.org/default-theme-config/#built-in-search)
63-
* [Algolia Search](https://vuepress.vuejs.org/default-theme-config/#algolia-search)
64-
* Customizable [navbar](https://vuepress.vuejs.org/default-theme-config/#navbar) and [sidebar](https://vuepress.vuejs.org/default-theme-config/#sidebar)
65-
* [Auto-generated GitHub link and page edit links](https://vuepress.vuejs.org/default-theme-config/#git-repo-and-edit-links)
66-
* [PWA: Popup UI to refresh contents](https://vuepress.vuejs.org/default-theme-config/#popup-ui-to-refresh-contents)
67-
* [Last Updated](https://vuepress.vuejs.org/default-theme-config/#last-updated)
61+
* [Optional Homepage](https://vuepress.vuejs.org/theme/default-theme-config.html#homepage)
62+
* [Simple out-of-the-box header-based search](https://vuepress.vuejs.org/theme/default-theme-config.html#built-in-search)
63+
* [Algolia Search](https://vuepress.vuejs.org/theme/default-theme-config.html#algolia-search)
64+
* Customizable [navbar](https://vuepress.vuejs.org/theme/default-theme-config.html#navbar) and [sidebar](https://vuepress.vuejs.org/theme/default-theme-config.html#sidebar)
65+
* [Auto-generated GitHub link and page edit links](https://vuepress.vuejs.org/theme/default-theme-config.html#git-repo-and-edit-links)
66+
* [PWA: Popup UI to refresh contents](https://vuepress.vuejs.org/theme/default-theme-config.html#popup-ui-to-refresh-contents)
67+
* [Last Updated](https://vuepress.vuejs.org/theme/default-theme-config.html#last-updated)
6868

6969
**Miscellaneous**
7070

Diff for: packages/@vuepress/core/lib/app/app.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,15 @@ export function createApp (isServer) {
6262
base: siteData.base,
6363
mode: 'history',
6464
fallback: false,
65-
routes
65+
routes,
66+
scrollBehavior (to, from, savedPosition) {
67+
if (savedPosition) {
68+
return savedPosition
69+
}
70+
if (to.path !== from.path) {
71+
return { x: 0, y: 0 }
72+
}
73+
}
6674
})
6775

6876
// redirect /foo to /foo/
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,13 @@
1-
import SmoothScroll from 'smooth-scroll/dist/smooth-scroll.js'
2-
31
export default {
42
created () {
53
this.$vuepress.$on('AsyncMarkdownContentMounted', () => {
64
this.$vuepress.$set('contentMounted', true)
7-
8-
this.$smoothScroll = new SmoothScroll('a[href*="#"]', {
9-
speed: 1,
10-
speedAsDuration: true,
11-
easing: 'easeInOutCubic'
12-
})
13-
14-
if (this.$route.hash) {
15-
const hash = decodeURIComponent(this.$route.hash)
16-
try {
17-
const anchor = document.getElementById(hash.slice(1))
18-
const anchorLink = anchor.querySelector('a.header-anchor')
19-
setTimeout(() => {
20-
window.scroll({
21-
top: anchorLink.offsetTop - 70,
22-
left: 0,
23-
behavior: 'auto'
24-
})
25-
})
26-
} catch (e) {
27-
console.error(e)
28-
}
29-
}
305
})
316
},
327

338
watch: {
349
'$route.path' () {
3510
this.$vuepress.$set('contentMounted', false)
36-
this.$smoothScroll.destroy()
3711
}
38-
},
39-
40-
beforeDestroy () {
41-
this.$smoothScroll.destroy()
4212
}
4313
}

Diff for: packages/@vuepress/core/lib/build.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,23 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
6363
.map(renderHeadTag)
6464
.join('\n ')
6565

66+
// if the user does not have a custom 404.md, generate the theme's default
67+
if (!ctx.pages.some(p => p.path === '/404.html')) {
68+
ctx.addPage({ path: '/404.html' })
69+
}
70+
6671
// render pages
6772
logger.wait('Rendering static HTML...')
68-
for (const page of ctx.pages) {
69-
await renderPage(page)
70-
}
7173

72-
// if the user does not have a custom 404.md, generate the theme's default
73-
if (!ctx.pages.some(p => p.path === '/404.html')) {
74-
await renderPage({ path: '/404.html' })
74+
const pagePaths = []
75+
for (const page of ctx.pages) {
76+
pagePaths.push(await renderPage(page))
7577
}
7678

7779
readline.clearLine(process.stdout, 0)
7880
readline.cursorTo(process.stdout, 0)
7981

80-
await ctx.pluginAPI.options.generated.apply()
82+
await ctx.pluginAPI.options.generated.apply(pagePaths)
8183

8284
// DONE.
8385
const relativeDir = path.relative(cwd, outDir)
@@ -155,6 +157,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
155157
const filePath = path.resolve(outDir, filename)
156158
await fs.ensureDir(path.dirname(filePath))
157159
await fs.writeFile(filePath, html)
160+
return filePath
158161
}
159162

160163
function renderPageMeta (meta) {

Diff for: packages/@vuepress/core/lib/plugin-api/abstract/AsyncOption.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AsyncOption extends Option {
3030
this.add(
3131
name,
3232
isFunction(value)
33-
? await value(...args)
33+
? await Promise.resolve(value(...args))
3434
: value
3535
)
3636
} catch (error) {
@@ -60,7 +60,7 @@ class AsyncOption extends Option {
6060
this.add(
6161
name,
6262
isFunction(value)
63-
? await value(...args)
63+
? await Promise.resolve(value(...args))
6464
: value
6565
)
6666
} catch (error) {
@@ -84,7 +84,7 @@ class AsyncOption extends Option {
8484

8585
async pipeline (input) {
8686
for (const fn of this.values) {
87-
input = await fn(input)
87+
input = await Promise.resolve(fn(input))
8888
}
8989
return input
9090
}

Diff for: packages/@vuepress/core/lib/plugin-api/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const PLUGIN_OPTION_META_MAP = {
55
READY: { name: 'ready', types: [Function] },
66
COMPILED: { name: 'compiled', types: [Function] },
77
UPDATED: { name: 'updated', types: [Function] },
8-
GENERATED: { name: 'generated', types: [Function] },
8+
GENERATED: { name: 'generated', types: [Function], async: true },
99
// options
1010
CHAIN_WEBPACK: { name: 'chainWebpack', types: [Function] },
1111
ENHANCE_DEV_SERVER: { name: 'enhanceDevServer', types: [Function] },

Diff for: packages/@vuepress/core/lib/plugin-api/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ module.exports = class PluginAPI {
147147
initializeOptions () {
148148
Object.keys(PLUGIN_OPTION_MAP).forEach(key => {
149149
const option = PLUGIN_OPTION_MAP[key]
150-
this.options[option.name] = instantiateOption(option.name)
150+
this.options[option.name] = instantiateOption(option)
151151
})
152152
}
153153

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+
}

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ const ClientDynamicModulesOption = require('./ClientDynamicModulesOption')
33
const GlobalUIComponentsOption = require('./GlobalUIComponentsOption')
44
const DefineOption = require('./DefineOption')
55
const AliasOption = require('./AliasOption')
6+
const AsyncOption = require('../abstract/AsyncOption')
7+
const AdditionalPagesOption = require('./AdditionalPagesOption')
68
const Option = require('../abstract/Option')
79
const { PLUGIN_OPTION_MAP } = require('../constants')
810

9-
module.exports = function instantiateOption (name) {
11+
module.exports = function instantiateOption ({ name, async }) {
1012
switch (name) {
1113
case PLUGIN_OPTION_MAP.ENHANCE_APP_FILES.name:
1214
return new EnhanceAppFilesOption(name)
@@ -23,6 +25,9 @@ module.exports = function instantiateOption (name) {
2325
case PLUGIN_OPTION_MAP.ALIAS.name:
2426
return new AliasOption(name)
2527

26-
default: return new Option(name)
28+
case PLUGIN_OPTION_MAP.ADDITIONAL_PAGES.name:
29+
return new AdditionalPagesOption(name)
30+
31+
default: return async ? new AsyncOption(name) : new Option(name)
2732
}
2833
}

Diff for: packages/@vuepress/core/lib/prepare/AppContext.js

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

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

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

Diff for: packages/@vuepress/core/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"optimize-css-assets-webpack-plugin": "^4.0.0",
5656
"portfinder": "^1.0.13",
5757
"postcss-loader": "^2.1.5",
58-
"smooth-scroll": "^15.0.0",
5958
"toml": "^2.3.3",
6059
"url-loader": "^1.0.1",
6160
"vue": "^2.5.16",

Diff for: 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:

Diff for: yarn.lock

-4
Original file line numberDiff line numberDiff line change
@@ -7606,10 +7606,6 @@ [email protected]:
76067606
dependencies:
76077607
is-fullwidth-code-point "^2.0.0"
76087608

7609-
smooth-scroll@^15.0.0:
7610-
version "15.0.0"
7611-
resolved "https://registry.yarnpkg.com/smooth-scroll/-/smooth-scroll-15.0.0.tgz#be4f9cb2cc4952d80db6736e5656ed5849305272"
7612-
76137609
snapdragon-node@^2.0.1:
76147610
version "2.1.1"
76157611
resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"

0 commit comments

Comments
 (0)