@vuepress/core 2.0.0-beta.24 → 2.0.0-beta.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/app/appInit.js +5 -4
- package/lib/app/appPrepare.js +11 -11
- package/lib/app/appUse.js +3 -3
- package/lib/app/createAppDir.js +6 -6
- package/lib/app/createAppMarkdown.d.ts +6 -0
- package/lib/app/createAppMarkdown.js +16 -0
- package/lib/app/createAppPages.js +14 -5
- package/lib/app/createBaseApp.js +16 -19
- package/lib/app/createBuildApp.d.ts +1 -1
- package/lib/app/createBuildApp.js +2 -2
- package/lib/app/createDevApp.d.ts +1 -1
- package/lib/app/createDevApp.js +2 -2
- package/lib/app/index.d.ts +1 -1
- package/lib/app/index.js +1 -1
- package/lib/app/normalizePluginConfig.d.ts +1 -1
- package/lib/app/normalizePluginConfig.js +1 -1
- package/lib/app/prepare/preparePagesRoutes.js +5 -5
- package/lib/app/resolveBundler.js +1 -1
- package/lib/app/resolvePlugin.js +3 -3
- package/lib/app/resolvePluginModule.js +2 -2
- package/lib/app/resolvePluginsFromConfig.js +2 -2
- package/lib/app/resolveTheme.js +3 -3
- package/lib/app/resolveThemeInfo.d.ts +5 -0
- package/lib/app/resolveThemeInfo.js +28 -0
- package/lib/app/resolveThemeLayouts.js +1 -1
- package/lib/page/createPage.d.ts +1 -1
- package/lib/page/createPage.js +32 -24
- package/lib/page/index.d.ts +1 -2
- package/lib/page/index.js +1 -2
- package/lib/page/inferPagePath.js +2 -2
- package/lib/page/resolvePageContent.js +1 -1
- package/lib/page/resolvePageDate.d.ts +1 -1
- package/lib/page/resolvePageDate.js +5 -5
- package/lib/page/resolvePageFileContent.js +2 -2
- package/lib/page/resolvePageFilePath.d.ts +1 -1
- package/lib/page/resolvePageFilePath.js +6 -11
- package/lib/page/resolvePageHtmlInfo.js +1 -1
- package/lib/page/resolvePageKey.js +1 -1
- package/lib/page/resolvePageLang.js +1 -1
- package/lib/page/resolvePagePath.js +2 -2
- package/lib/page/resolvePagePermalink.js +3 -3
- package/lib/page/resolvePageRouteMeta.d.ts +7 -0
- package/lib/page/resolvePageRouteMeta.js +8 -0
- package/lib/pluginApi/createHookQueue.js +3 -3
- package/lib/pluginApi/createPluginApi.js +2 -2
- package/lib/pluginApi/createPluginApiHooks.js +14 -14
- package/lib/pluginApi/createPluginApiRegisterHooks.js +6 -6
- package/lib/pluginApi/normalizeClientFilesHook.js +2 -2
- package/lib/pluginApi/normalizeReturnObjectHook.js +1 -1
- package/lib/types/app/app.d.ts +7 -5
- package/lib/types/index.d.ts +1 -1
- package/lib/types/page.d.ts +29 -5
- package/lib/types/pluginApi/hooks.d.ts +6 -7
- package/lib/types/theme.d.ts +13 -0
- package/package.json +6 -6
- package/lib/app/resolveThemeApi.d.ts +0 -8
- package/lib/app/resolveThemeApi.js +0 -29
- package/lib/page/resolvePageData.d.ts +0 -8
- package/lib/page/resolvePageData.js +0 -23
- package/lib/page/resolvePageOptions.d.ts +0 -8
- package/lib/page/resolvePageOptions.js +0 -14
package/lib/page/index.js
CHANGED
|
@@ -17,7 +17,6 @@ __exportStar(require("./renderPageExcerpt"), exports);
|
|
|
17
17
|
__exportStar(require("./resolvePageComponentInfo"), exports);
|
|
18
18
|
__exportStar(require("./resolvePageContent"), exports);
|
|
19
19
|
__exportStar(require("./resolvePageDataInfo"), exports);
|
|
20
|
-
__exportStar(require("./resolvePageData"), exports);
|
|
21
20
|
__exportStar(require("./resolvePageDate"), exports);
|
|
22
21
|
__exportStar(require("./resolvePageFileContent"), exports);
|
|
23
22
|
__exportStar(require("./resolvePageFilePath"), exports);
|
|
@@ -25,7 +24,7 @@ __exportStar(require("./resolvePageFrontmatter"), exports);
|
|
|
25
24
|
__exportStar(require("./resolvePageHtmlInfo"), exports);
|
|
26
25
|
__exportStar(require("./resolvePageKey"), exports);
|
|
27
26
|
__exportStar(require("./resolvePageLang"), exports);
|
|
28
|
-
__exportStar(require("./resolvePageOptions"), exports);
|
|
29
27
|
__exportStar(require("./resolvePagePath"), exports);
|
|
30
28
|
__exportStar(require("./resolvePagePermalink"), exports);
|
|
29
|
+
__exportStar(require("./resolvePageRouteMeta"), exports);
|
|
31
30
|
__exportStar(require("./resolvePageSlug"), exports);
|
|
@@ -14,11 +14,11 @@ const inferPagePath = ({ app, filePathRelative, }) => {
|
|
|
14
14
|
}
|
|
15
15
|
// infer page route path from file path
|
|
16
16
|
// foo/bar.md -> /foo/bar.html
|
|
17
|
-
const pathInferred = shared_1.ensureLeadingSlash(filePathRelative)
|
|
17
|
+
const pathInferred = (0, shared_1.ensureLeadingSlash)(filePathRelative)
|
|
18
18
|
.replace(/\.md$/, '.html')
|
|
19
19
|
.replace(/\/(README|index).html$/i, '/');
|
|
20
20
|
// resolve page locale path
|
|
21
|
-
const pathLocale = shared_1.resolveLocalePath(app.siteData.locales, pathInferred);
|
|
21
|
+
const pathLocale = (0, shared_1.resolveLocalePath)(app.siteData.locales, pathInferred);
|
|
22
22
|
return {
|
|
23
23
|
pathInferred,
|
|
24
24
|
pathLocale,
|
|
@@ -15,7 +15,7 @@ const resolvePageContent = ({ contentRaw, }) => {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
/* istanbul ignore next */
|
|
18
|
-
const { data, content, excerpt = '' } = matter(contentRaw, {
|
|
18
|
+
const { data, content, excerpt = '', } = matter(contentRaw, {
|
|
19
19
|
excerpt_separator: '<!-- more -->',
|
|
20
20
|
engines: {
|
|
21
21
|
toml: toml.parse.bind(toml),
|
|
@@ -15,14 +15,14 @@ const resolvePageDate = ({ frontmatter, filePathRelative, }) => {
|
|
|
15
15
|
var _a, _b;
|
|
16
16
|
// `frontmatter.date` could be parsed as UTC Date directly
|
|
17
17
|
if (frontmatter.date instanceof Date) {
|
|
18
|
-
return shared_1.formatDateString([
|
|
18
|
+
return (0, shared_1.formatDateString)([
|
|
19
19
|
frontmatter.date.getUTCFullYear(),
|
|
20
20
|
frontmatter.date.getUTCMonth() + 1,
|
|
21
21
|
frontmatter.date.getUTCDate(),
|
|
22
22
|
].join('-'), DEFAULT_DATE);
|
|
23
23
|
}
|
|
24
|
-
if (shared_1.isString(frontmatter.date)) {
|
|
25
|
-
return shared_1.formatDateString(frontmatter.date, DEFAULT_DATE);
|
|
24
|
+
if ((0, shared_1.isString)(frontmatter.date)) {
|
|
25
|
+
return (0, shared_1.formatDateString)(frontmatter.date, DEFAULT_DATE);
|
|
26
26
|
}
|
|
27
27
|
if (filePathRelative === null) {
|
|
28
28
|
return DEFAULT_DATE;
|
|
@@ -31,14 +31,14 @@ const resolvePageDate = ({ frontmatter, filePathRelative, }) => {
|
|
|
31
31
|
if (filename) {
|
|
32
32
|
const matches = filename.match(FILENAME_DATE_RE);
|
|
33
33
|
if (matches) {
|
|
34
|
-
return shared_1.formatDateString(`${matches[1]}-${matches[2]}-${(_a = matches[3]) !== null && _a !== void 0 ? _a : '01'}`, DEFAULT_DATE);
|
|
34
|
+
return (0, shared_1.formatDateString)(`${matches[1]}-${matches[2]}-${(_a = matches[3]) !== null && _a !== void 0 ? _a : '01'}`, DEFAULT_DATE);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
const dirname = utils_1.path.dirname(filePathRelative);
|
|
38
38
|
if (dirname !== '.') {
|
|
39
39
|
const matches = dirname.match(DIRNAME_DATE_RE);
|
|
40
40
|
if (matches) {
|
|
41
|
-
return shared_1.formatDateString(`${matches[1]}-${matches[2]}-${(_b = matches[3]) !== null && _b !== void 0 ? _b : '01'}`, DEFAULT_DATE);
|
|
41
|
+
return (0, shared_1.formatDateString)(`${matches[1]}-${matches[2]}-${(_b = matches[3]) !== null && _b !== void 0 ? _b : '01'}`, DEFAULT_DATE);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
return DEFAULT_DATE;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolvePageFileContent = void 0;
|
|
4
4
|
const utils_1 = require("@vuepress/utils");
|
|
5
|
-
const log = utils_1.debug('vuepress:core/page');
|
|
5
|
+
const log = (0, utils_1.debug)('vuepress:core/page');
|
|
6
6
|
/**
|
|
7
7
|
* Resolve page file content according to filePath or options content
|
|
8
8
|
*/
|
|
@@ -15,7 +15,7 @@ const resolvePageFileContent = async ({ filePath, options, }) => {
|
|
|
15
15
|
return content;
|
|
16
16
|
}
|
|
17
17
|
catch (e) {
|
|
18
|
-
log(e.message);
|
|
18
|
+
log(e instanceof Error ? e.message : e);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
// load raw content from options
|
|
@@ -2,7 +2,7 @@ import type { App, PageOptions } from '../types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Resolve absolute and relative path of page file
|
|
4
4
|
*/
|
|
5
|
-
export declare const resolvePageFilePath: ({ app, options
|
|
5
|
+
export declare const resolvePageFilePath: ({ app, options, }: {
|
|
6
6
|
app: App;
|
|
7
7
|
options: PageOptions;
|
|
8
8
|
}) => {
|
|
@@ -5,25 +5,20 @@ const utils_1 = require("@vuepress/utils");
|
|
|
5
5
|
/**
|
|
6
6
|
* Resolve absolute and relative path of page file
|
|
7
7
|
*/
|
|
8
|
-
const resolvePageFilePath = ({ app, options
|
|
8
|
+
const resolvePageFilePath = ({ app, options, }) => {
|
|
9
9
|
// empty file path
|
|
10
|
-
if (!filePath) {
|
|
10
|
+
if (!options.filePath) {
|
|
11
11
|
return {
|
|
12
12
|
filePath: null,
|
|
13
13
|
filePathRelative: null,
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
filePath,
|
|
20
|
-
filePathRelative: utils_1.path.relative(app.dir.source(), filePath),
|
|
21
|
-
};
|
|
16
|
+
if (!utils_1.path.isAbsolute(options.filePath)) {
|
|
17
|
+
throw utils_1.logger.createError(`filePath is not absolute file path: ${options.filePath}}`);
|
|
22
18
|
}
|
|
23
|
-
// relative file path
|
|
24
19
|
return {
|
|
25
|
-
filePath:
|
|
26
|
-
filePathRelative: filePath,
|
|
20
|
+
filePath: options.filePath,
|
|
21
|
+
filePathRelative: utils_1.path.relative(app.dir.source(), options.filePath),
|
|
27
22
|
};
|
|
28
23
|
};
|
|
29
24
|
exports.resolvePageFilePath = resolvePageFilePath;
|
|
@@ -8,7 +8,7 @@ const shared_1 = require("@vuepress/shared");
|
|
|
8
8
|
const resolvePageHtmlInfo = ({ app, path: pagePath, }) => {
|
|
9
9
|
// /foo.html -> foo.html
|
|
10
10
|
// /foo/ -> foo/index.html
|
|
11
|
-
const htmlFilePathRelative = shared_1.removeLeadingSlash(decodeURI(pagePath.replace(/\/$/, '/index.html')));
|
|
11
|
+
const htmlFilePathRelative = (0, shared_1.removeLeadingSlash)(decodeURI(pagePath.replace(/\/$/, '/index.html')));
|
|
12
12
|
const htmlFilePath = app.dir.dest(htmlFilePathRelative);
|
|
13
13
|
return {
|
|
14
14
|
htmlFilePath,
|
|
@@ -5,5 +5,5 @@ const utils_1 = require("@vuepress/utils");
|
|
|
5
5
|
/**
|
|
6
6
|
* Resolve page key to identify the page
|
|
7
7
|
*/
|
|
8
|
-
const resolvePageKey = ({ path }) => `v-${utils_1.hash(path)}`;
|
|
8
|
+
const resolvePageKey = ({ path }) => `v-${(0, utils_1.hash)(path)}`;
|
|
9
9
|
exports.resolvePageKey = resolvePageKey;
|
|
@@ -7,7 +7,7 @@ const shared_1 = require("@vuepress/shared");
|
|
|
7
7
|
*/
|
|
8
8
|
const resolvePageLang = ({ app, frontmatter, pathLocale, }) => {
|
|
9
9
|
var _a, _b;
|
|
10
|
-
if (shared_1.isString(frontmatter.lang) && frontmatter.lang) {
|
|
10
|
+
if ((0, shared_1.isString)(frontmatter.lang) && frontmatter.lang) {
|
|
11
11
|
return frontmatter.lang;
|
|
12
12
|
}
|
|
13
13
|
return (_b = (_a = app.siteData.locales[pathLocale]) === null || _a === void 0 ? void 0 : _a.lang) !== null && _b !== void 0 ? _b : app.siteData.lang;
|
|
@@ -9,10 +9,10 @@ const utils_1 = require("@vuepress/utils");
|
|
|
9
9
|
const resolvePagePath = ({ permalink, pathInferred, options, }) => {
|
|
10
10
|
let pagePath = options.path || permalink || pathInferred;
|
|
11
11
|
if (!pagePath) {
|
|
12
|
-
throw utils_1.logger.createError(`page path is empty, page options: ${JSON.stringify(options)}`);
|
|
12
|
+
throw utils_1.logger.createError(`page path is empty, page options: ${JSON.stringify(options, null, 2)}`);
|
|
13
13
|
}
|
|
14
14
|
if (!pagePath.endsWith('.html')) {
|
|
15
|
-
pagePath = shared_1.ensureEndingSlash(pagePath);
|
|
15
|
+
pagePath = (0, shared_1.ensureEndingSlash)(pagePath);
|
|
16
16
|
}
|
|
17
17
|
return encodeURI(pagePath);
|
|
18
18
|
};
|
|
@@ -9,11 +9,11 @@ const utils_1 = require("@vuepress/utils");
|
|
|
9
9
|
const resolvePagePermalink = ({ frontmatter, slug, date, pathInferred, pathLocale, }) => {
|
|
10
10
|
var _a;
|
|
11
11
|
// use permalink in frontmatter directly
|
|
12
|
-
if (shared_1.isString(frontmatter.permalink)) {
|
|
12
|
+
if ((0, shared_1.isString)(frontmatter.permalink)) {
|
|
13
13
|
return frontmatter.permalink;
|
|
14
14
|
}
|
|
15
15
|
// get permalink pattern from frontmatter or options
|
|
16
|
-
const pattern = shared_1.isString(frontmatter.permalinkPattern)
|
|
16
|
+
const pattern = (0, shared_1.isString)(frontmatter.permalinkPattern)
|
|
17
17
|
? frontmatter.permalinkPattern
|
|
18
18
|
: null;
|
|
19
19
|
if (!pattern) {
|
|
@@ -27,6 +27,6 @@ const resolvePagePermalink = ({ frontmatter, slug, date, pathInferred, pathLocal
|
|
|
27
27
|
.replace(/:day/, day)
|
|
28
28
|
.replace(/:slug/, slug)
|
|
29
29
|
.replace(/:raw/, (_a = pathInferred === null || pathInferred === void 0 ? void 0 : pathInferred.replace(/^\//, '')) !== null && _a !== void 0 ? _a : ''));
|
|
30
|
-
return shared_1.ensureLeadingSlash(link);
|
|
30
|
+
return (0, shared_1.ensureLeadingSlash)(link);
|
|
31
31
|
};
|
|
32
32
|
exports.resolvePagePermalink = resolvePagePermalink;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvePageRouteMeta = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Resolve page route meta
|
|
6
|
+
*/
|
|
7
|
+
const resolvePageRouteMeta = ({ frontmatter, }) => { var _a; return (_a = frontmatter.routeMeta) !== null && _a !== void 0 ? _a : {}; };
|
|
8
|
+
exports.resolvePageRouteMeta = resolvePageRouteMeta;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createHookQueue = void 0;
|
|
4
4
|
const utils_1 = require("@vuepress/utils");
|
|
5
|
-
const log = utils_1.debug('vuepress:core/plugin-api');
|
|
5
|
+
const log = (0, utils_1.debug)('vuepress:core/plugin-api');
|
|
6
6
|
/**
|
|
7
7
|
* Create hook queue for plugin system
|
|
8
8
|
*/
|
|
@@ -29,9 +29,9 @@ const createHookQueue = (name) => {
|
|
|
29
29
|
results.push(result);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
catch (
|
|
32
|
+
catch (e) {
|
|
33
33
|
utils_1.logger.error(`error in hook ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
|
|
34
|
-
throw
|
|
34
|
+
throw e;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
return results;
|
|
@@ -5,8 +5,8 @@ const createPluginApiHooks_1 = require("./createPluginApiHooks");
|
|
|
5
5
|
const createPluginApiRegisterHooks_1 = require("./createPluginApiRegisterHooks");
|
|
6
6
|
const createPluginApi = () => {
|
|
7
7
|
const plugins = [];
|
|
8
|
-
const hooks = createPluginApiHooks_1.createPluginApiHooks();
|
|
9
|
-
const registerHooks = createPluginApiRegisterHooks_1.createPluginApiRegisterHooks(plugins, hooks);
|
|
8
|
+
const hooks = (0, createPluginApiHooks_1.createPluginApiHooks)();
|
|
9
|
+
const registerHooks = (0, createPluginApiRegisterHooks_1.createPluginApiRegisterHooks)(plugins, hooks);
|
|
10
10
|
return {
|
|
11
11
|
plugins,
|
|
12
12
|
hooks,
|
|
@@ -4,21 +4,21 @@ exports.createPluginApiHooks = void 0;
|
|
|
4
4
|
const createHookQueue_1 = require("./createHookQueue");
|
|
5
5
|
const createPluginApiHooks = () => ({
|
|
6
6
|
// life cycle hooks
|
|
7
|
-
onInitialized: createHookQueue_1.createHookQueue('onInitialized'),
|
|
8
|
-
onPrepared: createHookQueue_1.createHookQueue('onPrepared'),
|
|
9
|
-
onWatched: createHookQueue_1.createHookQueue('onWatched'),
|
|
10
|
-
onGenerated: createHookQueue_1.createHookQueue('onGenerated'),
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
onInitialized: (0, createHookQueue_1.createHookQueue)('onInitialized'),
|
|
8
|
+
onPrepared: (0, createHookQueue_1.createHookQueue)('onPrepared'),
|
|
9
|
+
onWatched: (0, createHookQueue_1.createHookQueue)('onWatched'),
|
|
10
|
+
onGenerated: (0, createHookQueue_1.createHookQueue)('onGenerated'),
|
|
11
|
+
// extends hooks
|
|
12
|
+
extendsMarkdownOptions: (0, createHookQueue_1.createHookQueue)('extendsMarkdownOptions'),
|
|
13
|
+
extendsMarkdown: (0, createHookQueue_1.createHookQueue)('extendsMarkdown'),
|
|
14
|
+
extendsPageOptions: (0, createHookQueue_1.createHookQueue)('extendsPageOptions'),
|
|
15
|
+
extendsPage: (0, createHookQueue_1.createHookQueue)('extendsPage'),
|
|
16
16
|
// client files hooks
|
|
17
|
-
clientAppEnhanceFiles: createHookQueue_1.createHookQueue('clientAppEnhanceFiles'),
|
|
18
|
-
clientAppRootComponentFiles: createHookQueue_1.createHookQueue('clientAppRootComponentFiles'),
|
|
19
|
-
clientAppSetupFiles: createHookQueue_1.createHookQueue('clientAppSetupFiles'),
|
|
17
|
+
clientAppEnhanceFiles: (0, createHookQueue_1.createHookQueue)('clientAppEnhanceFiles'),
|
|
18
|
+
clientAppRootComponentFiles: (0, createHookQueue_1.createHookQueue)('clientAppRootComponentFiles'),
|
|
19
|
+
clientAppSetupFiles: (0, createHookQueue_1.createHookQueue)('clientAppSetupFiles'),
|
|
20
20
|
// bundler hooks
|
|
21
|
-
alias: createHookQueue_1.createHookQueue('alias'),
|
|
22
|
-
define: createHookQueue_1.createHookQueue('define'),
|
|
21
|
+
alias: (0, createHookQueue_1.createHookQueue)('alias'),
|
|
22
|
+
define: (0, createHookQueue_1.createHookQueue)('define'),
|
|
23
23
|
});
|
|
24
24
|
exports.createPluginApiHooks = createPluginApiHooks;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPluginApiRegisterHooks = void 0;
|
|
4
|
-
const normalizeReturnObjectHook_1 = require("./normalizeReturnObjectHook");
|
|
5
4
|
const normalizeClientFilesHook_1 = require("./normalizeClientFilesHook");
|
|
5
|
+
const normalizeReturnObjectHook_1 = require("./normalizeReturnObjectHook");
|
|
6
6
|
const createPluginApiRegisterHooks = (plugins, hooks) => () => {
|
|
7
7
|
plugins.forEach(({ name: pluginName, alias, define, clientAppEnhanceFiles, clientAppRootComponentFiles, clientAppSetupFiles, ...commonHooks }) => {
|
|
8
8
|
/**
|
|
@@ -11,31 +11,31 @@ const createPluginApiRegisterHooks = (plugins, hooks) => () => {
|
|
|
11
11
|
if (alias) {
|
|
12
12
|
hooks.alias.add({
|
|
13
13
|
pluginName,
|
|
14
|
-
hook: normalizeReturnObjectHook_1.normalizeReturnObjectHook(alias),
|
|
14
|
+
hook: (0, normalizeReturnObjectHook_1.normalizeReturnObjectHook)(alias),
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
if (define) {
|
|
18
18
|
hooks.define.add({
|
|
19
19
|
pluginName,
|
|
20
|
-
hook: normalizeReturnObjectHook_1.normalizeReturnObjectHook(define),
|
|
20
|
+
hook: (0, normalizeReturnObjectHook_1.normalizeReturnObjectHook)(define),
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
if (clientAppEnhanceFiles) {
|
|
24
24
|
hooks.clientAppEnhanceFiles.add({
|
|
25
25
|
pluginName,
|
|
26
|
-
hook: normalizeClientFilesHook_1.normalizeClientFilesHook(clientAppEnhanceFiles),
|
|
26
|
+
hook: (0, normalizeClientFilesHook_1.normalizeClientFilesHook)(clientAppEnhanceFiles),
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
if (clientAppRootComponentFiles) {
|
|
30
30
|
hooks.clientAppRootComponentFiles.add({
|
|
31
31
|
pluginName,
|
|
32
|
-
hook: normalizeClientFilesHook_1.normalizeClientFilesHook(clientAppRootComponentFiles),
|
|
32
|
+
hook: (0, normalizeClientFilesHook_1.normalizeClientFilesHook)(clientAppRootComponentFiles),
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
if (clientAppSetupFiles) {
|
|
36
36
|
hooks.clientAppSetupFiles.add({
|
|
37
37
|
pluginName,
|
|
38
|
-
hook: normalizeClientFilesHook_1.normalizeClientFilesHook(clientAppSetupFiles),
|
|
38
|
+
hook: (0, normalizeClientFilesHook_1.normalizeClientFilesHook)(clientAppSetupFiles),
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
@@ -8,8 +8,8 @@ const utils_1 = require("@vuepress/utils");
|
|
|
8
8
|
*/
|
|
9
9
|
const normalizeClientFilesHook = (hook) => async (app) => {
|
|
10
10
|
// resolve clientFiles result
|
|
11
|
-
const clientFilesResult = shared_1.isFunction(hook) ? await hook(app) : hook;
|
|
12
|
-
const clientFiles = shared_1.isArray(clientFilesResult)
|
|
11
|
+
const clientFilesResult = (0, shared_1.isFunction)(hook) ? await hook(app) : hook;
|
|
12
|
+
const clientFiles = (0, shared_1.isArray)(clientFilesResult)
|
|
13
13
|
? clientFilesResult
|
|
14
14
|
: [clientFilesResult];
|
|
15
15
|
// filter files that do not exist
|
|
@@ -5,5 +5,5 @@ const shared_1 = require("@vuepress/shared");
|
|
|
5
5
|
/**
|
|
6
6
|
* Normalize hook that returns an object
|
|
7
7
|
*/
|
|
8
|
-
const normalizeReturnObjectHook = (hook) => async (app) => shared_1.isFunction(hook) ? hook(app) : hook;
|
|
8
|
+
const normalizeReturnObjectHook = (hook) => async (app) => (0, shared_1.isFunction)(hook) ? hook(app) : hook;
|
|
9
9
|
exports.normalizeReturnObjectHook = normalizeReturnObjectHook;
|
package/lib/types/app/app.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Markdown } from '@vuepress/markdown';
|
|
2
2
|
import type { SiteData } from '@vuepress/shared';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BundlerBuild, BundlerDev } from '../bundler';
|
|
4
4
|
import type { Page } from '../page';
|
|
5
5
|
import type { Plugin, PluginOptions } from '../plugin';
|
|
6
6
|
import type { PluginApi } from '../pluginApi';
|
|
@@ -30,10 +30,6 @@ export interface App {
|
|
|
30
30
|
* Site data, which will be used in client side
|
|
31
31
|
*/
|
|
32
32
|
siteData: SiteData;
|
|
33
|
-
/**
|
|
34
|
-
* Markdown-it instance
|
|
35
|
-
*/
|
|
36
|
-
markdown: Markdown;
|
|
37
33
|
/**
|
|
38
34
|
* Plugin system
|
|
39
35
|
*/
|
|
@@ -65,6 +61,12 @@ export interface App {
|
|
|
65
61
|
* Only available after initialization
|
|
66
62
|
*/
|
|
67
63
|
layouts: Record<string, string>;
|
|
64
|
+
/**
|
|
65
|
+
* Markdown-it instance.
|
|
66
|
+
*
|
|
67
|
+
* Only available after initialization
|
|
68
|
+
*/
|
|
69
|
+
markdown: Markdown;
|
|
68
70
|
/**
|
|
69
71
|
* Page objects.
|
|
70
72
|
*
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HeadConfig, HeadTag, HeadTagEmpty, HeadTagNonEmpty,
|
|
1
|
+
import type { HeadAttrsConfig, HeadConfig, HeadTag, HeadTagEmpty, HeadTagNonEmpty, LocaleConfig, LocaleData, PageData, PageFrontmatter, PageHeader, SiteData, SiteLocaleConfig } from '@vuepress/shared';
|
|
2
2
|
export type { HeadConfig, HeadTag, HeadTagEmpty, HeadTagNonEmpty, HeadAttrsConfig, LocaleConfig, LocaleData, PageData, PageFrontmatter, PageHeader, SiteData, SiteLocaleConfig, };
|
|
3
3
|
export * from './app';
|
|
4
4
|
export * from './bundler';
|
package/lib/types/page.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import type { PageData, PageFrontmatter } from '@vuepress/shared';
|
|
|
3
3
|
/**
|
|
4
4
|
* Vuepress Page
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export declare type Page<ExtraPageData extends Record<any, any> = Record<never, never>, ExtraPageFields extends Record<any, any> = Record<never, never>> = PageData & ExtraPageFields & {
|
|
7
7
|
/**
|
|
8
8
|
* Data of the page, which will be available in client code
|
|
9
9
|
*/
|
|
10
|
-
data:
|
|
10
|
+
data: PageData<ExtraPageData>;
|
|
11
11
|
/**
|
|
12
12
|
* Raw Content of the page
|
|
13
13
|
*/
|
|
@@ -56,6 +56,12 @@ export interface Page<T extends PageData = PageData> extends PageData {
|
|
|
56
56
|
* If the page does not have a permalink, it would be `null`
|
|
57
57
|
*/
|
|
58
58
|
permalink: string | null;
|
|
59
|
+
/**
|
|
60
|
+
* Custom data to be attached to the page route record of vue-router
|
|
61
|
+
*
|
|
62
|
+
* @see https://next.router.vuejs.org/api/#meta
|
|
63
|
+
*/
|
|
64
|
+
routeMeta: Record<string, unknown>;
|
|
59
65
|
/**
|
|
60
66
|
* Slug of the page
|
|
61
67
|
*/
|
|
@@ -108,13 +114,31 @@ export interface Page<T extends PageData = PageData> extends PageData {
|
|
|
108
114
|
* Rendered html file path relative to dest directory
|
|
109
115
|
*/
|
|
110
116
|
htmlFilePathRelative: string;
|
|
111
|
-
}
|
|
117
|
+
};
|
|
112
118
|
/**
|
|
113
119
|
* Options to create vuepress page
|
|
114
120
|
*/
|
|
115
121
|
export interface PageOptions {
|
|
116
|
-
|
|
122
|
+
/**
|
|
123
|
+
* If `filePath` is not set, this option will be used as the raw
|
|
124
|
+
* markdown content of the page.
|
|
125
|
+
*
|
|
126
|
+
* If `filePath` is set, this option will be ignored, while the
|
|
127
|
+
* content of the file will be used.
|
|
128
|
+
*/
|
|
129
|
+
content?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Absolute file path of the markdown source file.
|
|
132
|
+
*/
|
|
117
133
|
filePath?: string;
|
|
134
|
+
/**
|
|
135
|
+
* Default frontmatter of the page, which could be overridden by
|
|
136
|
+
* the frontmatter of the markdown content.
|
|
137
|
+
*/
|
|
118
138
|
frontmatter?: PageFrontmatter;
|
|
119
|
-
|
|
139
|
+
/**
|
|
140
|
+
* If this option is set, it will be used as the final route path
|
|
141
|
+
* of the page, ignoring the relative path and permalink.
|
|
142
|
+
*/
|
|
143
|
+
path?: string;
|
|
120
144
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Markdown } from '@vuepress/markdown';
|
|
1
|
+
import type { Markdown, MarkdownOptions } from '@vuepress/markdown';
|
|
2
2
|
import type { App } from '../app';
|
|
3
3
|
import type { Page, PageOptions } from '../page';
|
|
4
4
|
declare type PromiseOrNot<T> = Promise<T> | T;
|
|
@@ -11,11 +11,9 @@ export declare type Hook<Exposed, Normalized = Exposed, Result = Normalized exte
|
|
|
11
11
|
result: Result;
|
|
12
12
|
};
|
|
13
13
|
export declare type LifeCycleHook<T extends unknown[] = []> = Hook<(app: App, ...args: T) => PromiseOrNot<void>>;
|
|
14
|
+
export declare type ExtendsHook<T> = Hook<(extendable: T, app: App) => PromiseOrNot<void>>;
|
|
14
15
|
export declare type ClientFilesHook = Hook<string | string[] | ((app: App) => PromiseOrNot<string | string[]>), (app: App) => Promise<string[]>>;
|
|
15
16
|
export declare type ReturnObjectHook = Hook<Record<string, any> | ((app: App) => PromiseOrNot<Record<string, any>>), (app: App) => Promise<Record<string, any>>>;
|
|
16
|
-
export declare type ExtendsMarkdownHook = Hook<(md: Markdown, app: App) => PromiseOrNot<void>>;
|
|
17
|
-
export declare type ExtendsPageOptionsHook = Hook<(options: PageOptions, app: App) => PromiseOrNot<PageOptions>>;
|
|
18
|
-
export declare type ExtendsPageDataHook = Hook<(page: Omit<Page, 'data'>, app: App) => PromiseOrNot<Record<string, any>>>;
|
|
19
17
|
/**
|
|
20
18
|
* List of hooks
|
|
21
19
|
*/
|
|
@@ -24,9 +22,10 @@ export interface Hooks {
|
|
|
24
22
|
onPrepared: LifeCycleHook;
|
|
25
23
|
onWatched: LifeCycleHook<[watchers: Closable[], restart: () => Promise<void>]>;
|
|
26
24
|
onGenerated: LifeCycleHook;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
extendsMarkdownOptions: ExtendsHook<MarkdownOptions>;
|
|
26
|
+
extendsMarkdown: ExtendsHook<Markdown>;
|
|
27
|
+
extendsPageOptions: ExtendsHook<PageOptions>;
|
|
28
|
+
extendsPage: ExtendsHook<Page>;
|
|
30
29
|
clientAppEnhanceFiles: ClientFilesHook;
|
|
31
30
|
clientAppRootComponentFiles: ClientFilesHook;
|
|
32
31
|
clientAppSetupFiles: ClientFilesHook;
|
package/lib/types/theme.d.ts
CHANGED
|
@@ -32,3 +32,16 @@ export interface ThemeObject extends PluginObject {
|
|
|
32
32
|
* @remark suffix `Config` means this is for user config
|
|
33
33
|
*/
|
|
34
34
|
export declare type ThemeConfig = Record<string, any>;
|
|
35
|
+
/**
|
|
36
|
+
* Resolved theme info
|
|
37
|
+
*/
|
|
38
|
+
export interface ThemeInfo {
|
|
39
|
+
/**
|
|
40
|
+
* Layout components
|
|
41
|
+
*/
|
|
42
|
+
layouts: Record<string, string>;
|
|
43
|
+
/**
|
|
44
|
+
* Plugins, including theme itself and plugins used by theme
|
|
45
|
+
*/
|
|
46
|
+
plugins: PluginObject[];
|
|
47
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/core",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.28",
|
|
4
4
|
"description": "Core package of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"clean": "rimraf lib *.tsbuildinfo"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@vuepress/client": "2.0.0-beta.
|
|
30
|
-
"@vuepress/markdown": "2.0.0-beta.
|
|
31
|
-
"@vuepress/shared": "2.0.0-beta.
|
|
32
|
-
"@vuepress/utils": "2.0.0-beta.
|
|
29
|
+
"@vuepress/client": "2.0.0-beta.28",
|
|
30
|
+
"@vuepress/markdown": "2.0.0-beta.28",
|
|
31
|
+
"@vuepress/shared": "2.0.0-beta.28",
|
|
32
|
+
"@vuepress/utils": "2.0.0-beta.28",
|
|
33
33
|
"gray-matter": "^4.0.3",
|
|
34
34
|
"toml": "^3.0.0"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "71c34816a79263c7dcba3ff0c103e264abdbf0d2"
|
|
40
40
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { App, PluginObject } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Recursively resolve plugins and layouts of theme and its parent theme
|
|
4
|
-
*/
|
|
5
|
-
export declare const resolveThemeApi: (app: App, themeName: string) => {
|
|
6
|
-
layouts: Record<string, string>;
|
|
7
|
-
plugins: PluginObject[];
|
|
8
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveThemeApi = void 0;
|
|
4
|
-
const resolvePluginsFromConfig_1 = require("./resolvePluginsFromConfig");
|
|
5
|
-
const resolveTheme_1 = require("./resolveTheme");
|
|
6
|
-
const resolveThemeLayouts_1 = require("./resolveThemeLayouts");
|
|
7
|
-
/**
|
|
8
|
-
* Recursively resolve plugins and layouts of theme and its parent theme
|
|
9
|
-
*/
|
|
10
|
-
const resolveThemeApi = (app, themeName) => {
|
|
11
|
-
const theme = resolveTheme_1.resolveTheme(app, themeName);
|
|
12
|
-
const themeLayouts = resolveThemeLayouts_1.resolveThemeLayouts(theme.layouts);
|
|
13
|
-
const themePlugins = resolvePluginsFromConfig_1.resolvePluginsFromConfig(app, theme.plugins);
|
|
14
|
-
if (!theme.extends) {
|
|
15
|
-
return {
|
|
16
|
-
layouts: themeLayouts,
|
|
17
|
-
plugins: [theme, ...themePlugins],
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
const parentThemeApi = exports.resolveThemeApi(app, theme.extends);
|
|
21
|
-
return {
|
|
22
|
-
layouts: {
|
|
23
|
-
...parentThemeApi.layouts,
|
|
24
|
-
...themeLayouts,
|
|
25
|
-
},
|
|
26
|
-
plugins: [...parentThemeApi.plugins, theme, ...themePlugins],
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
exports.resolveThemeApi = resolveThemeApi;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePageData = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Resolve page data
|
|
6
|
-
*/
|
|
7
|
-
const resolvePageData = async ({ app, page, }) => {
|
|
8
|
-
const { key, path, title, lang, frontmatter, excerpt, headers } = page;
|
|
9
|
-
const data = {
|
|
10
|
-
key,
|
|
11
|
-
path,
|
|
12
|
-
title,
|
|
13
|
-
lang,
|
|
14
|
-
frontmatter,
|
|
15
|
-
excerpt,
|
|
16
|
-
headers,
|
|
17
|
-
};
|
|
18
|
-
// plugin hook: extendsPageData
|
|
19
|
-
const extendsPageData = await app.pluginApi.hooks.extendsPageData.process(page, app);
|
|
20
|
-
extendsPageData.forEach((item) => Object.assign(data, item));
|
|
21
|
-
return data;
|
|
22
|
-
};
|
|
23
|
-
exports.resolvePageData = resolvePageData;
|