@vuepress/core 2.0.0-beta.4 → 2.0.0-beta.42
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 +6 -16
- package/lib/app/appPrepare.js +12 -15
- package/lib/app/appUse.d.ts +2 -2
- package/lib/app/appUse.js +17 -15
- package/lib/app/createBaseApp.d.ts +5 -0
- package/lib/app/createBaseApp.js +46 -0
- package/lib/app/createBuildApp.d.ts +5 -0
- package/lib/app/createBuildApp.js +13 -0
- package/lib/app/createDevApp.d.ts +5 -0
- package/lib/app/createDevApp.js +13 -0
- package/lib/app/index.d.ts +13 -12
- package/lib/app/index.js +18 -13
- package/lib/app/prepare/index.d.ts +1 -3
- package/lib/app/prepare/index.js +6 -4
- package/lib/app/prepare/prepareLayoutComponents.js +2 -2
- package/lib/app/prepare/preparePageComponent.js +6 -1
- package/lib/app/prepare/preparePageData.js +7 -11
- package/lib/app/prepare/{preparePagesComponent.d.ts → preparePagesComponents.d.ts} +1 -1
- package/lib/app/prepare/preparePagesComponents.js +24 -0
- package/lib/app/prepare/preparePagesData.js +5 -4
- package/lib/app/prepare/preparePagesRoutes.js +61 -11
- package/lib/app/prepare/prepareSiteData.js +19 -1
- package/lib/app/{createAppDir.d.ts → resolveAppDir.d.ts} +2 -2
- package/lib/app/resolveAppDir.js +32 -0
- package/lib/app/resolveAppEnv.d.ts +5 -0
- package/lib/app/resolveAppEnv.js +12 -0
- package/lib/app/resolveAppMarkdown.d.ts +6 -0
- package/lib/app/resolveAppMarkdown.js +16 -0
- package/lib/app/resolveAppOptions.d.ts +5 -0
- package/lib/app/{createAppOptions.js → resolveAppOptions.js} +16 -20
- package/lib/app/resolveAppPages.d.ts +5 -0
- package/lib/app/resolveAppPages.js +31 -0
- package/lib/app/resolveAppSiteData.d.ts +7 -0
- package/lib/app/resolveAppSiteData.js +17 -0
- package/lib/app/resolveAppVersion.d.ts +4 -0
- package/lib/app/resolveAppVersion.js +10 -0
- package/lib/app/resolveAppWriteTemp.d.ts +5 -0
- package/lib/app/{createAppWriteTemp.js → resolveAppWriteTemp.js} +5 -5
- package/lib/app/resolvePluginObject.d.ts +5 -0
- package/lib/app/resolvePluginObject.js +9 -0
- package/lib/app/resolveThemeInfo.d.ts +5 -0
- package/lib/app/resolveThemeInfo.js +31 -0
- package/lib/app/resolveThemeLayouts.d.ts +5 -0
- package/lib/app/resolveThemeLayouts.js +25 -0
- package/lib/app/setupAppThemeAndPlugins.d.ts +5 -0
- package/lib/app/setupAppThemeAndPlugins.js +21 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.js +5 -2
- package/lib/page/createPage.js +75 -39
- package/lib/page/index.d.ts +4 -3
- package/lib/page/index.js +9 -4
- package/lib/page/inferPagePath.js +2 -2
- package/lib/page/renderPageContent.d.ts +19 -0
- package/lib/page/renderPageContent.js +26 -0
- package/lib/page/renderPageExcerpt.d.ts +11 -0
- package/lib/page/renderPageExcerpt.js +17 -0
- package/lib/page/resolvePageComponentInfo.d.ts +2 -9
- package/lib/page/resolvePageComponentInfo.js +2 -24
- package/lib/page/resolvePageContent.js +1 -2
- package/lib/page/resolvePageDataInfo.d.ts +2 -1
- package/lib/page/resolvePageDataInfo.js +2 -2
- package/lib/page/resolvePageDate.d.ts +1 -1
- package/lib/page/resolvePageDate.js +6 -7
- package/lib/page/resolvePageFileContent.js +3 -4
- package/lib/page/resolvePageFilePath.d.ts +1 -1
- package/lib/page/resolvePageFilePath.js +6 -11
- package/lib/page/resolvePageHtmlInfo.d.ts +11 -0
- package/lib/page/resolvePageHtmlInfo.js +18 -0
- package/lib/page/resolvePageKey.js +1 -1
- package/lib/page/resolvePageLang.js +2 -3
- package/lib/page/resolvePagePath.js +12 -1
- package/lib/page/resolvePagePermalink.js +4 -5
- package/lib/page/resolvePageRouteMeta.d.ts +7 -0
- package/lib/page/resolvePageRouteMeta.js +8 -0
- package/lib/pluginApi/createHookQueue.d.ts +1 -1
- package/lib/pluginApi/createHookQueue.js +7 -46
- package/lib/pluginApi/createPluginApi.js +2 -2
- package/lib/pluginApi/createPluginApiHooks.js +15 -14
- package/lib/pluginApi/createPluginApiRegisterHooks.js +6 -6
- package/lib/pluginApi/index.js +5 -1
- package/lib/pluginApi/normalizeClientFilesHook.js +5 -2
- package/lib/pluginApi/normalizeReturnObjectHook.js +1 -1
- package/lib/types/app/app.d.ts +82 -14
- package/lib/types/app/index.js +5 -1
- package/lib/types/app/options.d.ts +78 -27
- package/lib/types/app/utils.d.ts +10 -3
- package/lib/types/bundler.d.ts +3 -24
- package/lib/types/index.d.ts +2 -3
- package/lib/types/index.js +6 -3
- package/lib/types/page.d.ts +78 -32
- package/lib/types/plugin.d.ts +5 -24
- package/lib/types/{plugin-api → pluginApi}/hooks.d.ts +8 -9
- package/lib/types/{plugin-api → pluginApi}/hooks.js +0 -0
- package/lib/types/{plugin-api → pluginApi}/index.d.ts +0 -0
- package/lib/types/{plugin-api → pluginApi}/index.js +5 -1
- package/lib/types/{plugin-api → pluginApi}/pluginApi.d.ts +0 -0
- package/lib/types/{plugin-api → pluginApi}/pluginApi.js +0 -0
- package/lib/types/theme.d.ts +42 -14
- package/package.json +14 -14
- package/CHANGELOG.md +0 -260
- package/lib/app/appUseByConfig.d.ts +0 -2
- package/lib/app/appUseByConfig.js +0 -14
- package/lib/app/createApp.d.ts +0 -5
- package/lib/app/createApp.js +0 -44
- package/lib/app/createAppDir.js +0 -32
- package/lib/app/createAppEnv.d.ts +0 -5
- package/lib/app/createAppEnv.js +0 -14
- package/lib/app/createAppOptions.d.ts +0 -5
- package/lib/app/createAppPages.d.ts +0 -5
- package/lib/app/createAppPages.js +0 -33
- package/lib/app/createAppSiteData.d.ts +0 -7
- package/lib/app/createAppSiteData.js +0 -19
- package/lib/app/createAppVersion.d.ts +0 -4
- package/lib/app/createAppVersion.js +0 -11
- package/lib/app/createAppWriteTemp.d.ts +0 -5
- package/lib/app/normalizePlugin.d.ts +0 -2
- package/lib/app/normalizePlugin.js +0 -19
- package/lib/app/normalizePluginConfig.d.ts +0 -2
- package/lib/app/normalizePluginConfig.js +0 -18
- package/lib/app/prepare/preparePageRoutes.d.ts +0 -5
- package/lib/app/prepare/preparePageRoutes.js +0 -57
- package/lib/app/prepare/preparePagesComponent.js +0 -23
- package/lib/app/prepare/resolvePageData.d.ts +0 -5
- package/lib/app/prepare/resolvePageData.js +0 -18
- package/lib/app/resolveBundler.d.ts +0 -2
- package/lib/app/resolveBundler.js +0 -10
- package/lib/app/resolvePlugin.d.ts +0 -5
- package/lib/app/resolvePlugin.js +0 -20
- package/lib/page/resolvePageExcerpt.d.ts +0 -9
- package/lib/page/resolvePageExcerpt.js +0 -15
- package/lib/page/resolvePageRoutesInfo.d.ts +0 -11
- package/lib/page/resolvePageRoutesInfo.js +0 -16
- package/lib/page/resolvePageTitle.d.ts +0 -9
- package/lib/page/resolvePageTitle.js +0 -26
- package/lib/themeApi/createThemeApi.d.ts +0 -7
- package/lib/themeApi/createThemeApi.js +0 -30
- package/lib/themeApi/index.d.ts +0 -1
- package/lib/themeApi/index.js +0 -13
- package/lib/themeApi/resolveThemeInfo.d.ts +0 -2
- package/lib/themeApi/resolveThemeInfo.js +0 -34
- package/lib/themeApi/resolveThemeLayouts.d.ts +0 -5
- package/lib/themeApi/resolveThemeLayouts.js +0 -33
- package/lib/types/theme-api/index.d.ts +0 -1
- package/lib/types/theme-api/index.js +0 -13
- package/lib/types/theme-api/themeApi.d.ts +0 -44
- package/lib/types/theme-api/themeApi.js +0 -2
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderPageContent = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Render page content and extract related info
|
|
6
|
+
*/
|
|
7
|
+
const renderPageContent = async ({ app, content, frontmatter, filePath, filePathRelative, }) => {
|
|
8
|
+
const markdownEnv = {
|
|
9
|
+
base: app.options.base,
|
|
10
|
+
filePath,
|
|
11
|
+
filePathRelative,
|
|
12
|
+
frontmatter,
|
|
13
|
+
};
|
|
14
|
+
const contentRendered = app.markdown.render(content, markdownEnv);
|
|
15
|
+
/* istanbul ignore next */
|
|
16
|
+
const { headers = [], hoistedTags = [], importedFiles = [], links = [], title = '', } = markdownEnv;
|
|
17
|
+
return {
|
|
18
|
+
contentRendered,
|
|
19
|
+
deps: importedFiles,
|
|
20
|
+
headers,
|
|
21
|
+
hoistedTags,
|
|
22
|
+
links,
|
|
23
|
+
title,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports.renderPageContent = renderPageContent;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { App, PageFrontmatter } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Render page excerpt from raw excerpt
|
|
4
|
+
*/
|
|
5
|
+
export declare const renderPageExcerpt: ({ app, excerptRaw, frontmatter, filePath, filePathRelative, }: {
|
|
6
|
+
app: App;
|
|
7
|
+
excerptRaw: string;
|
|
8
|
+
frontmatter: PageFrontmatter;
|
|
9
|
+
filePath: string | null;
|
|
10
|
+
filePathRelative: string | null;
|
|
11
|
+
}) => string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderPageExcerpt = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Render page excerpt from raw excerpt
|
|
6
|
+
*/
|
|
7
|
+
const renderPageExcerpt = ({ app, excerptRaw, frontmatter, filePath, filePathRelative, }) => {
|
|
8
|
+
const markdownEnv = {
|
|
9
|
+
base: app.options.base,
|
|
10
|
+
filePath,
|
|
11
|
+
filePathRelative,
|
|
12
|
+
frontmatter,
|
|
13
|
+
};
|
|
14
|
+
const renderedExcerpt = app.markdown.render(excerptRaw, markdownEnv);
|
|
15
|
+
return renderedExcerpt;
|
|
16
|
+
};
|
|
17
|
+
exports.renderPageExcerpt = renderPageExcerpt;
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
import type { MarkdownHeader, MarkdownLink } from '@vuepress/markdown';
|
|
2
|
-
import { path } from '@vuepress/utils';
|
|
3
1
|
import type { App } from '../types';
|
|
4
2
|
/**
|
|
5
3
|
* Resolve page component and related info
|
|
6
4
|
*/
|
|
7
|
-
export declare const resolvePageComponentInfo: ({ app,
|
|
5
|
+
export declare const resolvePageComponentInfo: ({ app, htmlFilePathRelative, key, }: {
|
|
8
6
|
app: App;
|
|
9
|
-
|
|
10
|
-
filePathRelative: string | null;
|
|
11
|
-
path: string;
|
|
7
|
+
htmlFilePathRelative: string;
|
|
12
8
|
key: string;
|
|
13
9
|
}) => Promise<{
|
|
14
|
-
headers: MarkdownHeader[];
|
|
15
|
-
links: MarkdownLink[];
|
|
16
10
|
componentFilePath: string;
|
|
17
11
|
componentFilePathRelative: string;
|
|
18
|
-
componentFileContent: string;
|
|
19
12
|
componentFileChunkName: string;
|
|
20
13
|
}>;
|
|
@@ -5,36 +5,14 @@ const utils_1 = require("@vuepress/utils");
|
|
|
5
5
|
/**
|
|
6
6
|
* Resolve page component and related info
|
|
7
7
|
*/
|
|
8
|
-
const resolvePageComponentInfo = async ({ app,
|
|
9
|
-
var _a;
|
|
10
|
-
const markdownEnv = {
|
|
11
|
-
base: app.options.base,
|
|
12
|
-
filePathRelative,
|
|
13
|
-
};
|
|
14
|
-
const rendered = app.markdown.render(content, markdownEnv);
|
|
15
|
-
const { headers = [], links = [], hoistedTags = [] } = markdownEnv;
|
|
16
|
-
// TODO: links check
|
|
17
|
-
// resolve component file content
|
|
18
|
-
// take the rendered markdown content as <template>
|
|
19
|
-
// hoist `<script>`, `<style>` and other custom blocks
|
|
20
|
-
const componentFileContent = [
|
|
21
|
-
// if the `<template>` block is empty, vue will print a runtime warning
|
|
22
|
-
// during development, so here we add a whitespace to temporarily avoid
|
|
23
|
-
// the warning
|
|
24
|
-
// @see https://github.com/vuejs/vue-next/issues/2463
|
|
25
|
-
`<template>${rendered || ' '}</template>`,
|
|
26
|
-
...hoistedTags,
|
|
27
|
-
].join('\n\n');
|
|
8
|
+
const resolvePageComponentInfo = async ({ app, htmlFilePathRelative, key, }) => {
|
|
28
9
|
// resolve component file path
|
|
29
|
-
const componentFilePathRelative = utils_1.path.join('pages',
|
|
10
|
+
const componentFilePathRelative = utils_1.path.join('pages', `${htmlFilePathRelative}.vue`);
|
|
30
11
|
const componentFilePath = app.dir.temp(componentFilePathRelative);
|
|
31
12
|
const componentFileChunkName = key;
|
|
32
13
|
return {
|
|
33
|
-
headers,
|
|
34
|
-
links,
|
|
35
14
|
componentFilePath,
|
|
36
15
|
componentFilePathRelative,
|
|
37
|
-
componentFileContent,
|
|
38
16
|
componentFileChunkName,
|
|
39
17
|
};
|
|
40
18
|
};
|
|
@@ -14,9 +14,8 @@ const resolvePageContent = ({ contentRaw, }) => {
|
|
|
14
14
|
excerptRaw: '',
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
const { data, content,
|
|
18
17
|
/* istanbul ignore next */
|
|
19
|
-
excerpt = '', } = matter(contentRaw, {
|
|
18
|
+
const { data, content, excerpt = '', } = matter(contentRaw, {
|
|
20
19
|
excerpt_separator: '<!-- more -->',
|
|
21
20
|
engines: {
|
|
22
21
|
toml: toml.parse.bind(toml),
|
|
@@ -2,8 +2,9 @@ import type { App } from '../types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Resolve page data file path
|
|
4
4
|
*/
|
|
5
|
-
export declare const resolvePageDataInfo: ({ app, key, }: {
|
|
5
|
+
export declare const resolvePageDataInfo: ({ app, htmlFilePathRelative, key, }: {
|
|
6
6
|
app: App;
|
|
7
|
+
htmlFilePathRelative: string;
|
|
7
8
|
key: string;
|
|
8
9
|
}) => {
|
|
9
10
|
dataFilePath: string;
|
|
@@ -5,8 +5,8 @@ const utils_1 = require("@vuepress/utils");
|
|
|
5
5
|
/**
|
|
6
6
|
* Resolve page data file path
|
|
7
7
|
*/
|
|
8
|
-
const resolvePageDataInfo = ({ app, key, }) => {
|
|
9
|
-
const dataFilePathRelative = utils_1.path.join(
|
|
8
|
+
const resolvePageDataInfo = ({ app, htmlFilePathRelative, key, }) => {
|
|
9
|
+
const dataFilePathRelative = utils_1.path.join('pages', `${htmlFilePathRelative}.js`);
|
|
10
10
|
const dataFilePath = app.dir.temp(dataFilePathRelative);
|
|
11
11
|
const dataFileChunkName = key;
|
|
12
12
|
return {
|
|
@@ -12,17 +12,16 @@ const DEFAULT_DATE = '0000-00-00';
|
|
|
12
12
|
* It will be resolved as 'yyyy-MM-dd' format
|
|
13
13
|
*/
|
|
14
14
|
const resolvePageDate = ({ frontmatter, filePathRelative, }) => {
|
|
15
|
-
var _a, _b;
|
|
16
15
|
// `frontmatter.date` could be parsed as UTC Date directly
|
|
17
16
|
if (frontmatter.date instanceof Date) {
|
|
18
|
-
return shared_1.formatDateString([
|
|
17
|
+
return (0, shared_1.formatDateString)([
|
|
19
18
|
frontmatter.date.getUTCFullYear(),
|
|
20
19
|
frontmatter.date.getUTCMonth() + 1,
|
|
21
20
|
frontmatter.date.getUTCDate(),
|
|
22
21
|
].join('-'), DEFAULT_DATE);
|
|
23
22
|
}
|
|
24
|
-
if (shared_1.isString(frontmatter.date)) {
|
|
25
|
-
return shared_1.formatDateString(frontmatter.date, DEFAULT_DATE);
|
|
23
|
+
if ((0, shared_1.isString)(frontmatter.date)) {
|
|
24
|
+
return (0, shared_1.formatDateString)(frontmatter.date, DEFAULT_DATE);
|
|
26
25
|
}
|
|
27
26
|
if (filePathRelative === null) {
|
|
28
27
|
return DEFAULT_DATE;
|
|
@@ -31,14 +30,14 @@ const resolvePageDate = ({ frontmatter, filePathRelative, }) => {
|
|
|
31
30
|
if (filename) {
|
|
32
31
|
const matches = filename.match(FILENAME_DATE_RE);
|
|
33
32
|
if (matches) {
|
|
34
|
-
return shared_1.formatDateString(`${matches[1]}-${matches[2]}-${
|
|
33
|
+
return (0, shared_1.formatDateString)(`${matches[1]}-${matches[2]}-${matches[3] ?? '01'}`, DEFAULT_DATE);
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
const dirname = utils_1.path.dirname(filePathRelative);
|
|
38
|
-
if (dirname) {
|
|
37
|
+
if (dirname !== '.') {
|
|
39
38
|
const matches = dirname.match(DIRNAME_DATE_RE);
|
|
40
39
|
if (matches) {
|
|
41
|
-
return shared_1.formatDateString(`${matches[1]}-${matches[2]}-${
|
|
40
|
+
return (0, shared_1.formatDateString)(`${matches[1]}-${matches[2]}-${matches[3] ?? '01'}`, DEFAULT_DATE);
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
return DEFAULT_DATE;
|
|
@@ -2,12 +2,11 @@
|
|
|
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
|
*/
|
|
9
9
|
const resolvePageFileContent = async ({ filePath, options, }) => {
|
|
10
|
-
var _a;
|
|
11
10
|
if (filePath) {
|
|
12
11
|
try {
|
|
13
12
|
// read page content from file
|
|
@@ -15,10 +14,10 @@ const resolvePageFileContent = async ({ filePath, options, }) => {
|
|
|
15
14
|
return content;
|
|
16
15
|
}
|
|
17
16
|
catch (e) {
|
|
18
|
-
log(e.message);
|
|
17
|
+
log(e instanceof Error ? e.message : e);
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
// load raw content from options
|
|
22
|
-
return
|
|
21
|
+
return options.content ?? '';
|
|
23
22
|
};
|
|
24
23
|
exports.resolvePageFileContent = resolvePageFileContent;
|
|
@@ -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;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { App } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve page rendered html file path
|
|
4
|
+
*/
|
|
5
|
+
export declare const resolvePageHtmlInfo: ({ app, path: pagePath, }: {
|
|
6
|
+
app: App;
|
|
7
|
+
path: string;
|
|
8
|
+
}) => {
|
|
9
|
+
htmlFilePath: string;
|
|
10
|
+
htmlFilePathRelative: string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvePageHtmlInfo = void 0;
|
|
4
|
+
const shared_1 = require("@vuepress/shared");
|
|
5
|
+
/**
|
|
6
|
+
* Resolve page rendered html file path
|
|
7
|
+
*/
|
|
8
|
+
const resolvePageHtmlInfo = ({ app, path: pagePath, }) => {
|
|
9
|
+
// /foo.html -> foo.html
|
|
10
|
+
// /foo/ -> foo/index.html
|
|
11
|
+
const htmlFilePathRelative = (0, shared_1.removeLeadingSlash)(decodeURI(pagePath.replace(/\/$/, '/index.html')));
|
|
12
|
+
const htmlFilePath = app.dir.dest(htmlFilePathRelative);
|
|
13
|
+
return {
|
|
14
|
+
htmlFilePath,
|
|
15
|
+
htmlFilePathRelative,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
exports.resolvePageHtmlInfo = resolvePageHtmlInfo;
|
|
@@ -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;
|
|
@@ -6,10 +6,9 @@ const shared_1 = require("@vuepress/shared");
|
|
|
6
6
|
* Resolve language of page
|
|
7
7
|
*/
|
|
8
8
|
const resolvePageLang = ({ app, frontmatter, pathLocale, }) => {
|
|
9
|
-
|
|
10
|
-
if (shared_1.isString(frontmatter.lang) && frontmatter.lang) {
|
|
9
|
+
if ((0, shared_1.isString)(frontmatter.lang) && frontmatter.lang) {
|
|
11
10
|
return frontmatter.lang;
|
|
12
11
|
}
|
|
13
|
-
return
|
|
12
|
+
return app.siteData.locales[pathLocale]?.lang ?? app.siteData.lang;
|
|
14
13
|
};
|
|
15
14
|
exports.resolvePageLang = resolvePageLang;
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolvePagePath = void 0;
|
|
4
|
+
const shared_1 = require("@vuepress/shared");
|
|
5
|
+
const utils_1 = require("@vuepress/utils");
|
|
4
6
|
/**
|
|
5
7
|
* Resolve the final route path of a page
|
|
6
8
|
*/
|
|
7
|
-
const resolvePagePath = ({ permalink, pathInferred, options, }) =>
|
|
9
|
+
const resolvePagePath = ({ permalink, pathInferred, options, }) => {
|
|
10
|
+
let pagePath = options.path || permalink || pathInferred;
|
|
11
|
+
if (!pagePath) {
|
|
12
|
+
throw utils_1.logger.createError(`page path is empty, page options: ${JSON.stringify(options, null, 2)}`);
|
|
13
|
+
}
|
|
14
|
+
if (!pagePath.endsWith('.html')) {
|
|
15
|
+
pagePath = (0, shared_1.ensureEndingSlash)(pagePath);
|
|
16
|
+
}
|
|
17
|
+
return encodeURI(pagePath);
|
|
18
|
+
};
|
|
8
19
|
exports.resolvePagePath = resolvePagePath;
|
|
@@ -7,13 +7,12 @@ const utils_1 = require("@vuepress/utils");
|
|
|
7
7
|
* Resolve page permalink from frontmatter / options / pattern
|
|
8
8
|
*/
|
|
9
9
|
const resolvePagePermalink = ({ frontmatter, slug, date, pathInferred, pathLocale, }) => {
|
|
10
|
-
var _a;
|
|
11
10
|
// use permalink in frontmatter directly
|
|
12
|
-
if (shared_1.isString(frontmatter.permalink)) {
|
|
11
|
+
if ((0, shared_1.isString)(frontmatter.permalink)) {
|
|
13
12
|
return frontmatter.permalink;
|
|
14
13
|
}
|
|
15
14
|
// get permalink pattern from frontmatter or options
|
|
16
|
-
const pattern = shared_1.isString(frontmatter.permalinkPattern)
|
|
15
|
+
const pattern = (0, shared_1.isString)(frontmatter.permalinkPattern)
|
|
17
16
|
? frontmatter.permalinkPattern
|
|
18
17
|
: null;
|
|
19
18
|
if (!pattern) {
|
|
@@ -26,7 +25,7 @@ const resolvePagePermalink = ({ frontmatter, slug, date, pathInferred, pathLocal
|
|
|
26
25
|
.replace(/:month/, month)
|
|
27
26
|
.replace(/:day/, day)
|
|
28
27
|
.replace(/:slug/, slug)
|
|
29
|
-
.replace(/:raw/,
|
|
30
|
-
return shared_1.ensureLeadingSlash(link);
|
|
28
|
+
.replace(/:raw/, pathInferred?.replace(/^\//, '') ?? ''));
|
|
29
|
+
return (0, shared_1.ensureLeadingSlash)(link);
|
|
31
30
|
};
|
|
32
31
|
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, }) => frontmatter.routeMeta ?? {};
|
|
8
|
+
exports.resolvePageRouteMeta = resolvePageRouteMeta;
|
|
@@ -2,4 +2,4 @@ import type { HookQueue } from '../types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Create hook queue for plugin system
|
|
4
4
|
*/
|
|
5
|
-
export declare const createHookQueue: <T extends keyof import("../types").Hooks>(name: T
|
|
5
|
+
export declare const createHookQueue: <T extends keyof import("../types").Hooks>(name: T) => HookQueue<T>;
|
|
@@ -1,76 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createHookQueue = void 0;
|
|
4
|
-
const shared_1 = require("@vuepress/shared");
|
|
5
4
|
const utils_1 = require("@vuepress/utils");
|
|
6
|
-
const log = utils_1.debug('vuepress:core/plugin-api');
|
|
5
|
+
const log = (0, utils_1.debug)('vuepress:core/plugin-api');
|
|
7
6
|
/**
|
|
8
7
|
* Create hook queue for plugin system
|
|
9
8
|
*/
|
|
10
|
-
const createHookQueue = (name
|
|
9
|
+
const createHookQueue = (name) => {
|
|
11
10
|
const items = [];
|
|
12
11
|
const hookQueue = {
|
|
13
|
-
// hook name
|
|
14
12
|
name,
|
|
15
|
-
// hook items array
|
|
16
13
|
items,
|
|
17
|
-
// add hook item to queue
|
|
18
14
|
add: (item) => {
|
|
19
15
|
items.push(item);
|
|
20
16
|
},
|
|
21
|
-
// process the hook queue and get the results
|
|
22
17
|
process: async (...args) => {
|
|
23
18
|
// store the results of all hook items
|
|
24
19
|
const results = [];
|
|
25
|
-
// process
|
|
26
|
-
const
|
|
20
|
+
// process all hook items
|
|
21
|
+
for (const item of items) {
|
|
27
22
|
log(`process ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
|
|
28
23
|
try {
|
|
29
24
|
// process and get the result of the the hook item
|
|
30
|
-
// @ts-
|
|
25
|
+
// @ts-expect-error: the types could not be narrowed correctly
|
|
31
26
|
const result = (await item.hook(...args));
|
|
32
27
|
// push the result to results array
|
|
33
28
|
if (result !== undefined) {
|
|
34
29
|
results.push(result);
|
|
35
30
|
}
|
|
36
31
|
}
|
|
37
|
-
catch (
|
|
38
|
-
utils_1.logger.error(`error in hook ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
|
|
39
|
-
throw error;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
// process all hook items in current queue
|
|
43
|
-
if (parallel) {
|
|
44
|
-
// process in parallel
|
|
45
|
-
await Promise.all(items.map((item) => processItem(item, ...args)));
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
// process in serial
|
|
49
|
-
for (const item of items) {
|
|
50
|
-
await processItem(item, ...args);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return results;
|
|
54
|
-
},
|
|
55
|
-
// process the hook queue and get the results
|
|
56
|
-
processSync: (...args) => {
|
|
57
|
-
// store the results of all hook items
|
|
58
|
-
const results = [];
|
|
59
|
-
// process all hook items
|
|
60
|
-
for (const item of items) {
|
|
61
|
-
log(`processSync ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
|
|
62
|
-
try {
|
|
63
|
-
// @ts-ignore
|
|
64
|
-
// process and get the result of the the hook item
|
|
65
|
-
const result = item.hook(...args);
|
|
66
|
-
// push the result to results array
|
|
67
|
-
if (result !== undefined && !shared_1.isPromise(result)) {
|
|
68
|
-
results.push(result);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
32
|
+
catch (e) {
|
|
72
33
|
utils_1.logger.error(`error in hook ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
|
|
73
|
-
throw
|
|
34
|
+
throw e;
|
|
74
35
|
}
|
|
75
36
|
}
|
|
76
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,22 @@ 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
|
+
extendsBundlerOptions: (0, createHookQueue_1.createHookQueue)('extendsBundlerOptions'),
|
|
16
17
|
// client files hooks
|
|
17
|
-
clientAppEnhanceFiles: createHookQueue_1.createHookQueue('clientAppEnhanceFiles'
|
|
18
|
-
clientAppRootComponentFiles: createHookQueue_1.createHookQueue('clientAppRootComponentFiles'
|
|
19
|
-
clientAppSetupFiles: createHookQueue_1.createHookQueue('clientAppSetupFiles'
|
|
18
|
+
clientAppEnhanceFiles: (0, createHookQueue_1.createHookQueue)('clientAppEnhanceFiles'),
|
|
19
|
+
clientAppRootComponentFiles: (0, createHookQueue_1.createHookQueue)('clientAppRootComponentFiles'),
|
|
20
|
+
clientAppSetupFiles: (0, createHookQueue_1.createHookQueue)('clientAppSetupFiles'),
|
|
20
21
|
// bundler hooks
|
|
21
|
-
alias: createHookQueue_1.createHookQueue('alias'),
|
|
22
|
-
define: createHookQueue_1.createHookQueue('define'),
|
|
22
|
+
alias: (0, createHookQueue_1.createHookQueue)('alias'),
|
|
23
|
+
define: (0, createHookQueue_1.createHookQueue)('define'),
|
|
23
24
|
});
|
|
24
25
|
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
|
/**
|
package/lib/pluginApi/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -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
|
|
@@ -19,6 +19,9 @@ const normalizeClientFilesHook = (hook) => async (app) => {
|
|
|
19
19
|
if (isExisted) {
|
|
20
20
|
result.push(filePath);
|
|
21
21
|
}
|
|
22
|
+
else {
|
|
23
|
+
throw utils_1.logger.createError(`client file does not exist: ${filePath}`);
|
|
24
|
+
}
|
|
22
25
|
}
|
|
23
26
|
return result;
|
|
24
27
|
};
|
|
@@ -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) => (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;
|