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

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,25 +379,18 @@ 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,
@@ -534,7 +398,6 @@ var createPage = async (app, options) => {
534
398
  headers
535
399
  },
536
400
  // base fields
537
- key,
538
401
  path: path9,
539
402
  title,
540
403
  lang,
@@ -558,10 +421,9 @@ var createPage = async (app, options) => {
558
421
  filePathRelative,
559
422
  componentFilePath,
560
423
  componentFilePathRelative,
561
- componentFileChunkName,
562
- dataFilePath,
563
- dataFilePathRelative,
564
- dataFileChunkName,
424
+ chunkFilePath,
425
+ chunkFilePathRelative,
426
+ chunkName,
565
427
  htmlFilePath,
566
428
  htmlFilePathRelative
567
429
  };
@@ -569,7 +431,123 @@ var createPage = async (app, options) => {
569
431
  return page;
570
432
  };
571
433
 
434
+ // src/page/renderPageSfcBlocksToVue.ts
435
+ var renderPageSfcBlocksToVue = (sfcBlocks) => [
436
+ // #688: wrap the content of `<template>` with a `<div>` to avoid some potential issues of fragment component
437
+ `${sfcBlocks.template?.tagOpen}<div>${sfcBlocks.template?.contentStripped}</div>${sfcBlocks.template?.tagClose}
438
+ `,
439
+ // hoist `<script>`, `<style>` and other custom blocks
440
+ sfcBlocks.script?.content,
441
+ sfcBlocks.scriptSetup?.content,
442
+ ...sfcBlocks.styles.map((item) => item.content),
443
+ ...sfcBlocks.customBlocks.map((item) => item.content)
444
+ ].join("\n");
445
+
446
+ // src/app/prepare/preparePageComponent.ts
447
+ var preparePageComponent = async (app, page) => {
448
+ await app.writeTemp(
449
+ page.componentFilePathRelative,
450
+ renderPageSfcBlocksToVue(page.sfcBlocks)
451
+ );
452
+ };
453
+
454
+ // src/app/prepare/prepareRoutes.ts
455
+ import { normalizeRoutePath } from "@vuepress/shared";
456
+ var HMR_CODE2 = `
457
+ if (import.meta.webpackHot) {
458
+ import.meta.webpackHot.accept()
459
+ if (__VUE_HMR_RUNTIME__.updateRoutes) {
460
+ __VUE_HMR_RUNTIME__.updateRoutes(routes)
461
+ }
462
+ if (__VUE_HMR_RUNTIME__.updateRedirects) {
463
+ __VUE_HMR_RUNTIME__.updateRedirects(redirects)
464
+ }
465
+ }
466
+
467
+ if (import.meta.hot) {
468
+ import.meta.hot.accept(({ routes, redirects }) => {
469
+ __VUE_HMR_RUNTIME__.updateRoutes(routes)
470
+ __VUE_HMR_RUNTIME__.updateRedirects(redirects)
471
+ })
472
+ }
473
+ `;
474
+ var resolvePageRedirects = ({ path: path9, pathInferred }) => {
475
+ const redirectsSet = /* @__PURE__ */ new Set();
476
+ if (pathInferred !== null) {
477
+ const normalizedPathInferred = normalizeRoutePath(pathInferred);
478
+ const encodedPathInferred = encodeURI(normalizedPathInferred);
479
+ if (normalizedPathInferred !== path9 && encodedPathInferred !== path9) {
480
+ redirectsSet.add(encodedPathInferred);
481
+ }
482
+ }
483
+ return Array.from(redirectsSet);
484
+ };
485
+ var prepareRoutes = async (app) => {
486
+ let content = `export const redirects = JSON.parse(${JSON.stringify(
487
+ JSON.stringify(
488
+ Object.fromEntries(
489
+ app.pages.flatMap(
490
+ (page) => resolvePageRedirects(page).map((redirect) => [redirect, page.path])
491
+ )
492
+ )
493
+ )
494
+ )})
495
+
496
+ export const routes = Object.fromEntries([
497
+ ${app.pages.map(
498
+ ({ chunkFilePath, chunkName, path: path9, routeMeta }) => ` [${JSON.stringify(path9)}, { loader: () => import(${chunkName ? `/* webpackChunkName: "${chunkName}" */` : ""}${JSON.stringify(chunkFilePath)}), meta: ${JSON.stringify(routeMeta)} }],`
499
+ ).join("\n")}
500
+ ]);
501
+ `;
502
+ if (app.env.isDev) {
503
+ content += HMR_CODE2;
504
+ }
505
+ await app.writeTemp("internal/routes.js", content);
506
+ };
507
+
508
+ // src/app/prepare/prepareSiteData.ts
509
+ var HMR_CODE3 = `
510
+ if (import.meta.webpackHot) {
511
+ import.meta.webpackHot.accept()
512
+ if (__VUE_HMR_RUNTIME__.updateSiteData) {
513
+ __VUE_HMR_RUNTIME__.updateSiteData(siteData)
514
+ }
515
+ }
516
+
517
+ if (import.meta.hot) {
518
+ import.meta.hot.accept(({ siteData }) => {
519
+ __VUE_HMR_RUNTIME__.updateSiteData(siteData)
520
+ })
521
+ }
522
+ `;
523
+ var prepareSiteData = async (app) => {
524
+ let content = `export const siteData = JSON.parse(${JSON.stringify(
525
+ JSON.stringify(app.siteData)
526
+ )})
527
+ `;
528
+ if (app.env.isDev) {
529
+ content += HMR_CODE3;
530
+ }
531
+ await app.writeTemp("internal/siteData.js", content);
532
+ };
533
+
534
+ // src/app/appInit.ts
535
+ import { debug as debug3 } from "@vuepress/utils";
536
+
537
+ // src/app/resolveAppMarkdown.ts
538
+ import { createMarkdown } from "@vuepress/markdown";
539
+ var resolveAppMarkdown = async (app) => {
540
+ await app.pluginApi.hooks.extendsMarkdownOptions.process(
541
+ app.options.markdown,
542
+ app
543
+ );
544
+ const markdown = createMarkdown(app.options.markdown);
545
+ await app.pluginApi.hooks.extendsMarkdown.process(markdown, app);
546
+ return markdown;
547
+ };
548
+
572
549
  // src/app/resolveAppPages.ts
550
+ import { debug as debug2, globby } from "@vuepress/utils";
573
551
  var log2 = debug2("vuepress:core/app");
574
552
  var resolveAppPages = async (app) => {
575
553
  log2("resolveAppPages start");
@@ -577,16 +555,23 @@ var resolveAppPages = async (app) => {
577
555
  absolute: true,
578
556
  cwd: app.dir.source()
579
557
  });
558
+ let hasNotFoundPage = false;
580
559
  const pages = await Promise.all(
581
- pageFilePaths.map((filePath) => createPage(app, { filePath }))
560
+ pageFilePaths.map(async (filePath) => {
561
+ const page = await createPage(app, { filePath });
562
+ if (page.path === "/404.html") {
563
+ page.frontmatter.layout ??= "NotFound";
564
+ hasNotFoundPage = true;
565
+ }
566
+ return page;
567
+ })
582
568
  );
583
- if (!pages.some((page) => page.path === "/404.html")) {
569
+ if (!hasNotFoundPage) {
584
570
  pages.push(
585
571
  await createPage(app, {
586
572
  path: "/404.html",
587
- frontmatter: {
588
- layout: "NotFound"
589
- }
573
+ frontmatter: { layout: "NotFound" },
574
+ content: "404 Not Found"
590
575
  })
591
576
  );
592
577
  }
@@ -610,17 +595,15 @@ import { debug as debug4 } from "@vuepress/utils";
610
595
  var log4 = debug4("vuepress:core/app");
611
596
  var appPrepare = async (app) => {
612
597
  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);
598
+ await Promise.all([
599
+ ...app.pages.flatMap((page) => [
600
+ preparePageComponent(app, page),
601
+ preparePageChunk(app, page)
602
+ ]),
603
+ prepareRoutes(app),
604
+ prepareSiteData(app),
605
+ prepareClientConfigs(app)
606
+ ]);
624
607
  await app.pluginApi.hooks.onPrepared.process(app);
625
608
  log4("prepare finish");
626
609
  };
@@ -768,6 +751,7 @@ var createPluginApiRegisterHooks = (plugins, hooks) => () => {
768
751
  if (hooks[key] && commonHooks[key]) {
769
752
  hooks[key].add({
770
753
  pluginName,
754
+ // @ts-expect-error: the type could not be narrowed correctly
771
755
  hook: commonHooks[key]
772
756
  });
773
757
  }
@@ -789,12 +773,10 @@ var createPluginApi = () => {
789
773
  };
790
774
 
791
775
  // src/app/resolveAppDir.ts
792
- import { createRequire } from "module";
776
+ import { createRequire } from "node:module";
793
777
  import { path as path7 } from "@vuepress/utils";
794
778
  var require2 = createRequire(import.meta.url);
795
- var createAppDirFunction = (baseDir) => {
796
- return (...args) => path7.resolve(baseDir, ...args);
797
- };
779
+ var createAppDirFunction = (baseDir) => (...args) => path7.resolve(baseDir, ...args);
798
780
  var resolveAppDir = (options) => {
799
781
  const cache = createAppDirFunction(options.cache);
800
782
  const temp = createAppDirFunction(options.temp);
@@ -815,14 +797,14 @@ var resolveAppDir = (options) => {
815
797
  };
816
798
 
817
799
  // src/app/resolveAppEnv.ts
818
- var resolveAppEnv = (options, isBuild) => ({
819
- isBuild,
820
- isDev: !isBuild,
800
+ var resolveAppEnv = (options) => ({
801
+ isBuild: false,
802
+ isDev: false,
821
803
  isDebug: options.debug
822
804
  });
823
805
 
824
806
  // src/app/resolveAppOptions.ts
825
- import { createRequire as createRequire2 } from "module";
807
+ import { createRequire as createRequire2 } from "node:module";
826
808
  import { path as path8, templateRenderer } from "@vuepress/utils";
827
809
  var require3 = createRequire2(import.meta.url);
828
810
  var resolveAppOptions = ({
@@ -852,6 +834,7 @@ var resolveAppOptions = ({
852
834
  templateBuild = path8.normalize(
853
835
  require3.resolve("@vuepress/client/templates/build.html")
854
836
  ),
837
+ templateBuildRenderer = templateRenderer,
855
838
  // common config
856
839
  bundler,
857
840
  debug: debug7 = false,
@@ -879,7 +862,7 @@ var resolveAppOptions = ({
879
862
  shouldPreload,
880
863
  shouldPrefetch,
881
864
  templateBuild,
882
- templateBuildRenderer: templateRenderer,
865
+ templateBuildRenderer,
883
866
  bundler,
884
867
  debug: debug7,
885
868
  markdown,
@@ -900,7 +883,7 @@ var resolveAppSiteData = (options) => ({
900
883
  });
901
884
 
902
885
  // src/app/resolveAppVersion.ts
903
- import { createRequire as createRequire3 } from "module";
886
+ import { createRequire as createRequire3 } from "node:module";
904
887
  import { fs as fs3 } from "@vuepress/utils";
905
888
  var require4 = createRequire3(import.meta.url);
906
889
  var resolveAppVersion = () => {
@@ -921,6 +904,32 @@ var resolveAppWriteTemp = (dir) => {
921
904
  return writeTemp;
922
905
  };
923
906
 
907
+ // src/app/createBaseApp.ts
908
+ var createBaseApp = (config) => {
909
+ const options = resolveAppOptions(config);
910
+ const dir = resolveAppDir(options);
911
+ const env = resolveAppEnv(options);
912
+ const pluginApi = createPluginApi();
913
+ const siteData = resolveAppSiteData(options);
914
+ const version = resolveAppVersion();
915
+ const writeTemp = resolveAppWriteTemp(dir);
916
+ const app = {
917
+ options,
918
+ siteData,
919
+ version,
920
+ // utils
921
+ dir,
922
+ env,
923
+ pluginApi,
924
+ writeTemp,
925
+ // methods
926
+ use: (plugin) => appUse(app, plugin),
927
+ init: async () => appInit(app),
928
+ prepare: async () => appPrepare(app)
929
+ };
930
+ return app;
931
+ };
932
+
924
933
  // src/app/resolveThemeInfo.ts
925
934
  var resolveThemeInfo = (app, theme) => {
926
935
  const themeObject = resolvePluginObject(app, theme);
@@ -951,44 +960,21 @@ var setupAppThemeAndPlugins = (app, config) => {
951
960
  [...themeInfo.plugins, ...app.options.plugins].flat().forEach((plugin) => app.use(plugin));
952
961
  };
953
962
 
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
963
  // src/app/createBuildApp.ts
982
964
  var createBuildApp = (config) => {
983
- const app = createBaseApp(config, true);
984
- app.build = () => app.options.bundler.build(app);
965
+ const app = createBaseApp(config);
966
+ app.env.isBuild = true;
967
+ app.build = async () => app.options.bundler.build(app);
968
+ setupAppThemeAndPlugins(app, config);
985
969
  return app;
986
970
  };
987
971
 
988
972
  // src/app/createDevApp.ts
989
973
  var createDevApp = (config) => {
990
- const app = createBaseApp(config, false);
991
- app.dev = () => app.options.bundler.dev(app);
974
+ const app = createBaseApp(config);
975
+ app.env.isDev = true;
976
+ app.dev = async () => app.options.bundler.dev(app);
977
+ setupAppThemeAndPlugins(app, config);
992
978
  return app;
993
979
  };
994
980
  export {
@@ -1007,14 +993,13 @@ export {
1007
993
  inferPagePath,
1008
994
  normalizeAliasDefineHook,
1009
995
  normalizeClientConfigFileHook,
996
+ parsePageContent,
1010
997
  prepareClientConfigs,
998
+ preparePageChunk,
1011
999
  preparePageComponent,
1012
- preparePageData,
1013
- preparePagesComponents,
1014
- preparePagesData,
1015
- preparePagesRoutes,
1000
+ prepareRoutes,
1016
1001
  prepareSiteData,
1017
- renderPageContent,
1002
+ renderPageSfcBlocksToVue,
1018
1003
  resolveAppDir,
1019
1004
  resolveAppEnv,
1020
1005
  resolveAppOptions,
@@ -1022,13 +1007,12 @@ export {
1022
1007
  resolveAppSiteData,
1023
1008
  resolveAppVersion,
1024
1009
  resolveAppWriteTemp,
1010
+ resolvePageChunkInfo,
1025
1011
  resolvePageComponentInfo,
1026
- resolvePageDataInfo,
1012
+ resolvePageContent,
1027
1013
  resolvePageDate,
1028
- resolvePageFileContent,
1029
1014
  resolvePageFilePath,
1030
1015
  resolvePageHtmlInfo,
1031
- resolvePageKey,
1032
1016
  resolvePageLang,
1033
1017
  resolvePagePath,
1034
1018
  resolvePagePermalink,