@vuepress/core 2.0.0-beta.45 → 2.0.0-beta.48
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/prepare/preparePageComponent.js +2 -1
- package/lib/app/prepare/preparePageData.js +2 -1
- package/lib/app/prepare/preparePagesRoutes.js +4 -31
- package/lib/app/prepare/prepareSiteData.js +1 -1
- package/lib/app/resolveAppOptions.d.ts +1 -1
- package/lib/app/resolveAppOptions.js +2 -1
- package/lib/page/createPage.js +1 -0
- package/lib/page/resolvePagePermalink.d.ts +3 -2
- package/lib/page/resolvePagePermalink.js +17 -7
- package/lib/types/app/options.d.ts +1 -0
- package/package.json +6 -6
|
@@ -7,7 +7,8 @@ exports.preparePageComponent = void 0;
|
|
|
7
7
|
const preparePageComponent = async (app, page) => {
|
|
8
8
|
await app.writeTemp(page.componentFilePathRelative, [
|
|
9
9
|
// take the rendered markdown content as <template>
|
|
10
|
-
|
|
10
|
+
// #688: wrap the content with a <div> to avoid some potential issues of fragment component
|
|
11
|
+
`<template><div>${page.contentRendered}</div></template>\n`,
|
|
11
12
|
// hoist `<script>`, `<style>` and other custom blocks
|
|
12
13
|
...page.hoistedTags,
|
|
13
14
|
].join('\n'));
|
|
@@ -20,7 +20,8 @@ if (import.meta.hot) {
|
|
|
20
20
|
*/
|
|
21
21
|
const preparePageData = async (app, page) => {
|
|
22
22
|
// page data file content
|
|
23
|
-
let content = `export const data = ${JSON.stringify(page.data
|
|
23
|
+
let content = `export const data = JSON.parse(${JSON.stringify(JSON.stringify(page.data))})
|
|
24
|
+
`;
|
|
24
25
|
// inject HMR code
|
|
25
26
|
if (app.env.isDev) {
|
|
26
27
|
content += HMR_CODE;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.preparePagesRoutes = void 0;
|
|
4
4
|
const shared_1 = require("@vuepress/shared");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Resolve page route item
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
8
|
+
const resolvePageRouteItem = ({ key, path, pathInferred, filePathRelative, routeMeta, }) => {
|
|
9
9
|
// paths that should redirect to this page, use set to dedupe
|
|
10
10
|
const redirectsSet = new Set();
|
|
11
11
|
// redirect from decoded path
|
|
@@ -37,38 +37,11 @@ const transformPageToRouteItem = ({ key, path, pathInferred, filePathRelative, r
|
|
|
37
37
|
* Generate routes temp file
|
|
38
38
|
*/
|
|
39
39
|
const preparePagesRoutes = async (app) => {
|
|
40
|
-
const routeItems = app.pages.map(
|
|
40
|
+
const routeItems = app.pages.map(resolvePageRouteItem);
|
|
41
41
|
const content = `\
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const routeItems = [\
|
|
42
|
+
export const pagesRoutes = [\
|
|
45
43
|
${routeItems.map((routeItem) => `\n ${JSON.stringify(routeItem)},`).join('')}
|
|
46
44
|
]
|
|
47
|
-
|
|
48
|
-
export const pagesRoutes = routeItems.reduce(
|
|
49
|
-
(result, [name, path, meta, redirects]) => {
|
|
50
|
-
result.push(
|
|
51
|
-
{
|
|
52
|
-
name,
|
|
53
|
-
path,
|
|
54
|
-
component: Vuepress,
|
|
55
|
-
meta,
|
|
56
|
-
},
|
|
57
|
-
...redirects.map((item) => ({
|
|
58
|
-
path: item,
|
|
59
|
-
redirect: path,
|
|
60
|
-
}))
|
|
61
|
-
)
|
|
62
|
-
return result
|
|
63
|
-
},
|
|
64
|
-
[
|
|
65
|
-
{
|
|
66
|
-
name: '404',
|
|
67
|
-
path: '/:catchAll(.*)',
|
|
68
|
-
component: Vuepress,
|
|
69
|
-
}
|
|
70
|
-
]
|
|
71
|
-
)
|
|
72
45
|
`;
|
|
73
46
|
await app.writeTemp('internal/pagesRoutes.js', content);
|
|
74
47
|
};
|
|
@@ -20,7 +20,7 @@ if (import.meta.hot) {
|
|
|
20
20
|
*/
|
|
21
21
|
const prepareSiteData = async (app) => {
|
|
22
22
|
let content = `\
|
|
23
|
-
export const siteData = ${JSON.stringify(app.siteData
|
|
23
|
+
export const siteData = JSON.parse(${JSON.stringify(JSON.stringify(app.siteData))})
|
|
24
24
|
`;
|
|
25
25
|
// inject HMR code
|
|
26
26
|
if (app.env.isDev) {
|
|
@@ -2,4 +2,4 @@ import type { AppConfig, AppOptions } from '../types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Create app options with default values
|
|
4
4
|
*/
|
|
5
|
-
export declare const resolveAppOptions: ({ base, lang, title, description, head, locales, source, dest, temp, cache, public: publicDir, host, port, open, templateDev, shouldPreload, shouldPrefetch, templateBuild, bundler, debug, markdown, pagePatterns, plugins, theme, }: AppConfig) => AppOptions;
|
|
5
|
+
export declare const resolveAppOptions: ({ base, lang, title, description, head, locales, source, dest, temp, cache, public: publicDir, host, port, open, templateDev, shouldPreload, shouldPrefetch, templateBuild, bundler, debug, markdown, pagePatterns, permalinkPattern, plugins, theme, }: AppConfig) => AppOptions;
|
|
@@ -15,7 +15,7 @@ host = '0.0.0.0', port = 8080, open = false, templateDev = utils_1.path.normaliz
|
|
|
15
15
|
// build config
|
|
16
16
|
shouldPreload = true, shouldPrefetch = true, templateBuild = utils_1.path.normalize(require.resolve('@vuepress/client/templates/build.html')),
|
|
17
17
|
// common config
|
|
18
|
-
bundler, debug = false, markdown = {}, pagePatterns = ['**/*.md', '!.vuepress', '!node_modules'], plugins = [], theme, }) => ({
|
|
18
|
+
bundler, debug = false, markdown = {}, pagePatterns = ['**/*.md', '!.vuepress', '!node_modules'], permalinkPattern = null, plugins = [], theme, }) => ({
|
|
19
19
|
base,
|
|
20
20
|
lang,
|
|
21
21
|
title,
|
|
@@ -38,6 +38,7 @@ bundler, debug = false, markdown = {}, pagePatterns = ['**/*.md', '!.vuepress',
|
|
|
38
38
|
debug,
|
|
39
39
|
markdown,
|
|
40
40
|
pagePatterns,
|
|
41
|
+
permalinkPattern,
|
|
41
42
|
plugins,
|
|
42
43
|
theme,
|
|
43
44
|
});
|
package/lib/page/createPage.js
CHANGED
|
@@ -62,6 +62,7 @@ const createPage = async (app, options) => {
|
|
|
62
62
|
const lang = (0, resolvePageLang_1.resolvePageLang)({ app, frontmatter, pathLocale });
|
|
63
63
|
// resolve page permalink
|
|
64
64
|
const permalink = (0, resolvePagePermalink_1.resolvePagePermalink)({
|
|
65
|
+
app,
|
|
65
66
|
frontmatter,
|
|
66
67
|
slug,
|
|
67
68
|
date,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { PageFrontmatter } from '../types';
|
|
1
|
+
import type { App, PageFrontmatter } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Resolve page permalink from frontmatter / options / pattern
|
|
4
4
|
*/
|
|
5
|
-
export declare const resolvePagePermalink: ({ frontmatter, slug, date, pathInferred, pathLocale, }: {
|
|
5
|
+
export declare const resolvePagePermalink: ({ app, frontmatter, slug, date, pathInferred, pathLocale, }: {
|
|
6
|
+
app: App;
|
|
6
7
|
frontmatter: PageFrontmatter;
|
|
7
8
|
slug: string;
|
|
8
9
|
date: string;
|
|
@@ -6,21 +6,19 @@ const utils_1 = require("@vuepress/utils");
|
|
|
6
6
|
/**
|
|
7
7
|
* Resolve page permalink from frontmatter / options / pattern
|
|
8
8
|
*/
|
|
9
|
-
const resolvePagePermalink = ({ frontmatter, slug, date, pathInferred, pathLocale, }) => {
|
|
9
|
+
const resolvePagePermalink = ({ app, frontmatter, slug, date, pathInferred, pathLocale, }) => {
|
|
10
10
|
// use permalink in frontmatter directly
|
|
11
11
|
if ((0, shared_1.isString)(frontmatter.permalink)) {
|
|
12
12
|
return frontmatter.permalink;
|
|
13
13
|
}
|
|
14
|
-
// get permalink pattern
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
: null;
|
|
18
|
-
if (!pattern) {
|
|
14
|
+
// get permalink pattern
|
|
15
|
+
const permalinkPattern = getPermalinkPattern({ app, frontmatter });
|
|
16
|
+
if (permalinkPattern === null) {
|
|
19
17
|
return null;
|
|
20
18
|
}
|
|
21
19
|
// resolve permalink according to the pattern
|
|
22
20
|
const [year, month, day] = date.split('-');
|
|
23
|
-
const link = utils_1.path.join(pathLocale,
|
|
21
|
+
const link = utils_1.path.join(pathLocale, permalinkPattern
|
|
24
22
|
.replace(/:year/, year)
|
|
25
23
|
.replace(/:month/, month)
|
|
26
24
|
.replace(/:day/, day)
|
|
@@ -29,3 +27,15 @@ const resolvePagePermalink = ({ frontmatter, slug, date, pathInferred, pathLocal
|
|
|
29
27
|
return (0, shared_1.ensureLeadingSlash)(link);
|
|
30
28
|
};
|
|
31
29
|
exports.resolvePagePermalink = resolvePagePermalink;
|
|
30
|
+
/**
|
|
31
|
+
* Get permalink pattern from frontmatter or app options
|
|
32
|
+
*/
|
|
33
|
+
const getPermalinkPattern = ({ app, frontmatter, }) => {
|
|
34
|
+
if (frontmatter.permalinkPattern === null) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if ((0, shared_1.isString)(frontmatter.permalinkPattern)) {
|
|
38
|
+
return frontmatter.permalinkPattern;
|
|
39
|
+
}
|
|
40
|
+
return app.options.permalinkPattern;
|
|
41
|
+
};
|
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.48",
|
|
4
4
|
"description": "Core package of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"lib"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@vuepress/client": "2.0.0-beta.
|
|
26
|
-
"@vuepress/markdown": "2.0.0-beta.
|
|
27
|
-
"@vuepress/shared": "2.0.0-beta.
|
|
28
|
-
"@vuepress/utils": "2.0.0-beta.
|
|
25
|
+
"@vuepress/client": "2.0.0-beta.48",
|
|
26
|
+
"@vuepress/markdown": "2.0.0-beta.48",
|
|
27
|
+
"@vuepress/shared": "2.0.0-beta.48",
|
|
28
|
+
"@vuepress/utils": "2.0.0-beta.48",
|
|
29
29
|
"gray-matter": "^4.0.3",
|
|
30
30
|
"toml": "^3.0.0",
|
|
31
|
-
"vue": "^3.2.
|
|
31
|
+
"vue": "^3.2.36"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|