@vuepress/core 2.0.0-beta.25 → 2.0.0-beta.29

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.
Files changed (57) hide show
  1. package/lib/app/appInit.js +5 -4
  2. package/lib/app/appPrepare.js +11 -11
  3. package/lib/app/appUse.js +3 -3
  4. package/lib/app/createAppDir.js +6 -6
  5. package/lib/app/createAppMarkdown.d.ts +6 -0
  6. package/lib/app/createAppMarkdown.js +16 -0
  7. package/lib/app/createAppOptions.js +1 -1
  8. package/lib/app/createAppPages.js +14 -5
  9. package/lib/app/createBaseApp.js +12 -15
  10. package/lib/app/createBuildApp.d.ts +1 -1
  11. package/lib/app/createBuildApp.js +2 -2
  12. package/lib/app/createDevApp.d.ts +1 -1
  13. package/lib/app/createDevApp.js +2 -2
  14. package/lib/app/normalizePluginConfig.d.ts +1 -1
  15. package/lib/app/normalizePluginConfig.js +1 -1
  16. package/lib/app/prepare/preparePagesRoutes.js +5 -5
  17. package/lib/app/resolveBundler.js +1 -1
  18. package/lib/app/resolvePlugin.js +3 -3
  19. package/lib/app/resolvePluginModule.js +2 -2
  20. package/lib/app/resolvePluginsFromConfig.js +2 -2
  21. package/lib/app/resolveTheme.js +3 -3
  22. package/lib/app/resolveThemeInfo.js +4 -4
  23. package/lib/app/resolveThemeLayouts.js +1 -1
  24. package/lib/page/createPage.d.ts +1 -1
  25. package/lib/page/createPage.js +32 -24
  26. package/lib/page/index.d.ts +1 -2
  27. package/lib/page/index.js +1 -2
  28. package/lib/page/inferPagePath.js +2 -2
  29. package/lib/page/resolvePageContent.js +1 -1
  30. package/lib/page/resolvePageDate.d.ts +1 -1
  31. package/lib/page/resolvePageDate.js +5 -5
  32. package/lib/page/resolvePageFileContent.js +2 -2
  33. package/lib/page/resolvePageFilePath.d.ts +1 -1
  34. package/lib/page/resolvePageFilePath.js +6 -11
  35. package/lib/page/resolvePageHtmlInfo.js +1 -1
  36. package/lib/page/resolvePageKey.js +1 -1
  37. package/lib/page/resolvePageLang.js +1 -1
  38. package/lib/page/resolvePagePath.js +2 -2
  39. package/lib/page/resolvePagePermalink.js +3 -3
  40. package/lib/page/resolvePageRouteMeta.d.ts +7 -0
  41. package/lib/page/resolvePageRouteMeta.js +8 -0
  42. package/lib/pluginApi/createHookQueue.js +3 -3
  43. package/lib/pluginApi/createPluginApi.js +2 -2
  44. package/lib/pluginApi/createPluginApiHooks.js +14 -14
  45. package/lib/pluginApi/createPluginApiRegisterHooks.js +5 -5
  46. package/lib/pluginApi/normalizeClientFilesHook.js +2 -2
  47. package/lib/pluginApi/normalizeReturnObjectHook.js +1 -1
  48. package/lib/types/app/app.d.ts +7 -5
  49. package/lib/types/app/options.d.ts +7 -9
  50. package/lib/types/index.d.ts +1 -1
  51. package/lib/types/page.d.ts +29 -5
  52. package/lib/types/pluginApi/hooks.d.ts +6 -7
  53. package/package.json +6 -6
  54. package/lib/page/resolvePageData.d.ts +0 -8
  55. package/lib/page/resolvePageData.js +0 -23
  56. package/lib/page/resolvePageOptions.d.ts +0 -8
  57. package/lib/page/resolvePageOptions.js +0 -14
@@ -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),
@@ -1,4 +1,4 @@
1
- import { PageFrontmatter } from '../types';
1
+ import type { PageFrontmatter } from '../types';
2
2
  /**
3
3
  * Resolve page date according to frontmatter or file path
4
4
  *
@@ -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: { filePath }, }: {
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: { filePath }, }) => {
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
- // absolute file path
17
- if (utils_1.path.isAbsolute(filePath)) {
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: app.dir.source(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,7 @@
1
+ import type { PageFrontmatter } from '../types';
2
+ /**
3
+ * Resolve page route meta
4
+ */
5
+ export declare const resolvePageRouteMeta: ({ frontmatter, }: {
6
+ frontmatter: PageFrontmatter;
7
+ }) => Record<string, unknown>;
@@ -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 (error) {
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 error;
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
- // page hooks
12
- extendsPageOptions: createHookQueue_1.createHookQueue('extendsPageOptions'),
13
- extendsPageData: createHookQueue_1.createHookQueue('extendsPageData'),
14
- // markdown hooks
15
- extendsMarkdown: createHookQueue_1.createHookQueue('extendsMarkdown'),
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;
@@ -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;
@@ -1,6 +1,6 @@
1
1
  import type { Markdown } from '@vuepress/markdown';
2
2
  import type { SiteData } from '@vuepress/shared';
3
- import type { BundlerDev, BundlerBuild } from '../bundler';
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
  *
@@ -1,14 +1,12 @@
1
1
  import type { MarkdownOptions } from '@vuepress/markdown';
2
- import type { SiteLocaleConfig, SiteLocaleData } from '@vuepress/shared';
2
+ import type { SiteData } from '@vuepress/shared';
3
3
  import type { BundlerConfig } from '../bundler';
4
4
  import type { PluginConfig } from '../plugin';
5
5
  import type { ThemeConfig } from '../theme';
6
6
  /**
7
7
  * Vuepress app options
8
8
  */
9
- export interface AppOptions<T extends ThemeConfig = ThemeConfig, U extends BundlerConfig = BundlerConfig> extends SiteLocaleData {
10
- base: string;
11
- locales: SiteLocaleConfig;
9
+ export interface AppOptions<T extends ThemeConfig = ThemeConfig, U extends BundlerConfig = BundlerConfig> extends SiteData {
12
10
  theme: string;
13
11
  themeConfig: Partial<T>;
14
12
  bundler: string;
@@ -18,16 +16,16 @@ export interface AppOptions<T extends ThemeConfig = ThemeConfig, U extends Bundl
18
16
  temp: string;
19
17
  cache: string;
20
18
  public: string;
21
- markdown: MarkdownOptions;
22
19
  debug: boolean;
20
+ markdown: MarkdownOptions;
21
+ pagePatterns: string[];
22
+ plugins: PluginConfig[];
23
23
  host: string;
24
24
  port: number;
25
25
  open: boolean;
26
- pagePatterns: string[];
27
26
  templateDev: string;
28
- templateSSR: string;
29
27
  shouldPreload: ((file: string, type: string) => boolean) | boolean;
30
28
  shouldPrefetch: ((file: string, type: string) => boolean) | boolean;
31
- plugins: PluginConfig[];
29
+ templateSSR: string;
32
30
  }
33
- export declare type AppConfig = Partial<AppOptions> & Pick<AppOptions, 'source'>;
31
+ export declare type AppConfig<T extends ThemeConfig = ThemeConfig, U extends BundlerConfig = BundlerConfig> = Partial<AppOptions<T, U>> & Pick<AppOptions<T, U>, 'source'>;
@@ -1,4 +1,4 @@
1
- import type { HeadConfig, HeadTag, HeadTagEmpty, HeadTagNonEmpty, HeadAttrsConfig, LocaleConfig, LocaleData, PageData, PageFrontmatter, PageHeader, SiteData, SiteLocaleConfig } from '@vuepress/shared';
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';
@@ -3,11 +3,11 @@ import type { PageData, PageFrontmatter } from '@vuepress/shared';
3
3
  /**
4
4
  * Vuepress Page
5
5
  */
6
- export interface Page<T extends PageData = PageData> extends PageData {
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: T;
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
- path?: string;
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
- content?: string;
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
- extendsMarkdown: ExtendsMarkdownHook;
28
- extendsPageOptions: ExtendsPageOptionsHook;
29
- extendsPageData: ExtendsPageDataHook;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/core",
3
- "version": "2.0.0-beta.25",
3
+ "version": "2.0.0-beta.29",
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.25",
30
- "@vuepress/markdown": "2.0.0-beta.25",
31
- "@vuepress/shared": "2.0.0-beta.25",
32
- "@vuepress/utils": "2.0.0-beta.25",
29
+ "@vuepress/client": "2.0.0-beta.29",
30
+ "@vuepress/markdown": "2.0.0-beta.29",
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": "76ce5e52b07de75cf1f40a57ef3b6a682e44fce7"
39
+ "gitHead": "2c6eb4270f96b6351cd1f565798bed1f662a6bb2"
40
40
  }
@@ -1,8 +0,0 @@
1
- import type { App, Page, PageData } from '../types';
2
- /**
3
- * Resolve page data
4
- */
5
- export declare const resolvePageData: ({ app, page, }: {
6
- app: App;
7
- page: Page;
8
- }) => Promise<PageData>;
@@ -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;
@@ -1,8 +0,0 @@
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>;
@@ -1,14 +0,0 @@
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;