@vuepress/core 2.0.0-beta.18 → 2.0.0-beta.22

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.
@@ -14,13 +14,7 @@ const createAppPages = async (app) => {
14
14
  cwd: app.dir.source(),
15
15
  });
16
16
  // create pages from files
17
- const pages = await Promise.all(pagePaths.map(async (filePath) => {
18
- const pageOptions = { filePath };
19
- // plugin hook: extendsPageOptions
20
- const extendsPageOptions = await app.pluginApi.hooks.extendsPageOptions.process(filePath, app);
21
- extendsPageOptions.forEach((item) => Object.assign(pageOptions, item));
22
- return page_1.createPage(app, pageOptions);
23
- }));
17
+ const pages = await Promise.all(pagePaths.map((filePath) => page_1.createPage(app, { filePath })));
24
18
  // if there is no 404 page, add one
25
19
  if (!pages.some((page) => page.path === '/404.html')) {
26
20
  pages.push(await page_1.createPage(app, {
@@ -5,6 +5,11 @@ exports.preparePageComponent = void 0;
5
5
  * Generate page component temp file of a single page
6
6
  */
7
7
  const preparePageComponent = async (app, page) => {
8
- await app.writeTemp(page.componentFilePathRelative, page.componentFileContent);
8
+ await app.writeTemp(page.componentFilePathRelative, [
9
+ // take the rendered markdown content as <template>
10
+ `<template>${page.contentRendered}</template>\n`,
11
+ // hoist `<script>`, `<style>` and other custom blocks
12
+ ...page.hoistedTags,
13
+ ].join('\n'));
9
14
  };
10
15
  exports.preparePageComponent = preparePageComponent;
@@ -1,2 +1,2 @@
1
1
  import type { App, Page, PageOptions } from '../types';
2
- export declare const createPage: (app: App, options: PageOptions) => Promise<Page>;
2
+ export declare const createPage: (app: App, optionsRaw: PageOptions) => Promise<Page>;
@@ -14,10 +14,13 @@ const resolvePageFrontmatter_1 = require("./resolvePageFrontmatter");
14
14
  const resolvePageHtmlInfo_1 = require("./resolvePageHtmlInfo");
15
15
  const resolvePageKey_1 = require("./resolvePageKey");
16
16
  const resolvePageLang_1 = require("./resolvePageLang");
17
+ const resolvePageOptions_1 = require("./resolvePageOptions");
17
18
  const resolvePagePath_1 = require("./resolvePagePath");
18
19
  const resolvePagePermalink_1 = require("./resolvePagePermalink");
19
20
  const resolvePageSlug_1 = require("./resolvePageSlug");
20
- const createPage = async (app, options) => {
21
+ const createPage = async (app, optionsRaw) => {
22
+ // resolve page options from raw options
23
+ const options = await resolvePageOptions_1.resolvePageOptions({ app, optionsRaw });
21
24
  // resolve page file absolute path and relative path
22
25
  const { filePath, filePathRelative } = resolvePageFilePath_1.resolvePageFilePath({
23
26
  app,
@@ -40,7 +43,7 @@ const createPage = async (app, options) => {
40
43
  frontmatter,
41
44
  });
42
45
  // render page content and extract information
43
- const { renderedContent, deps, headers, hoistedTags, links, title, } = await renderPageContent_1.renderPageContent({
46
+ const { contentRendered, deps, headers, hoistedTags, links, title, } = await renderPageContent_1.renderPageContent({
44
47
  app,
45
48
  content,
46
49
  filePath,
@@ -73,9 +76,8 @@ const createPage = async (app, options) => {
73
76
  path,
74
77
  });
75
78
  // resolve page component and extract headers & links
76
- const { componentFilePath, componentFilePathRelative, componentFileContent, componentFileChunkName, } = await resolvePageComponentInfo_1.resolvePageComponentInfo({
79
+ const { componentFilePath, componentFilePathRelative, componentFileChunkName, } = await resolvePageComponentInfo_1.resolvePageComponentInfo({
77
80
  app,
78
- renderedContent,
79
81
  hoistedTags,
80
82
  htmlFilePathRelative,
81
83
  key,
@@ -91,19 +93,21 @@ const createPage = async (app, options) => {
91
93
  excerpt,
92
94
  headers,
93
95
  // extra data
94
- pathInferred,
95
- pathLocale,
96
96
  content,
97
- slug,
97
+ contentRendered,
98
98
  date,
99
99
  deps,
100
+ hoistedTags,
100
101
  links,
102
+ pathInferred,
103
+ pathLocale,
104
+ permalink,
105
+ slug,
101
106
  // file info
102
107
  filePath,
103
108
  filePathRelative,
104
109
  componentFilePath,
105
110
  componentFilePathRelative,
106
- componentFileContent,
107
111
  componentFileChunkName,
108
112
  dataFilePath,
109
113
  dataFilePathRelative,
@@ -12,6 +12,7 @@ export * from './resolvePageFrontmatter';
12
12
  export * from './resolvePageHtmlInfo';
13
13
  export * from './resolvePageKey';
14
14
  export * from './resolvePageLang';
15
+ export * from './resolvePageOptions';
15
16
  export * from './resolvePagePath';
16
17
  export * from './resolvePagePermalink';
17
18
  export * from './resolvePageSlug';
package/lib/page/index.js CHANGED
@@ -24,6 +24,7 @@ __exportStar(require("./resolvePageFrontmatter"), exports);
24
24
  __exportStar(require("./resolvePageHtmlInfo"), exports);
25
25
  __exportStar(require("./resolvePageKey"), exports);
26
26
  __exportStar(require("./resolvePageLang"), exports);
27
+ __exportStar(require("./resolvePageOptions"), exports);
27
28
  __exportStar(require("./resolvePagePath"), exports);
28
29
  __exportStar(require("./resolvePagePermalink"), exports);
29
30
  __exportStar(require("./resolvePageSlug"), exports);
@@ -10,7 +10,7 @@ export declare const renderPageContent: ({ app, content, frontmatter, filePath,
10
10
  filePath: string | null;
11
11
  filePathRelative: string | null;
12
12
  }) => Promise<{
13
- renderedContent: string;
13
+ contentRendered: string;
14
14
  deps: string[];
15
15
  headers: MarkdownHeader[];
16
16
  hoistedTags: string[];
@@ -11,11 +11,11 @@ const renderPageContent = async ({ app, content, frontmatter, filePath, filePath
11
11
  filePathRelative,
12
12
  frontmatter,
13
13
  };
14
- const renderedContent = app.markdown.render(content, markdownEnv);
14
+ const contentRendered = app.markdown.render(content, markdownEnv);
15
15
  /* istanbul ignore next */
16
16
  const { headers = [], hoistedTags = [], importedFiles = [], links = [], title = '', } = markdownEnv;
17
17
  return {
18
- renderedContent,
18
+ contentRendered,
19
19
  deps: importedFiles,
20
20
  headers,
21
21
  hoistedTags,
@@ -2,15 +2,13 @@ import type { App } from '../types';
2
2
  /**
3
3
  * Resolve page component and related info
4
4
  */
5
- export declare const resolvePageComponentInfo: ({ app, renderedContent, hoistedTags, htmlFilePathRelative, key, }: {
5
+ export declare const resolvePageComponentInfo: ({ app, hoistedTags, htmlFilePathRelative, key, }: {
6
6
  app: App;
7
- renderedContent: string;
8
7
  hoistedTags: string[];
9
8
  htmlFilePathRelative: string;
10
9
  key: string;
11
10
  }) => Promise<{
12
11
  componentFilePath: string;
13
12
  componentFilePathRelative: string;
14
- componentFileContent: string;
15
13
  componentFileChunkName: string;
16
14
  }>;
@@ -5,14 +5,7 @@ const utils_1 = require("@vuepress/utils");
5
5
  /**
6
6
  * Resolve page component and related info
7
7
  */
8
- const resolvePageComponentInfo = async ({ app, renderedContent, hoistedTags, htmlFilePathRelative, key, }) => {
9
- // resolve component file content
10
- // take the rendered markdown content as <template>
11
- // hoist `<script>`, `<style>` and other custom blocks
12
- const componentFileContent = [
13
- `<template>${renderedContent}</template>`,
14
- ...hoistedTags,
15
- ].join('\n\n');
8
+ const resolvePageComponentInfo = async ({ app, hoistedTags, htmlFilePathRelative, key, }) => {
16
9
  // resolve component file path
17
10
  const componentFilePathRelative = utils_1.path.join('pages', `${htmlFilePathRelative}.vue`);
18
11
  const componentFilePath = app.dir.temp(componentFilePathRelative);
@@ -20,7 +13,6 @@ const resolvePageComponentInfo = async ({ app, renderedContent, hoistedTags, htm
20
13
  return {
21
14
  componentFilePath,
22
15
  componentFilePathRelative,
23
- componentFileContent,
24
16
  componentFileChunkName,
25
17
  };
26
18
  };
@@ -0,0 +1,8 @@
1
+ import type { App, PageOptions } from '../types';
2
+ /**
3
+ * Render page content and extract related info
4
+ */
5
+ export declare const resolvePageOptions: ({ app, optionsRaw, }: {
6
+ app: App;
7
+ optionsRaw: PageOptions;
8
+ }) => Promise<PageOptions>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolvePageOptions = void 0;
4
+ /**
5
+ * Render page content and extract related info
6
+ */
7
+ const resolvePageOptions = async ({ app, optionsRaw, }) => {
8
+ const options = { ...optionsRaw };
9
+ // plugin hook: extendsPageOptions
10
+ const extendsPageOptions = await app.pluginApi.hooks.extendsPageOptions.process(optionsRaw, app);
11
+ extendsPageOptions.forEach((item) => Object.assign(options, item));
12
+ return options;
13
+ };
14
+ exports.resolvePageOptions = resolvePageOptions;
@@ -4,6 +4,32 @@ import type { PageData, PageFrontmatter } from '@vuepress/shared';
4
4
  * Vuepress Page
5
5
  */
6
6
  export interface Page extends PageData {
7
+ /**
8
+ * Raw Content of the page
9
+ */
10
+ content: string;
11
+ /**
12
+ * Rendered content of the page
13
+ */
14
+ contentRendered: string;
15
+ /**
16
+ * Date of the page, in 'yyyy-MM-dd' format
17
+ *
18
+ * @example '2020-09-09'
19
+ */
20
+ date: string;
21
+ /**
22
+ * Dependencies of the page
23
+ */
24
+ deps: string[];
25
+ /**
26
+ * Hoisted tags of the page
27
+ */
28
+ hoistedTags: string[];
29
+ /**
30
+ * Links of the page
31
+ */
32
+ links: MarkdownLink[];
7
33
  /**
8
34
  * Path of the page that inferred from file path
9
35
  *
@@ -20,6 +46,16 @@ export interface Page extends PageData {
20
46
  * @example '/zh/getting-started.html' -> '/zh/'
21
47
  */
22
48
  pathLocale: string;
49
+ /**
50
+ * Permalink of the page
51
+ *
52
+ * If the page does not have a permalink, it would be `null`
53
+ */
54
+ permalink: string | null;
55
+ /**
56
+ * Slug of the page
57
+ */
58
+ slug: string;
23
59
  /**
24
60
  * Source file path
25
61
  *
@@ -32,14 +68,6 @@ export interface Page extends PageData {
32
68
  * If the page does not come from a file, it would be `null`
33
69
  */
34
70
  filePathRelative: string | null;
35
- /**
36
- * Rendered html file path
37
- */
38
- htmlFilePath: string;
39
- /**
40
- * Rendered html file path relative to dest directory
41
- */
42
- htmlFilePathRelative: string;
43
71
  /**
44
72
  * Component file path
45
73
  */
@@ -48,10 +76,6 @@ export interface Page extends PageData {
48
76
  * Component file path relative to temp directory
49
77
  */
50
78
  componentFilePathRelative: string;
51
- /**
52
- * Component file content that generated from the source file
53
- */
54
- componentFileContent: string;
55
79
  /**
56
80
  * Component file chunk name
57
81
  *
@@ -73,27 +97,13 @@ export interface Page extends PageData {
73
97
  */
74
98
  dataFileChunkName: string;
75
99
  /**
76
- * Content of the page
77
- */
78
- content: string;
79
- /**
80
- * Slug of the page
81
- */
82
- slug: string;
83
- /**
84
- * Date of the page, in 'yyyy-MM-dd' format
85
- *
86
- * @example '2020-09-09'
87
- */
88
- date: string;
89
- /**
90
- * Dependencies of the page
100
+ * Rendered html file path
91
101
  */
92
- deps: string[];
102
+ htmlFilePath: string;
93
103
  /**
94
- * Links of the page
104
+ * Rendered html file path relative to dest directory
95
105
  */
96
- links: MarkdownLink[];
106
+ htmlFilePathRelative: string;
97
107
  }
98
108
  /**
99
109
  * Options to create vuepress page
@@ -14,7 +14,7 @@ export declare type LifeCycleHook<T extends unknown[] = []> = Hook<(app: App, ..
14
14
  export declare type ClientFilesHook = Hook<string | string[] | ((app: App) => PromiseOrNot<string | string[]>), (app: App) => Promise<string[]>>;
15
15
  export declare type ReturnObjectHook = Hook<Record<string, any> | ((app: App) => PromiseOrNot<Record<string, any>>), (app: App) => Promise<Record<string, any>>>;
16
16
  export declare type ExtendsMarkdownHook = Hook<(md: Markdown, app: App) => PromiseOrNot<void>>;
17
- export declare type ExtendsPageOptionsHook = Hook<(filePath: string, app: App) => PromiseOrNot<PageOptions>>;
17
+ export declare type ExtendsPageOptionsHook = Hook<(options: PageOptions, app: App) => PromiseOrNot<PageOptions>>;
18
18
  export declare type ExtendsPageDataHook = Hook<(page: Page, app: App) => PromiseOrNot<Record<string, any>>>;
19
19
  /**
20
20
  * List of hooks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/core",
3
- "version": "2.0.0-beta.18",
3
+ "version": "2.0.0-beta.22",
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.18",
30
- "@vuepress/markdown": "2.0.0-beta.18",
31
- "@vuepress/shared": "2.0.0-beta.18",
32
- "@vuepress/utils": "2.0.0-beta.18",
29
+ "@vuepress/client": "2.0.0-beta.21",
30
+ "@vuepress/markdown": "2.0.0-beta.22",
31
+ "@vuepress/shared": "2.0.0-beta.21",
32
+ "@vuepress/utils": "2.0.0-beta.21",
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": "b74a98f3ebe57b5edf3443bf747834a767e67796"
39
+ "gitHead": "8db8d235df8914c70c864ae3f3f66f93cfd1a457"
40
40
  }