@vuepress/core 2.0.0-rc.2 → 2.0.0-rc.21

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/dist/index.js CHANGED
@@ -1,33 +1,18 @@
1
1
  // src/app/prepare/prepareClientConfigs.ts
2
2
  var prepareClientConfigs = async (app) => {
3
3
  const clientConfigFiles = await app.pluginApi.hooks.clientConfigFile.process(app);
4
- const content = `${clientConfigFiles.map((filePath, index) => `import clientConfig${index} from '${filePath}'`).join("\n")}
4
+ const content = `${clientConfigFiles.map(
5
+ (filePath, index) => `import * as clientConfig${index} from '${filePath}'`
6
+ ).join("\n")}
5
7
 
6
8
  export const clientConfigs = [
7
9
  ${clientConfigFiles.map((_, index) => ` clientConfig${index},`).join("\n")}
8
- ]
10
+ ].map((m) => m.default).filter(Boolean)
9
11
  `;
10
12
  await app.writeTemp("internal/clientConfigs.js", content);
11
13
  };
12
14
 
13
- // src/app/prepare/preparePageComponent.ts
14
- var preparePageComponent = async (app, page) => {
15
- await app.writeTemp(
16
- page.componentFilePathRelative,
17
- [
18
- // #688: wrap the content of `<template>` with a `<div>` to avoid some potential issues of fragment component
19
- `${page.sfcBlocks.template?.tagOpen}<div>${page.sfcBlocks.template?.contentStripped}</div>${page.sfcBlocks.template?.tagClose}
20
- `,
21
- // hoist `<script>`, `<style>` and other custom blocks
22
- page.sfcBlocks.script?.content,
23
- page.sfcBlocks.scriptSetup?.content,
24
- ...page.sfcBlocks.styles.map((item) => item.content),
25
- ...page.sfcBlocks.customBlocks.map((item) => item.content)
26
- ].join("\n")
27
- );
28
- };
29
-
30
- // src/app/prepare/preparePageData.ts
15
+ // src/app/prepare/preparePageChunk.ts
31
16
  var HMR_CODE = `
32
17
  if (import.meta.webpackHot) {
33
18
  import.meta.webpackHot.accept()
@@ -42,128 +27,23 @@ if (import.meta.hot) {
42
27
  })
43
28
  }
44
29
  `;
45
- var preparePageData = async (app, page) => {
46
- let content = `export const data = JSON.parse(${JSON.stringify(
47
- JSON.stringify(page.data)
48
- )})
30
+ var preparePageChunk = async (app, page) => {
31
+ let content = `import comp from ${JSON.stringify(page.componentFilePath)}
32
+ const data = JSON.parse(${JSON.stringify(JSON.stringify(page.data))})
33
+ export { comp, data }
49
34
  `;
50
35
  if (app.env.isDev) {
51
36
  content += HMR_CODE;
52
37
  }
53
- await app.writeTemp(page.dataFilePathRelative, content);
54
- };
55
-
56
- // src/app/prepare/preparePagesComponents.ts
57
- var preparePagesComponents = async (app) => {
58
- const content = `import { defineAsyncComponent } from 'vue'
59
-
60
- export const pagesComponents = {${app.pages.map(
61
- ({ key, path: path9, componentFilePath, componentFileChunkName }) => `
62
- // path: ${path9}
63
- ${JSON.stringify(key)}: defineAsyncComponent(() => import(${componentFileChunkName ? `/* webpackChunkName: "${componentFileChunkName}" */` : ""}${JSON.stringify(componentFilePath)})),`
64
- ).join("")}
65
- }
66
- `;
67
- await app.writeTemp("internal/pagesComponents.js", content);
68
- };
69
-
70
- // src/app/prepare/preparePagesData.ts
71
- var preparePagesData = async (app) => {
72
- const content = `export const pagesData = {${app.pages.map(
73
- ({ key, path: path9, dataFilePath, dataFileChunkName }) => `
74
- // path: ${path9}
75
- ${JSON.stringify(key)}: () => import(${dataFileChunkName ? `/* webpackChunkName: "${dataFileChunkName}" */` : ""}${JSON.stringify(dataFilePath)}).then(({ data }) => data),`
76
- ).join("")}
77
- }
78
- `;
79
- await app.writeTemp("internal/pagesData.js", content);
80
- };
81
-
82
- // src/app/prepare/preparePagesRoutes.ts
83
- import { ensureLeadingSlash } from "@vuepress/shared";
84
- var resolvePageRouteItem = ({
85
- key,
86
- path: path9,
87
- pathInferred,
88
- filePathRelative,
89
- routeMeta
90
- }) => {
91
- const redirectsSet = /* @__PURE__ */ new Set();
92
- redirectsSet.add(decodeURI(path9));
93
- if (pathInferred !== null) {
94
- redirectsSet.add(pathInferred);
95
- redirectsSet.add(encodeURI(pathInferred));
96
- }
97
- if (filePathRelative !== null) {
98
- const filenamePath = ensureLeadingSlash(filePathRelative);
99
- redirectsSet.add(filenamePath);
100
- redirectsSet.add(encodeURI(filenamePath));
101
- }
102
- redirectsSet.delete(path9);
103
- return [
104
- key,
105
- path9,
106
- routeMeta,
107
- [...redirectsSet].map(
108
- (item) => item.replace(/\.md$/, ".html") === path9 ? ":md" : item
109
- )
110
- ];
111
- };
112
- var preparePagesRoutes = async (app) => {
113
- const routeItems = app.pages.map(resolvePageRouteItem);
114
- const content = `export const pagesRoutes = [${routeItems.map((routeItem) => `
115
- ${JSON.stringify(routeItem)},`).join("")}
116
- ]
117
- `;
118
- await app.writeTemp("internal/pagesRoutes.js", content);
119
- };
120
-
121
- // src/app/prepare/prepareSiteData.ts
122
- var HMR_CODE2 = `
123
- if (import.meta.webpackHot) {
124
- import.meta.webpackHot.accept()
125
- if (__VUE_HMR_RUNTIME__.updateSiteData) {
126
- __VUE_HMR_RUNTIME__.updateSiteData(siteData)
127
- }
128
- }
129
-
130
- if (import.meta.hot) {
131
- import.meta.hot.accept(({ siteData }) => {
132
- __VUE_HMR_RUNTIME__.updateSiteData(siteData)
133
- })
134
- }
135
- `;
136
- var prepareSiteData = async (app) => {
137
- let content = `export const siteData = JSON.parse(${JSON.stringify(
138
- JSON.stringify(app.siteData)
139
- )})
140
- `;
141
- if (app.env.isDev) {
142
- content += HMR_CODE2;
143
- }
144
- await app.writeTemp("internal/siteData.js", content);
145
- };
146
-
147
- // src/app/appInit.ts
148
- import { debug as debug3 } from "@vuepress/utils";
149
-
150
- // src/app/resolveAppMarkdown.ts
151
- import { createMarkdown } from "@vuepress/markdown";
152
- var resolveAppMarkdown = async (app) => {
153
- await app.pluginApi.hooks.extendsMarkdownOptions.process(
154
- app.options.markdown,
155
- app
156
- );
157
- const markdown = createMarkdown(app.options.markdown);
158
- await app.pluginApi.hooks.extendsMarkdown.process(markdown, app);
159
- return markdown;
38
+ await app.writeTemp(page.chunkFilePathRelative, content);
160
39
  };
161
40
 
162
- // src/app/resolveAppPages.ts
163
- import { debug as debug2, globby } from "@vuepress/utils";
164
-
165
41
  // src/page/inferPagePath.ts
166
- import { ensureLeadingSlash as ensureLeadingSlash2, resolveLocalePath } from "@vuepress/shared";
42
+ import {
43
+ ensureLeadingSlash,
44
+ inferRoutePath,
45
+ resolveLocalePath
46
+ } from "@vuepress/shared";
167
47
  var inferPagePath = ({
168
48
  app,
169
49
  filePathRelative
@@ -174,7 +54,7 @@ var inferPagePath = ({
174
54
  pathLocale: "/"
175
55
  };
176
56
  }
177
- const pathInferred = ensureLeadingSlash2(filePathRelative).replace(/\.md$/, ".html").replace(/\/(README|index).html$/i, "/");
57
+ const pathInferred = inferRoutePath(ensureLeadingSlash(filePathRelative));
178
58
  const pathLocale = resolveLocalePath(app.siteData.locales, pathInferred);
179
59
  return {
180
60
  pathInferred,
@@ -182,9 +62,9 @@ var inferPagePath = ({
182
62
  };
183
63
  };
184
64
 
185
- // src/page/renderPageContent.ts
65
+ // src/page/parsePageContent.ts
186
66
  import { omit } from "@vuepress/shared";
187
- var renderPageContent = ({
67
+ var parsePageContent = ({
188
68
  app,
189
69
  content,
190
70
  filePath,
@@ -229,49 +109,69 @@ var renderPageContent = ({
229
109
  "frontmatter"
230
110
  ),
231
111
  sfcBlocks,
112
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-template-expression -- the title from frontmatter is not guaranteed to be a string
232
113
  title: frontmatter.title ? `${frontmatter.title}` : title
233
114
  };
234
115
  };
235
116
 
117
+ // src/page/resolvePageChunkInfo.ts
118
+ import { path, transformPathToFileName } from "@vuepress/utils";
119
+ var resolvePageChunkInfo = ({
120
+ app,
121
+ htmlFilePathRelative
122
+ }) => {
123
+ const chunkFilePathRelative = path.join("pages", `${htmlFilePathRelative}.js`);
124
+ const chunkFilePath = app.dir.temp(chunkFilePathRelative);
125
+ const chunkName = transformPathToFileName(htmlFilePathRelative);
126
+ return {
127
+ chunkFilePath,
128
+ chunkFilePathRelative,
129
+ chunkName
130
+ };
131
+ };
132
+
236
133
  // src/page/resolvePageComponentInfo.ts
237
- import { path } from "@vuepress/utils";
238
- var resolvePageComponentInfo = async ({
134
+ import { path as path2 } from "@vuepress/utils";
135
+ var resolvePageComponentInfo = ({
239
136
  app,
240
- htmlFilePathRelative,
241
- key
137
+ htmlFilePathRelative
242
138
  }) => {
243
- const componentFilePathRelative = path.join(
139
+ const componentFilePathRelative = path2.join(
244
140
  "pages",
245
141
  `${htmlFilePathRelative}.vue`
246
142
  );
247
143
  const componentFilePath = app.dir.temp(componentFilePathRelative);
248
- const componentFileChunkName = key;
249
144
  return {
250
145
  componentFilePath,
251
- componentFilePathRelative,
252
- componentFileChunkName
146
+ componentFilePathRelative
253
147
  };
254
148
  };
255
149
 
256
- // src/page/resolvePageDataInfo.ts
257
- import { path as path2 } from "@vuepress/utils";
258
- var resolvePageDataInfo = ({
259
- app,
260
- htmlFilePathRelative,
261
- key
150
+ // src/page/resolvePageContent.ts
151
+ import { isString } from "@vuepress/shared";
152
+ import { debug, fs } from "@vuepress/utils";
153
+ var log = debug("vuepress:core/page");
154
+ var FALLBACK_CONTENT = "";
155
+ var resolvePageContent = async ({
156
+ filePath,
157
+ options
262
158
  }) => {
263
- const dataFilePathRelative = path2.join("pages", `${htmlFilePathRelative}.js`);
264
- const dataFilePath = app.dir.temp(dataFilePathRelative);
265
- const dataFileChunkName = key;
266
- return {
267
- dataFilePath,
268
- dataFilePathRelative,
269
- dataFileChunkName
270
- };
159
+ if (isString(options.content)) {
160
+ return options.content;
161
+ }
162
+ if (filePath) {
163
+ try {
164
+ const content = await fs.readFile(filePath, "utf-8");
165
+ return content;
166
+ } catch (e) {
167
+ log(e instanceof Error ? e.message : e);
168
+ }
169
+ }
170
+ return FALLBACK_CONTENT;
271
171
  };
272
172
 
273
173
  // src/page/resolvePageDate.ts
274
- import { formatDateString, isString } from "@vuepress/shared";
174
+ import { formatDateString, isString as isString2 } from "@vuepress/shared";
275
175
  import { path as path3 } from "@vuepress/utils";
276
176
  var FILENAME_DATE_RE = /^(\d{4})-(\d{1,2})(?:-(\d{1,2}))?-(.*)$/;
277
177
  var DIRNAME_DATE_RE = /(\d{4})\/(\d{1,2})(?:\/(\d{1,2}))?(\/|$)/;
@@ -290,7 +190,7 @@ var resolvePageDate = ({
290
190
  DEFAULT_DATE
291
191
  );
292
192
  }
293
- if (isString(frontmatter.date)) {
193
+ if (isString2(frontmatter.date)) {
294
194
  return formatDateString(frontmatter.date, DEFAULT_DATE);
295
195
  }
296
196
  if (filePathRelative === null) {
@@ -301,6 +201,7 @@ var resolvePageDate = ({
301
201
  const matches = filename.match(FILENAME_DATE_RE);
302
202
  if (matches) {
303
203
  return formatDateString(
204
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- unsafe indexed access
304
205
  `${matches[1]}-${matches[2]}-${matches[3] ?? "01"}`,
305
206
  DEFAULT_DATE
306
207
  );
@@ -311,6 +212,7 @@ var resolvePageDate = ({
311
212
  const matches = dirname.match(DIRNAME_DATE_RE);
312
213
  if (matches) {
313
214
  return formatDateString(
215
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- unsafe indexed access
314
216
  `${matches[1]}-${matches[2]}-${matches[3] ?? "01"}`,
315
217
  DEFAULT_DATE
316
218
  );
@@ -319,24 +221,6 @@ var resolvePageDate = ({
319
221
  return DEFAULT_DATE;
320
222
  };
321
223
 
322
- // src/page/resolvePageFileContent.ts
323
- import { debug, fs } from "@vuepress/utils";
324
- var log = debug("vuepress:core/page");
325
- var resolvePageFileContent = async ({
326
- filePath,
327
- options
328
- }) => {
329
- if (filePath) {
330
- try {
331
- const content = await fs.readFile(filePath, "utf-8");
332
- return content;
333
- } catch (e) {
334
- log(e instanceof Error ? e.message : e);
335
- }
336
- }
337
- return options.content ?? "";
338
- };
339
-
340
224
  // src/page/resolvePageFilePath.ts
341
225
  import { logger, path as path4 } from "@vuepress/utils";
342
226
  var resolvePageFilePath = ({
@@ -366,8 +250,9 @@ var resolvePageHtmlInfo = ({
366
250
  app,
367
251
  path: pagePath
368
252
  }) => {
253
+ const path9 = decodeURI(pagePath);
369
254
  const htmlFilePathRelative = removeLeadingSlash(
370
- decodeURI(pagePath.replace(/\/$/, "/index.html"))
255
+ path9.endsWith("/") ? `${path9}index.html` : path9.endsWith(".html") ? path9 : `${path9}.html`
371
256
  );
372
257
  const htmlFilePath = app.dir.dest(htmlFilePathRelative);
373
258
  return {
@@ -376,45 +261,37 @@ var resolvePageHtmlInfo = ({
376
261
  };
377
262
  };
378
263
 
379
- // src/page/resolvePageKey.ts
380
- import { hash } from "@vuepress/utils";
381
- var resolvePageKey = ({ path: path9 }) => `v-${hash(path9)}`;
382
-
383
264
  // src/page/resolvePageLang.ts
384
- import { isString as isString2 } from "@vuepress/shared";
265
+ import { isString as isString3 } from "@vuepress/shared";
385
266
  var resolvePageLang = ({
386
267
  app,
387
268
  frontmatter,
388
269
  pathLocale
389
270
  }) => {
390
- if (isString2(frontmatter.lang) && frontmatter.lang) {
271
+ if (isString3(frontmatter.lang) && frontmatter.lang) {
391
272
  return frontmatter.lang;
392
273
  }
393
274
  return app.siteData.locales[pathLocale]?.lang ?? app.siteData.lang;
394
275
  };
395
276
 
396
277
  // src/page/resolvePagePath.ts
397
- import { ensureEndingSlash } from "@vuepress/shared";
398
278
  import { logger as logger2, sanitizeFileName } from "@vuepress/utils";
399
279
  var resolvePagePath = ({
400
280
  permalink,
401
281
  pathInferred,
402
282
  options
403
283
  }) => {
404
- let pagePath = options.path || permalink || pathInferred;
284
+ const pagePath = options.path || permalink || pathInferred;
405
285
  if (!pagePath) {
406
286
  throw logger2.createError(
407
287
  `page path is empty, page options: ${JSON.stringify(options, null, 2)}`
408
288
  );
409
289
  }
410
- if (!pagePath.endsWith(".html")) {
411
- pagePath = ensureEndingSlash(pagePath);
412
- }
413
290
  return encodeURI(pagePath.split("/").map(sanitizeFileName).join("/"));
414
291
  };
415
292
 
416
293
  // src/page/resolvePagePermalink.ts
417
- import { ensureLeadingSlash as ensureLeadingSlash3, isString as isString3 } from "@vuepress/shared";
294
+ import { ensureLeadingSlash as ensureLeadingSlash2, isString as isString4 } from "@vuepress/shared";
418
295
  import { path as path5 } from "@vuepress/utils";
419
296
  var resolvePagePermalink = ({
420
297
  app,
@@ -424,11 +301,17 @@ var resolvePagePermalink = ({
424
301
  pathInferred,
425
302
  pathLocale
426
303
  }) => {
427
- if (isString3(frontmatter.permalink)) {
304
+ if (frontmatter.permalink === null) {
305
+ return null;
306
+ }
307
+ if (isString4(frontmatter.permalink)) {
428
308
  return frontmatter.permalink;
429
309
  }
430
- const permalinkPattern = getPermalinkPattern({ app, frontmatter });
431
- if (permalinkPattern === null) {
310
+ if (frontmatter.permalinkPattern === null) {
311
+ return null;
312
+ }
313
+ const permalinkPattern = frontmatter.permalinkPattern || app.options.permalinkPattern;
314
+ if (!isString4(permalinkPattern)) {
432
315
  return null;
433
316
  }
434
317
  const [year, month, day] = date.split("-");
@@ -436,19 +319,7 @@ var resolvePagePermalink = ({
436
319
  pathLocale,
437
320
  permalinkPattern.replace(/:year/, year).replace(/:month/, month).replace(/:day/, day).replace(/:slug/, slug).replace(/:raw/, pathInferred?.replace(/^\//, "") ?? "")
438
321
  );
439
- return ensureLeadingSlash3(link);
440
- };
441
- var getPermalinkPattern = ({
442
- app,
443
- frontmatter
444
- }) => {
445
- if (frontmatter.permalinkPattern === null) {
446
- return null;
447
- }
448
- if (isString3(frontmatter.permalinkPattern)) {
449
- return frontmatter.permalinkPattern;
450
- }
451
- return app.options.permalinkPattern;
322
+ return ensureLeadingSlash2(link);
452
323
  };
453
324
 
454
325
  // src/page/resolvePageRouteMeta.ts
@@ -477,7 +348,7 @@ var createPage = async (app, options) => {
477
348
  app,
478
349
  options
479
350
  });
480
- const content = await resolvePageFileContent({ filePath, options });
351
+ const content = await resolvePageContent({ filePath, options });
481
352
  const {
482
353
  contentRendered,
483
354
  deps,
@@ -487,7 +358,7 @@ var createPage = async (app, options) => {
487
358
  markdownEnv,
488
359
  sfcBlocks,
489
360
  title
490
- } = renderPageContent({
361
+ } = parsePageContent({
491
362
  app,
492
363
  content,
493
364
  filePath,
@@ -508,33 +379,24 @@ var createPage = async (app, options) => {
508
379
  pathLocale
509
380
  });
510
381
  const path9 = resolvePagePath({ permalink, pathInferred, options });
511
- const key = resolvePageKey({ path: path9 });
512
382
  const { htmlFilePath, htmlFilePathRelative } = resolvePageHtmlInfo({
513
383
  app,
514
384
  path: path9
515
385
  });
516
- const {
517
- componentFilePath,
518
- componentFilePathRelative,
519
- componentFileChunkName
520
- } = await resolvePageComponentInfo({
386
+ const { componentFilePath, componentFilePathRelative } = resolvePageComponentInfo({
521
387
  app,
522
- htmlFilePathRelative,
523
- key
388
+ htmlFilePathRelative
524
389
  });
525
- const { dataFilePath, dataFilePathRelative, dataFileChunkName } = resolvePageDataInfo({ app, htmlFilePathRelative, key });
390
+ const { chunkFilePath, chunkFilePathRelative, chunkName } = resolvePageChunkInfo({ app, htmlFilePathRelative });
526
391
  const page = {
527
392
  // page data
528
393
  data: {
529
- key,
530
394
  path: path9,
531
395
  title,
532
396
  lang,
533
- frontmatter,
534
- headers
397
+ frontmatter
535
398
  },
536
399
  // base fields
537
- key,
538
400
  path: path9,
539
401
  title,
540
402
  lang,
@@ -558,10 +420,9 @@ var createPage = async (app, options) => {
558
420
  filePathRelative,
559
421
  componentFilePath,
560
422
  componentFilePathRelative,
561
- componentFileChunkName,
562
- dataFilePath,
563
- dataFilePathRelative,
564
- dataFileChunkName,
423
+ chunkFilePath,
424
+ chunkFilePathRelative,
425
+ chunkName,
565
426
  htmlFilePath,
566
427
  htmlFilePathRelative
567
428
  };
@@ -569,7 +430,123 @@ var createPage = async (app, options) => {
569
430
  return page;
570
431
  };
571
432
 
433
+ // src/page/renderPageSfcBlocksToVue.ts
434
+ var renderPageSfcBlocksToVue = (sfcBlocks) => [
435
+ // #688: wrap the content of `<template>` with a `<div>` to avoid some potential issues of fragment component
436
+ `${sfcBlocks.template?.tagOpen}<div>${sfcBlocks.template?.contentStripped}</div>${sfcBlocks.template?.tagClose}
437
+ `,
438
+ // hoist `<script>`, `<style>` and other custom blocks
439
+ sfcBlocks.script?.content,
440
+ sfcBlocks.scriptSetup?.content,
441
+ ...sfcBlocks.styles.map((item) => item.content),
442
+ ...sfcBlocks.customBlocks.map((item) => item.content)
443
+ ].join("\n");
444
+
445
+ // src/app/prepare/preparePageComponent.ts
446
+ var preparePageComponent = async (app, page) => {
447
+ await app.writeTemp(
448
+ page.componentFilePathRelative,
449
+ renderPageSfcBlocksToVue(page.sfcBlocks)
450
+ );
451
+ };
452
+
453
+ // src/app/prepare/prepareRoutes.ts
454
+ import { normalizeRoutePath } from "@vuepress/shared";
455
+ var HMR_CODE2 = `
456
+ if (import.meta.webpackHot) {
457
+ import.meta.webpackHot.accept()
458
+ if (__VUE_HMR_RUNTIME__.updateRoutes) {
459
+ __VUE_HMR_RUNTIME__.updateRoutes(routes)
460
+ }
461
+ if (__VUE_HMR_RUNTIME__.updateRedirects) {
462
+ __VUE_HMR_RUNTIME__.updateRedirects(redirects)
463
+ }
464
+ }
465
+
466
+ if (import.meta.hot) {
467
+ import.meta.hot.accept(({ routes, redirects }) => {
468
+ __VUE_HMR_RUNTIME__.updateRoutes(routes)
469
+ __VUE_HMR_RUNTIME__.updateRedirects(redirects)
470
+ })
471
+ }
472
+ `;
473
+ var resolvePageRedirects = ({ path: path9, pathInferred }) => {
474
+ const redirectsSet = /* @__PURE__ */ new Set();
475
+ if (pathInferred !== null) {
476
+ const normalizedPathInferred = normalizeRoutePath(pathInferred);
477
+ const encodedPathInferred = encodeURI(normalizedPathInferred);
478
+ if (normalizedPathInferred !== path9 && encodedPathInferred !== path9) {
479
+ redirectsSet.add(encodedPathInferred);
480
+ }
481
+ }
482
+ return Array.from(redirectsSet);
483
+ };
484
+ var prepareRoutes = async (app) => {
485
+ let content = `export const redirects = JSON.parse(${JSON.stringify(
486
+ JSON.stringify(
487
+ Object.fromEntries(
488
+ app.pages.flatMap(
489
+ (page) => resolvePageRedirects(page).map((redirect) => [redirect, page.path])
490
+ )
491
+ )
492
+ )
493
+ )})
494
+
495
+ export const routes = Object.fromEntries([
496
+ ${app.pages.map(
497
+ ({ chunkFilePath, chunkName, path: path9, routeMeta }) => ` [${JSON.stringify(path9)}, { loader: () => import(${chunkName ? `/* webpackChunkName: "${chunkName}" */` : ""}${JSON.stringify(chunkFilePath)}), meta: ${JSON.stringify(routeMeta)} }],`
498
+ ).join("\n")}
499
+ ]);
500
+ `;
501
+ if (app.env.isDev) {
502
+ content += HMR_CODE2;
503
+ }
504
+ await app.writeTemp("internal/routes.js", content);
505
+ };
506
+
507
+ // src/app/prepare/prepareSiteData.ts
508
+ var HMR_CODE3 = `
509
+ if (import.meta.webpackHot) {
510
+ import.meta.webpackHot.accept()
511
+ if (__VUE_HMR_RUNTIME__.updateSiteData) {
512
+ __VUE_HMR_RUNTIME__.updateSiteData(siteData)
513
+ }
514
+ }
515
+
516
+ if (import.meta.hot) {
517
+ import.meta.hot.accept(({ siteData }) => {
518
+ __VUE_HMR_RUNTIME__.updateSiteData(siteData)
519
+ })
520
+ }
521
+ `;
522
+ var prepareSiteData = async (app) => {
523
+ let content = `export const siteData = JSON.parse(${JSON.stringify(
524
+ JSON.stringify(app.siteData)
525
+ )})
526
+ `;
527
+ if (app.env.isDev) {
528
+ content += HMR_CODE3;
529
+ }
530
+ await app.writeTemp("internal/siteData.js", content);
531
+ };
532
+
533
+ // src/app/appInit.ts
534
+ import { debug as debug3 } from "@vuepress/utils";
535
+
536
+ // src/app/resolveAppMarkdown.ts
537
+ import { createMarkdown } from "@vuepress/markdown";
538
+ var resolveAppMarkdown = async (app) => {
539
+ await app.pluginApi.hooks.extendsMarkdownOptions.process(
540
+ app.options.markdown,
541
+ app
542
+ );
543
+ const markdown = createMarkdown(app.options.markdown);
544
+ await app.pluginApi.hooks.extendsMarkdown.process(markdown, app);
545
+ return markdown;
546
+ };
547
+
572
548
  // src/app/resolveAppPages.ts
549
+ import { debug as debug2, globby } from "@vuepress/utils";
573
550
  var log2 = debug2("vuepress:core/app");
574
551
  var resolveAppPages = async (app) => {
575
552
  log2("resolveAppPages start");
@@ -577,16 +554,23 @@ var resolveAppPages = async (app) => {
577
554
  absolute: true,
578
555
  cwd: app.dir.source()
579
556
  });
557
+ let hasNotFoundPage = false;
580
558
  const pages = await Promise.all(
581
- pageFilePaths.map((filePath) => createPage(app, { filePath }))
559
+ pageFilePaths.map(async (filePath) => {
560
+ const page = await createPage(app, { filePath });
561
+ if (page.path === "/404.html") {
562
+ page.frontmatter.layout ??= "NotFound";
563
+ hasNotFoundPage = true;
564
+ }
565
+ return page;
566
+ })
582
567
  );
583
- if (!pages.some((page) => page.path === "/404.html")) {
568
+ if (!hasNotFoundPage) {
584
569
  pages.push(
585
570
  await createPage(app, {
586
571
  path: "/404.html",
587
- frontmatter: {
588
- layout: "NotFound"
589
- }
572
+ frontmatter: { layout: "NotFound" },
573
+ content: "404 Not Found"
590
574
  })
591
575
  );
592
576
  }
@@ -610,17 +594,15 @@ import { debug as debug4 } from "@vuepress/utils";
610
594
  var log4 = debug4("vuepress:core/app");
611
595
  var appPrepare = async (app) => {
612
596
  log4("prepare start");
613
- for (const page of app.pages) {
614
- await preparePageComponent(app, page);
615
- }
616
- await preparePagesComponents(app);
617
- for (const page of app.pages) {
618
- await preparePageData(app, page);
619
- }
620
- await preparePagesData(app);
621
- await preparePagesRoutes(app);
622
- await prepareSiteData(app);
623
- await prepareClientConfigs(app);
597
+ await Promise.all([
598
+ ...app.pages.flatMap((page) => [
599
+ preparePageComponent(app, page),
600
+ preparePageChunk(app, page)
601
+ ]),
602
+ prepareRoutes(app),
603
+ prepareSiteData(app),
604
+ prepareClientConfigs(app)
605
+ ]);
624
606
  await app.pluginApi.hooks.onPrepared.process(app);
625
607
  log4("prepare finish");
626
608
  };
@@ -768,6 +750,7 @@ var createPluginApiRegisterHooks = (plugins, hooks) => () => {
768
750
  if (hooks[key] && commonHooks[key]) {
769
751
  hooks[key].add({
770
752
  pluginName,
753
+ // @ts-expect-error: the type could not be narrowed correctly
771
754
  hook: commonHooks[key]
772
755
  });
773
756
  }
@@ -789,12 +772,10 @@ var createPluginApi = () => {
789
772
  };
790
773
 
791
774
  // src/app/resolveAppDir.ts
792
- import { createRequire } from "module";
775
+ import { createRequire } from "node:module";
793
776
  import { path as path7 } from "@vuepress/utils";
794
777
  var require2 = createRequire(import.meta.url);
795
- var createAppDirFunction = (baseDir) => {
796
- return (...args) => path7.resolve(baseDir, ...args);
797
- };
778
+ var createAppDirFunction = (baseDir) => (...args) => path7.resolve(baseDir, ...args);
798
779
  var resolveAppDir = (options) => {
799
780
  const cache = createAppDirFunction(options.cache);
800
781
  const temp = createAppDirFunction(options.temp);
@@ -815,14 +796,14 @@ var resolveAppDir = (options) => {
815
796
  };
816
797
 
817
798
  // src/app/resolveAppEnv.ts
818
- var resolveAppEnv = (options, isBuild) => ({
819
- isBuild,
820
- isDev: !isBuild,
799
+ var resolveAppEnv = (options) => ({
800
+ isBuild: false,
801
+ isDev: false,
821
802
  isDebug: options.debug
822
803
  });
823
804
 
824
805
  // src/app/resolveAppOptions.ts
825
- import { createRequire as createRequire2 } from "module";
806
+ import { createRequire as createRequire2 } from "node:module";
826
807
  import { path as path8, templateRenderer } from "@vuepress/utils";
827
808
  var require3 = createRequire2(import.meta.url);
828
809
  var resolveAppOptions = ({
@@ -852,6 +833,7 @@ var resolveAppOptions = ({
852
833
  templateBuild = path8.normalize(
853
834
  require3.resolve("@vuepress/client/templates/build.html")
854
835
  ),
836
+ templateBuildRenderer = templateRenderer,
855
837
  // common config
856
838
  bundler,
857
839
  debug: debug7 = false,
@@ -879,7 +861,7 @@ var resolveAppOptions = ({
879
861
  shouldPreload,
880
862
  shouldPrefetch,
881
863
  templateBuild,
882
- templateBuildRenderer: templateRenderer,
864
+ templateBuildRenderer,
883
865
  bundler,
884
866
  debug: debug7,
885
867
  markdown,
@@ -900,7 +882,7 @@ var resolveAppSiteData = (options) => ({
900
882
  });
901
883
 
902
884
  // src/app/resolveAppVersion.ts
903
- import { createRequire as createRequire3 } from "module";
885
+ import { createRequire as createRequire3 } from "node:module";
904
886
  import { fs as fs3 } from "@vuepress/utils";
905
887
  var require4 = createRequire3(import.meta.url);
906
888
  var resolveAppVersion = () => {
@@ -921,6 +903,32 @@ var resolveAppWriteTemp = (dir) => {
921
903
  return writeTemp;
922
904
  };
923
905
 
906
+ // src/app/createBaseApp.ts
907
+ var createBaseApp = (config) => {
908
+ const options = resolveAppOptions(config);
909
+ const dir = resolveAppDir(options);
910
+ const env = resolveAppEnv(options);
911
+ const pluginApi = createPluginApi();
912
+ const siteData = resolveAppSiteData(options);
913
+ const version = resolveAppVersion();
914
+ const writeTemp = resolveAppWriteTemp(dir);
915
+ const app = {
916
+ options,
917
+ siteData,
918
+ version,
919
+ // utils
920
+ dir,
921
+ env,
922
+ pluginApi,
923
+ writeTemp,
924
+ // methods
925
+ use: (plugin) => appUse(app, plugin),
926
+ init: async () => appInit(app),
927
+ prepare: async () => appPrepare(app)
928
+ };
929
+ return app;
930
+ };
931
+
924
932
  // src/app/resolveThemeInfo.ts
925
933
  var resolveThemeInfo = (app, theme) => {
926
934
  const themeObject = resolvePluginObject(app, theme);
@@ -951,44 +959,21 @@ var setupAppThemeAndPlugins = (app, config) => {
951
959
  [...themeInfo.plugins, ...app.options.plugins].flat().forEach((plugin) => app.use(plugin));
952
960
  };
953
961
 
954
- // src/app/createBaseApp.ts
955
- var createBaseApp = (config, isBuild = false) => {
956
- const options = resolveAppOptions(config);
957
- const dir = resolveAppDir(options);
958
- const env = resolveAppEnv(options, isBuild);
959
- const pluginApi = createPluginApi();
960
- const siteData = resolveAppSiteData(options);
961
- const version = resolveAppVersion();
962
- const writeTemp = resolveAppWriteTemp(dir);
963
- const app = {
964
- options,
965
- siteData,
966
- version,
967
- // utils
968
- dir,
969
- env,
970
- pluginApi,
971
- writeTemp,
972
- // methods
973
- use: (plugin) => appUse(app, plugin),
974
- init: () => appInit(app),
975
- prepare: () => appPrepare(app)
976
- };
977
- setupAppThemeAndPlugins(app, config);
978
- return app;
979
- };
980
-
981
962
  // src/app/createBuildApp.ts
982
963
  var createBuildApp = (config) => {
983
- const app = createBaseApp(config, true);
984
- app.build = () => app.options.bundler.build(app);
964
+ const app = createBaseApp(config);
965
+ app.env.isBuild = true;
966
+ app.build = async () => app.options.bundler.build(app);
967
+ setupAppThemeAndPlugins(app, config);
985
968
  return app;
986
969
  };
987
970
 
988
971
  // src/app/createDevApp.ts
989
972
  var createDevApp = (config) => {
990
- const app = createBaseApp(config, false);
991
- app.dev = () => app.options.bundler.dev(app);
973
+ const app = createBaseApp(config);
974
+ app.env.isDev = true;
975
+ app.dev = async () => app.options.bundler.dev(app);
976
+ setupAppThemeAndPlugins(app, config);
992
977
  return app;
993
978
  };
994
979
  export {
@@ -1007,14 +992,13 @@ export {
1007
992
  inferPagePath,
1008
993
  normalizeAliasDefineHook,
1009
994
  normalizeClientConfigFileHook,
995
+ parsePageContent,
1010
996
  prepareClientConfigs,
997
+ preparePageChunk,
1011
998
  preparePageComponent,
1012
- preparePageData,
1013
- preparePagesComponents,
1014
- preparePagesData,
1015
- preparePagesRoutes,
999
+ prepareRoutes,
1016
1000
  prepareSiteData,
1017
- renderPageContent,
1001
+ renderPageSfcBlocksToVue,
1018
1002
  resolveAppDir,
1019
1003
  resolveAppEnv,
1020
1004
  resolveAppOptions,
@@ -1022,13 +1006,12 @@ export {
1022
1006
  resolveAppSiteData,
1023
1007
  resolveAppVersion,
1024
1008
  resolveAppWriteTemp,
1009
+ resolvePageChunkInfo,
1025
1010
  resolvePageComponentInfo,
1026
- resolvePageDataInfo,
1011
+ resolvePageContent,
1027
1012
  resolvePageDate,
1028
- resolvePageFileContent,
1029
1013
  resolvePageFilePath,
1030
1014
  resolvePageHtmlInfo,
1031
- resolvePageKey,
1032
1015
  resolvePageLang,
1033
1016
  resolvePagePath,
1034
1017
  resolvePagePermalink,