@vuepress/core 2.0.0-beta.9 → 2.0.0-rc.1

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 (156) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +12 -0
  3. package/dist/index.d.ts +845 -0
  4. package/dist/index.js +1039 -0
  5. package/package.json +36 -19
  6. package/CHANGELOG.md +0 -338
  7. package/lib/app/appInit.d.ts +0 -7
  8. package/lib/app/appInit.js +0 -26
  9. package/lib/app/appPrepare.d.ts +0 -10
  10. package/lib/app/appPrepare.js +0 -46
  11. package/lib/app/appUse.d.ts +0 -2
  12. package/lib/app/appUse.js +0 -28
  13. package/lib/app/appUseByConfig.d.ts +0 -2
  14. package/lib/app/appUseByConfig.js +0 -11
  15. package/lib/app/createApp.d.ts +0 -5
  16. package/lib/app/createApp.js +0 -55
  17. package/lib/app/createAppDir.d.ts +0 -9
  18. package/lib/app/createAppDir.js +0 -32
  19. package/lib/app/createAppEnv.d.ts +0 -5
  20. package/lib/app/createAppEnv.js +0 -14
  21. package/lib/app/createAppOptions.d.ts +0 -5
  22. package/lib/app/createAppOptions.js +0 -47
  23. package/lib/app/createAppPages.d.ts +0 -5
  24. package/lib/app/createAppPages.js +0 -36
  25. package/lib/app/createAppSiteData.d.ts +0 -7
  26. package/lib/app/createAppSiteData.js +0 -19
  27. package/lib/app/createAppVersion.d.ts +0 -4
  28. package/lib/app/createAppVersion.js +0 -10
  29. package/lib/app/createAppWriteTemp.d.ts +0 -5
  30. package/lib/app/createAppWriteTemp.js +0 -21
  31. package/lib/app/index.d.ts +0 -16
  32. package/lib/app/index.js +0 -28
  33. package/lib/app/normalizePlugin.d.ts +0 -2
  34. package/lib/app/normalizePlugin.js +0 -17
  35. package/lib/app/normalizePluginConfig.d.ts +0 -2
  36. package/lib/app/normalizePluginConfig.js +0 -15
  37. package/lib/app/prepare/index.d.ts +0 -12
  38. package/lib/app/prepare/index.js +0 -24
  39. package/lib/app/prepare/prepareClientAppEnhances.d.ts +0 -5
  40. package/lib/app/prepare/prepareClientAppEnhances.js +0 -24
  41. package/lib/app/prepare/prepareClientAppRootComponents.d.ts +0 -5
  42. package/lib/app/prepare/prepareClientAppRootComponents.js +0 -24
  43. package/lib/app/prepare/prepareClientAppSetups.d.ts +0 -5
  44. package/lib/app/prepare/prepareClientAppSetups.js +0 -24
  45. package/lib/app/prepare/prepareLayoutComponents.d.ts +0 -5
  46. package/lib/app/prepare/prepareLayoutComponents.js +0 -20
  47. package/lib/app/prepare/preparePageComponent.d.ts +0 -5
  48. package/lib/app/prepare/preparePageComponent.js +0 -10
  49. package/lib/app/prepare/preparePageData.d.ts +0 -5
  50. package/lib/app/prepare/preparePageData.js +0 -37
  51. package/lib/app/prepare/preparePageRoutes.d.ts +0 -5
  52. package/lib/app/prepare/preparePageRoutes.js +0 -57
  53. package/lib/app/prepare/preparePagesComponent.d.ts +0 -5
  54. package/lib/app/prepare/preparePagesComponent.js +0 -23
  55. package/lib/app/prepare/preparePagesData.d.ts +0 -5
  56. package/lib/app/prepare/preparePagesData.js +0 -19
  57. package/lib/app/prepare/preparePagesRoutes.d.ts +0 -5
  58. package/lib/app/prepare/preparePagesRoutes.js +0 -25
  59. package/lib/app/prepare/prepareSiteData.d.ts +0 -5
  60. package/lib/app/prepare/prepareSiteData.js +0 -31
  61. package/lib/app/prepare/resolvePageData.d.ts +0 -5
  62. package/lib/app/prepare/resolvePageData.js +0 -18
  63. package/lib/app/resolveBundler.d.ts +0 -2
  64. package/lib/app/resolveBundler.js +0 -10
  65. package/lib/app/resolvePlugin.d.ts +0 -5
  66. package/lib/app/resolvePlugin.js +0 -20
  67. package/lib/index.d.ts +0 -5
  68. package/lib/index.js +0 -17
  69. package/lib/page/createPage.d.ts +0 -2
  70. package/lib/page/createPage.js +0 -112
  71. package/lib/page/index.d.ts +0 -18
  72. package/lib/page/index.js +0 -30
  73. package/lib/page/inferPagePath.d.ts +0 -11
  74. package/lib/page/inferPagePath.js +0 -27
  75. package/lib/page/resolvePageComponentInfo.d.ts +0 -20
  76. package/lib/page/resolvePageComponentInfo.js +0 -38
  77. package/lib/page/resolvePageContent.d.ts +0 -11
  78. package/lib/page/resolvePageContent.js +0 -30
  79. package/lib/page/resolvePageDataInfo.d.ts +0 -12
  80. package/lib/page/resolvePageDataInfo.js +0 -17
  81. package/lib/page/resolvePageDate.d.ts +0 -10
  82. package/lib/page/resolvePageDate.js +0 -46
  83. package/lib/page/resolvePageExcerpt.d.ts +0 -10
  84. package/lib/page/resolvePageExcerpt.js +0 -16
  85. package/lib/page/resolvePageFileContent.d.ts +0 -8
  86. package/lib/page/resolvePageFileContent.js +0 -24
  87. package/lib/page/resolvePageFilePath.d.ts +0 -11
  88. package/lib/page/resolvePageFilePath.js +0 -29
  89. package/lib/page/resolvePageFrontmatter.d.ts +0 -8
  90. package/lib/page/resolvePageFrontmatter.js +0 -12
  91. package/lib/page/resolvePageHtmlInfo.d.ts +0 -11
  92. package/lib/page/resolvePageHtmlInfo.js +0 -18
  93. package/lib/page/resolvePageKey.d.ts +0 -6
  94. package/lib/page/resolvePageKey.js +0 -9
  95. package/lib/page/resolvePageLang.d.ts +0 -9
  96. package/lib/page/resolvePageLang.js +0 -15
  97. package/lib/page/resolvePagePath.d.ts +0 -9
  98. package/lib/page/resolvePagePath.js +0 -19
  99. package/lib/page/resolvePagePermalink.d.ts +0 -11
  100. package/lib/page/resolvePagePermalink.js +0 -32
  101. package/lib/page/resolvePageRoutesInfo.d.ts +0 -11
  102. package/lib/page/resolvePageRoutesInfo.js +0 -15
  103. package/lib/page/resolvePageSlug.d.ts +0 -6
  104. package/lib/page/resolvePageSlug.js +0 -17
  105. package/lib/page/resolvePageTitle.d.ts +0 -9
  106. package/lib/page/resolvePageTitle.js +0 -26
  107. package/lib/pluginApi/createHookQueue.d.ts +0 -5
  108. package/lib/pluginApi/createHookQueue.js +0 -81
  109. package/lib/pluginApi/createPluginApi.d.ts +0 -2
  110. package/lib/pluginApi/createPluginApi.js +0 -16
  111. package/lib/pluginApi/createPluginApiHooks.d.ts +0 -2
  112. package/lib/pluginApi/createPluginApiHooks.js +0 -24
  113. package/lib/pluginApi/createPluginApiRegisterHooks.d.ts +0 -2
  114. package/lib/pluginApi/createPluginApiRegisterHooks.js +0 -54
  115. package/lib/pluginApi/index.d.ts +0 -6
  116. package/lib/pluginApi/index.js +0 -18
  117. package/lib/pluginApi/normalizeClientFilesHook.d.ts +0 -5
  118. package/lib/pluginApi/normalizeClientFilesHook.js +0 -28
  119. package/lib/pluginApi/normalizeReturnObjectHook.d.ts +0 -5
  120. package/lib/pluginApi/normalizeReturnObjectHook.js +0 -9
  121. package/lib/themeApi/createThemeApi.d.ts +0 -7
  122. package/lib/themeApi/createThemeApi.js +0 -30
  123. package/lib/themeApi/index.d.ts +0 -3
  124. package/lib/themeApi/index.js +0 -15
  125. package/lib/themeApi/resolveThemeInfo.d.ts +0 -2
  126. package/lib/themeApi/resolveThemeInfo.js +0 -32
  127. package/lib/themeApi/resolveThemeLayouts.d.ts +0 -5
  128. package/lib/themeApi/resolveThemeLayouts.js +0 -32
  129. package/lib/types/app/app.d.ts +0 -30
  130. package/lib/types/app/app.js +0 -2
  131. package/lib/types/app/index.d.ts +0 -3
  132. package/lib/types/app/index.js +0 -15
  133. package/lib/types/app/options.d.ts +0 -31
  134. package/lib/types/app/options.js +0 -2
  135. package/lib/types/app/utils.d.ts +0 -29
  136. package/lib/types/app/utils.js +0 -2
  137. package/lib/types/bundler.d.ts +0 -34
  138. package/lib/types/bundler.js +0 -2
  139. package/lib/types/index.d.ts +0 -9
  140. package/lib/types/index.js +0 -19
  141. package/lib/types/page.d.ts +0 -110
  142. package/lib/types/page.js +0 -2
  143. package/lib/types/plugin.d.ts +0 -48
  144. package/lib/types/plugin.js +0 -2
  145. package/lib/types/pluginApi/hooks.d.ts +0 -75
  146. package/lib/types/pluginApi/hooks.js +0 -2
  147. package/lib/types/pluginApi/index.d.ts +0 -2
  148. package/lib/types/pluginApi/index.js +0 -14
  149. package/lib/types/pluginApi/pluginApi.d.ts +0 -23
  150. package/lib/types/pluginApi/pluginApi.js +0 -2
  151. package/lib/types/theme.d.ts +0 -33
  152. package/lib/types/theme.js +0 -2
  153. package/lib/types/themeApi/index.d.ts +0 -1
  154. package/lib/types/themeApi/index.js +0 -13
  155. package/lib/types/themeApi/themeApi.d.ts +0 -44
  156. package/lib/types/themeApi/themeApi.js +0 -2
package/dist/index.js ADDED
@@ -0,0 +1,1039 @@
1
+ // src/app/prepare/prepareClientConfigs.ts
2
+ var prepareClientConfigs = async (app) => {
3
+ const clientConfigFiles = await app.pluginApi.hooks.clientConfigFile.process(app);
4
+ const content = `${clientConfigFiles.map((filePath, index) => `import clientConfig${index} from '${filePath}'`).join("\n")}
5
+
6
+ export const clientConfigs = [
7
+ ${clientConfigFiles.map((_, index) => ` clientConfig${index},`).join("\n")}
8
+ ]
9
+ `;
10
+ await app.writeTemp("internal/clientConfigs.js", content);
11
+ };
12
+
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
31
+ var HMR_CODE = `
32
+ if (import.meta.webpackHot) {
33
+ import.meta.webpackHot.accept()
34
+ if (__VUE_HMR_RUNTIME__.updatePageData) {
35
+ __VUE_HMR_RUNTIME__.updatePageData(data)
36
+ }
37
+ }
38
+
39
+ if (import.meta.hot) {
40
+ import.meta.hot.accept(({ data }) => {
41
+ __VUE_HMR_RUNTIME__.updatePageData(data)
42
+ })
43
+ }
44
+ `;
45
+ var preparePageData = async (app, page) => {
46
+ let content = `export const data = JSON.parse(${JSON.stringify(
47
+ JSON.stringify(page.data)
48
+ )})
49
+ `;
50
+ if (app.env.isDev) {
51
+ content += HMR_CODE;
52
+ }
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;
160
+ };
161
+
162
+ // src/app/resolveAppPages.ts
163
+ import { debug as debug2, globby } from "@vuepress/utils";
164
+
165
+ // src/page/inferPagePath.ts
166
+ import { ensureLeadingSlash as ensureLeadingSlash2, resolveLocalePath } from "@vuepress/shared";
167
+ var inferPagePath = ({
168
+ app,
169
+ filePathRelative
170
+ }) => {
171
+ if (!filePathRelative) {
172
+ return {
173
+ pathInferred: null,
174
+ pathLocale: "/"
175
+ };
176
+ }
177
+ const pathInferred = ensureLeadingSlash2(filePathRelative).replace(/\.md$/, ".html").replace(/\/(README|index).html$/i, "/");
178
+ const pathLocale = resolveLocalePath(app.siteData.locales, pathInferred);
179
+ return {
180
+ pathInferred,
181
+ pathLocale
182
+ };
183
+ };
184
+
185
+ // src/page/renderPageContent.ts
186
+ import { omit } from "@vuepress/shared";
187
+ var renderPageContent = ({
188
+ app,
189
+ content,
190
+ filePath,
191
+ filePathRelative,
192
+ options
193
+ }) => {
194
+ const markdownEnv = {
195
+ base: app.options.base,
196
+ filePath,
197
+ filePathRelative,
198
+ frontmatter: { ...options.frontmatter }
199
+ };
200
+ const contentRendered = app.markdown.render(content, markdownEnv);
201
+ const {
202
+ frontmatter = {},
203
+ headers = [],
204
+ importedFiles = [],
205
+ links = [],
206
+ sfcBlocks = {
207
+ template: null,
208
+ script: null,
209
+ scriptSetup: null,
210
+ scripts: [],
211
+ styles: [],
212
+ customBlocks: []
213
+ },
214
+ title = "",
215
+ ...extraMarkdownEnv
216
+ } = markdownEnv;
217
+ return {
218
+ contentRendered,
219
+ deps: importedFiles,
220
+ frontmatter,
221
+ headers,
222
+ links,
223
+ markdownEnv: omit(
224
+ extraMarkdownEnv,
225
+ "base",
226
+ "content",
227
+ "filePath",
228
+ "filePathRelative",
229
+ "frontmatter"
230
+ ),
231
+ sfcBlocks,
232
+ title: frontmatter.title ? `${frontmatter.title}` : title
233
+ };
234
+ };
235
+
236
+ // src/page/resolvePageComponentInfo.ts
237
+ import { path } from "@vuepress/utils";
238
+ var resolvePageComponentInfo = async ({
239
+ app,
240
+ htmlFilePathRelative,
241
+ key
242
+ }) => {
243
+ const componentFilePathRelative = path.join(
244
+ "pages",
245
+ `${htmlFilePathRelative}.vue`
246
+ );
247
+ const componentFilePath = app.dir.temp(componentFilePathRelative);
248
+ const componentFileChunkName = key;
249
+ return {
250
+ componentFilePath,
251
+ componentFilePathRelative,
252
+ componentFileChunkName
253
+ };
254
+ };
255
+
256
+ // src/page/resolvePageDataInfo.ts
257
+ import { path as path2 } from "@vuepress/utils";
258
+ var resolvePageDataInfo = ({
259
+ app,
260
+ htmlFilePathRelative,
261
+ key
262
+ }) => {
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
+ };
271
+ };
272
+
273
+ // src/page/resolvePageDate.ts
274
+ import { formatDateString, isString } from "@vuepress/shared";
275
+ import { path as path3 } from "@vuepress/utils";
276
+ var FILENAME_DATE_RE = /^(\d{4})-(\d{1,2})(?:-(\d{1,2}))?-(.*)$/;
277
+ var DIRNAME_DATE_RE = /(\d{4})\/(\d{1,2})(?:\/(\d{1,2}))?(\/|$)/;
278
+ var DEFAULT_DATE = "0000-00-00";
279
+ var resolvePageDate = ({
280
+ frontmatter,
281
+ filePathRelative
282
+ }) => {
283
+ if (frontmatter.date instanceof Date) {
284
+ return formatDateString(
285
+ [
286
+ frontmatter.date.getUTCFullYear(),
287
+ frontmatter.date.getUTCMonth() + 1,
288
+ frontmatter.date.getUTCDate()
289
+ ].join("-"),
290
+ DEFAULT_DATE
291
+ );
292
+ }
293
+ if (isString(frontmatter.date)) {
294
+ return formatDateString(frontmatter.date, DEFAULT_DATE);
295
+ }
296
+ if (filePathRelative === null) {
297
+ return DEFAULT_DATE;
298
+ }
299
+ const filename = path3.parse(filePathRelative).name;
300
+ if (filename) {
301
+ const matches = filename.match(FILENAME_DATE_RE);
302
+ if (matches) {
303
+ return formatDateString(
304
+ `${matches[1]}-${matches[2]}-${matches[3] ?? "01"}`,
305
+ DEFAULT_DATE
306
+ );
307
+ }
308
+ }
309
+ const dirname = path3.dirname(filePathRelative);
310
+ if (dirname !== ".") {
311
+ const matches = dirname.match(DIRNAME_DATE_RE);
312
+ if (matches) {
313
+ return formatDateString(
314
+ `${matches[1]}-${matches[2]}-${matches[3] ?? "01"}`,
315
+ DEFAULT_DATE
316
+ );
317
+ }
318
+ }
319
+ return DEFAULT_DATE;
320
+ };
321
+
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
+ // src/page/resolvePageFilePath.ts
341
+ import { logger, path as path4 } from "@vuepress/utils";
342
+ var resolvePageFilePath = ({
343
+ app,
344
+ options
345
+ }) => {
346
+ if (!options.filePath) {
347
+ return {
348
+ filePath: null,
349
+ filePathRelative: null
350
+ };
351
+ }
352
+ if (!path4.isAbsolute(options.filePath)) {
353
+ throw logger.createError(
354
+ `filePath is not absolute file path: ${options.filePath}}`
355
+ );
356
+ }
357
+ return {
358
+ filePath: options.filePath,
359
+ filePathRelative: path4.relative(app.dir.source(), options.filePath)
360
+ };
361
+ };
362
+
363
+ // src/page/resolvePageHtmlInfo.ts
364
+ import { removeLeadingSlash } from "@vuepress/shared";
365
+ var resolvePageHtmlInfo = ({
366
+ app,
367
+ path: pagePath
368
+ }) => {
369
+ const htmlFilePathRelative = removeLeadingSlash(
370
+ decodeURI(pagePath.replace(/\/$/, "/index.html"))
371
+ );
372
+ const htmlFilePath = app.dir.dest(htmlFilePathRelative);
373
+ return {
374
+ htmlFilePath,
375
+ htmlFilePathRelative
376
+ };
377
+ };
378
+
379
+ // src/page/resolvePageKey.ts
380
+ import { hash } from "@vuepress/utils";
381
+ var resolvePageKey = ({ path: path9 }) => `v-${hash(path9)}`;
382
+
383
+ // src/page/resolvePageLang.ts
384
+ import { isString as isString2 } from "@vuepress/shared";
385
+ var resolvePageLang = ({
386
+ app,
387
+ frontmatter,
388
+ pathLocale
389
+ }) => {
390
+ if (isString2(frontmatter.lang) && frontmatter.lang) {
391
+ return frontmatter.lang;
392
+ }
393
+ return app.siteData.locales[pathLocale]?.lang ?? app.siteData.lang;
394
+ };
395
+
396
+ // src/page/resolvePagePath.ts
397
+ import { ensureEndingSlash } from "@vuepress/shared";
398
+ import { logger as logger2, sanitizeFileName } from "@vuepress/utils";
399
+ var resolvePagePath = ({
400
+ permalink,
401
+ pathInferred,
402
+ options
403
+ }) => {
404
+ let pagePath = options.path || permalink || pathInferred;
405
+ if (!pagePath) {
406
+ throw logger2.createError(
407
+ `page path is empty, page options: ${JSON.stringify(options, null, 2)}`
408
+ );
409
+ }
410
+ if (!pagePath.endsWith(".html")) {
411
+ pagePath = ensureEndingSlash(pagePath);
412
+ }
413
+ return encodeURI(pagePath.split("/").map(sanitizeFileName).join("/"));
414
+ };
415
+
416
+ // src/page/resolvePagePermalink.ts
417
+ import { ensureLeadingSlash as ensureLeadingSlash3, isString as isString3 } from "@vuepress/shared";
418
+ import { path as path5 } from "@vuepress/utils";
419
+ var resolvePagePermalink = ({
420
+ app,
421
+ frontmatter,
422
+ slug,
423
+ date,
424
+ pathInferred,
425
+ pathLocale
426
+ }) => {
427
+ if (isString3(frontmatter.permalink)) {
428
+ return frontmatter.permalink;
429
+ }
430
+ const permalinkPattern = getPermalinkPattern({ app, frontmatter });
431
+ if (permalinkPattern === null) {
432
+ return null;
433
+ }
434
+ const [year, month, day] = date.split("-");
435
+ const link = path5.join(
436
+ pathLocale,
437
+ permalinkPattern.replace(/:year/, year).replace(/:month/, month).replace(/:day/, day).replace(/:slug/, slug).replace(/:raw/, pathInferred?.replace(/^\//, "") ?? "")
438
+ );
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;
452
+ };
453
+
454
+ // src/page/resolvePageRouteMeta.ts
455
+ var resolvePageRouteMeta = ({
456
+ frontmatter
457
+ }) => frontmatter.routeMeta ?? {};
458
+
459
+ // src/page/resolvePageSlug.ts
460
+ import { path as path6 } from "@vuepress/utils";
461
+ var DATE_RE = /(\d{4}-\d{1,2}(-\d{1,2})?)-(.*)/;
462
+ var resolvePageSlug = ({
463
+ filePathRelative
464
+ }) => {
465
+ if (!filePathRelative) {
466
+ return "";
467
+ }
468
+ const filename = path6.parse(filePathRelative).name;
469
+ const match = filename.match(DATE_RE);
470
+ return match ? match[3] : filename;
471
+ };
472
+
473
+ // src/page/createPage.ts
474
+ var createPage = async (app, options) => {
475
+ await app.pluginApi.hooks.extendsPageOptions.process(options, app);
476
+ const { filePath, filePathRelative } = resolvePageFilePath({
477
+ app,
478
+ options
479
+ });
480
+ const content = await resolvePageFileContent({ filePath, options });
481
+ const {
482
+ contentRendered,
483
+ deps,
484
+ frontmatter,
485
+ headers,
486
+ links,
487
+ markdownEnv,
488
+ sfcBlocks,
489
+ title
490
+ } = renderPageContent({
491
+ app,
492
+ content,
493
+ filePath,
494
+ filePathRelative,
495
+ options
496
+ });
497
+ const routeMeta = resolvePageRouteMeta({ frontmatter });
498
+ const slug = resolvePageSlug({ filePathRelative });
499
+ const date = resolvePageDate({ frontmatter, filePathRelative });
500
+ const { pathInferred, pathLocale } = inferPagePath({ app, filePathRelative });
501
+ const lang = resolvePageLang({ app, frontmatter, pathLocale });
502
+ const permalink = resolvePagePermalink({
503
+ app,
504
+ frontmatter,
505
+ slug,
506
+ date,
507
+ pathInferred,
508
+ pathLocale
509
+ });
510
+ const path9 = resolvePagePath({ permalink, pathInferred, options });
511
+ const key = resolvePageKey({ path: path9 });
512
+ const { htmlFilePath, htmlFilePathRelative } = resolvePageHtmlInfo({
513
+ app,
514
+ path: path9
515
+ });
516
+ const {
517
+ componentFilePath,
518
+ componentFilePathRelative,
519
+ componentFileChunkName
520
+ } = await resolvePageComponentInfo({
521
+ app,
522
+ htmlFilePathRelative,
523
+ key
524
+ });
525
+ const { dataFilePath, dataFilePathRelative, dataFileChunkName } = resolvePageDataInfo({ app, htmlFilePathRelative, key });
526
+ const page = {
527
+ // page data
528
+ data: {
529
+ key,
530
+ path: path9,
531
+ title,
532
+ lang,
533
+ frontmatter,
534
+ headers
535
+ },
536
+ // base fields
537
+ key,
538
+ path: path9,
539
+ title,
540
+ lang,
541
+ frontmatter,
542
+ headers,
543
+ // extra fields
544
+ content,
545
+ contentRendered,
546
+ date,
547
+ deps,
548
+ links,
549
+ markdownEnv,
550
+ pathInferred,
551
+ pathLocale,
552
+ permalink,
553
+ routeMeta,
554
+ sfcBlocks,
555
+ slug,
556
+ // file info
557
+ filePath,
558
+ filePathRelative,
559
+ componentFilePath,
560
+ componentFilePathRelative,
561
+ componentFileChunkName,
562
+ dataFilePath,
563
+ dataFilePathRelative,
564
+ dataFileChunkName,
565
+ htmlFilePath,
566
+ htmlFilePathRelative
567
+ };
568
+ await app.pluginApi.hooks.extendsPage.process(page, app);
569
+ return page;
570
+ };
571
+
572
+ // src/app/resolveAppPages.ts
573
+ var log2 = debug2("vuepress:core/app");
574
+ var resolveAppPages = async (app) => {
575
+ log2("resolveAppPages start");
576
+ const pageFilePaths = await globby(app.options.pagePatterns, {
577
+ absolute: true,
578
+ cwd: app.dir.source()
579
+ });
580
+ const pages = await Promise.all(
581
+ pageFilePaths.map((filePath) => createPage(app, { filePath }))
582
+ );
583
+ if (!pages.some((page) => page.path === "/404.html")) {
584
+ pages.push(
585
+ await createPage(app, {
586
+ path: "/404.html",
587
+ frontmatter: {
588
+ layout: "NotFound"
589
+ }
590
+ })
591
+ );
592
+ }
593
+ log2("resolveAppPages finish");
594
+ return pages;
595
+ };
596
+
597
+ // src/app/appInit.ts
598
+ var log3 = debug3("vuepress:core/app");
599
+ var appInit = async (app) => {
600
+ log3("init start");
601
+ app.pluginApi.registerHooks();
602
+ app.markdown = await resolveAppMarkdown(app);
603
+ app.pages = await resolveAppPages(app);
604
+ await app.pluginApi.hooks.onInitialized.process(app);
605
+ log3("init finish");
606
+ };
607
+
608
+ // src/app/appPrepare.ts
609
+ import { debug as debug4 } from "@vuepress/utils";
610
+ var log4 = debug4("vuepress:core/app");
611
+ var appPrepare = async (app) => {
612
+ 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);
624
+ await app.pluginApi.hooks.onPrepared.process(app);
625
+ log4("prepare finish");
626
+ };
627
+
628
+ // src/app/appUse.ts
629
+ import { colors, debug as debug5, warn } from "@vuepress/utils";
630
+
631
+ // src/app/resolvePluginObject.ts
632
+ import { isFunction } from "@vuepress/shared";
633
+ var resolvePluginObject = (app, plugin) => isFunction(plugin) ? plugin(app) : plugin;
634
+
635
+ // src/app/appUse.ts
636
+ var log5 = debug5("vuepress:core/app");
637
+ var appUse = (app, rawPlugin) => {
638
+ const pluginObject = resolvePluginObject(app, rawPlugin);
639
+ if (!pluginObject.name) {
640
+ warn(`an anonymous plugin or theme was detected and ignored`);
641
+ return app;
642
+ }
643
+ log5(`use plugin ${colors.magenta(pluginObject.name)}`);
644
+ if (pluginObject.multiple !== true) {
645
+ const duplicateIndex = app.pluginApi.plugins.findIndex(
646
+ ({ name }) => name === pluginObject.name
647
+ );
648
+ if (duplicateIndex !== -1) {
649
+ app.pluginApi.plugins.splice(duplicateIndex, 1);
650
+ warn(
651
+ `plugin ${colors.magenta(
652
+ pluginObject.name
653
+ )} has been used multiple times, only the last one will take effect`
654
+ );
655
+ }
656
+ }
657
+ app.pluginApi.plugins.push(pluginObject);
658
+ return app;
659
+ };
660
+
661
+ // src/pluginApi/createHookQueue.ts
662
+ import { colors as colors2, debug as debug6, logger as logger3 } from "@vuepress/utils";
663
+ var log6 = debug6("vuepress:core/plugin-api");
664
+ var createHookQueue = (name) => {
665
+ const items = [];
666
+ const hookQueue = {
667
+ name,
668
+ items,
669
+ add: (item) => {
670
+ items.push(item);
671
+ },
672
+ process: async (...args) => {
673
+ const results = [];
674
+ for (const item of items) {
675
+ log6(
676
+ `process ${colors2.magenta(name)} from ${colors2.magenta(
677
+ item.pluginName
678
+ )}`
679
+ );
680
+ try {
681
+ const result = await item.hook(...args);
682
+ if (result !== void 0) {
683
+ results.push(result);
684
+ }
685
+ } catch (e) {
686
+ logger3.error(
687
+ `error in hook ${colors2.magenta(name)} from ${colors2.magenta(
688
+ item.pluginName
689
+ )}`
690
+ );
691
+ throw e;
692
+ }
693
+ }
694
+ return results;
695
+ }
696
+ };
697
+ return hookQueue;
698
+ };
699
+
700
+ // src/pluginApi/createPluginApiHooks.ts
701
+ var createPluginApiHooks = () => ({
702
+ // life cycle hooks
703
+ onInitialized: createHookQueue("onInitialized"),
704
+ onPrepared: createHookQueue("onPrepared"),
705
+ onWatched: createHookQueue("onWatched"),
706
+ onGenerated: createHookQueue("onGenerated"),
707
+ // extends hooks
708
+ extendsMarkdownOptions: createHookQueue("extendsMarkdownOptions"),
709
+ extendsMarkdown: createHookQueue("extendsMarkdown"),
710
+ extendsPageOptions: createHookQueue("extendsPageOptions"),
711
+ extendsPage: createHookQueue("extendsPage"),
712
+ extendsBundlerOptions: createHookQueue("extendsBundlerOptions"),
713
+ // client config file hooks
714
+ clientConfigFile: createHookQueue("clientConfigFile"),
715
+ // bundler hooks
716
+ alias: createHookQueue("alias"),
717
+ define: createHookQueue("define")
718
+ });
719
+
720
+ // src/pluginApi/normalizeAliasDefineHook.ts
721
+ import { isFunction as isFunction2 } from "@vuepress/shared";
722
+ var normalizeAliasDefineHook = (hook) => async (app, isServer) => isFunction2(hook) ? hook(app, isServer) : hook;
723
+
724
+ // src/pluginApi/normalizeClientConfigFileHook.ts
725
+ import { isFunction as isFunction3 } from "@vuepress/shared";
726
+ import { fs as fs2, logger as logger4 } from "@vuepress/utils";
727
+ var normalizeClientConfigFileHook = (hook) => async (app) => {
728
+ const clientConfigFileResult = isFunction3(hook) ? await hook(app) : hook;
729
+ const isExisted = await fs2.pathExists(clientConfigFileResult);
730
+ if (!isExisted) {
731
+ throw logger4.createError(
732
+ `client config file does not exist: ${clientConfigFileResult}`
733
+ );
734
+ }
735
+ return clientConfigFileResult;
736
+ };
737
+
738
+ // src/pluginApi/createPluginApiRegisterHooks.ts
739
+ var createPluginApiRegisterHooks = (plugins, hooks) => () => {
740
+ plugins.forEach(
741
+ ({
742
+ name: pluginName,
743
+ multiple,
744
+ alias,
745
+ define,
746
+ clientConfigFile,
747
+ ...commonHooks
748
+ }) => {
749
+ if (alias) {
750
+ hooks.alias.add({
751
+ pluginName,
752
+ hook: normalizeAliasDefineHook(alias)
753
+ });
754
+ }
755
+ if (define) {
756
+ hooks.define.add({
757
+ pluginName,
758
+ hook: normalizeAliasDefineHook(define)
759
+ });
760
+ }
761
+ if (clientConfigFile) {
762
+ hooks.clientConfigFile.add({
763
+ pluginName,
764
+ hook: normalizeClientConfigFileHook(clientConfigFile)
765
+ });
766
+ }
767
+ Object.keys(commonHooks).forEach((key) => {
768
+ if (hooks[key] && commonHooks[key]) {
769
+ hooks[key].add({
770
+ pluginName,
771
+ hook: commonHooks[key]
772
+ });
773
+ }
774
+ });
775
+ }
776
+ );
777
+ };
778
+
779
+ // src/pluginApi/createPluginApi.ts
780
+ var createPluginApi = () => {
781
+ const plugins = [];
782
+ const hooks = createPluginApiHooks();
783
+ const registerHooks = createPluginApiRegisterHooks(plugins, hooks);
784
+ return {
785
+ plugins,
786
+ hooks,
787
+ registerHooks
788
+ };
789
+ };
790
+
791
+ // src/app/resolveAppDir.ts
792
+ import { createRequire } from "module";
793
+ import { path as path7 } from "@vuepress/utils";
794
+ var require2 = createRequire(import.meta.url);
795
+ var createAppDirFunction = (baseDir) => {
796
+ return (...args) => path7.resolve(baseDir, ...args);
797
+ };
798
+ var resolveAppDir = (options) => {
799
+ const cache = createAppDirFunction(options.cache);
800
+ const temp = createAppDirFunction(options.temp);
801
+ const source = createAppDirFunction(options.source);
802
+ const dest = createAppDirFunction(options.dest);
803
+ const publicDir = createAppDirFunction(options.public);
804
+ const client = createAppDirFunction(
805
+ path7.resolve(require2.resolve("@vuepress/client/package.json"), "..")
806
+ );
807
+ return {
808
+ cache,
809
+ temp,
810
+ source,
811
+ dest,
812
+ client,
813
+ public: publicDir
814
+ };
815
+ };
816
+
817
+ // src/app/resolveAppEnv.ts
818
+ var resolveAppEnv = (options, isBuild) => ({
819
+ isBuild,
820
+ isDev: !isBuild,
821
+ isDebug: options.debug
822
+ });
823
+
824
+ // src/app/resolveAppOptions.ts
825
+ import { createRequire as createRequire2 } from "module";
826
+ import { path as path8, templateRenderer } from "@vuepress/utils";
827
+ var require3 = createRequire2(import.meta.url);
828
+ var resolveAppOptions = ({
829
+ // site config
830
+ base = "/",
831
+ lang = "en-US",
832
+ title = "",
833
+ description = "",
834
+ head = [],
835
+ locales = {},
836
+ // directory config
837
+ source,
838
+ dest = path8.resolve(source, ".vuepress/dist"),
839
+ temp = path8.resolve(source, ".vuepress/.temp"),
840
+ cache = path8.resolve(source, ".vuepress/.cache"),
841
+ public: publicDir = path8.resolve(source, ".vuepress/public"),
842
+ // dev config
843
+ host = "0.0.0.0",
844
+ port = 8080,
845
+ open = false,
846
+ templateDev = path8.normalize(
847
+ require3.resolve("@vuepress/client/templates/dev.html")
848
+ ),
849
+ // build config
850
+ shouldPreload = true,
851
+ shouldPrefetch = true,
852
+ templateBuild = path8.normalize(
853
+ require3.resolve("@vuepress/client/templates/build.html")
854
+ ),
855
+ // common config
856
+ bundler,
857
+ debug: debug7 = false,
858
+ markdown = {},
859
+ pagePatterns = ["**/*.md", "!.vuepress", "!node_modules"],
860
+ permalinkPattern = null,
861
+ plugins = [],
862
+ theme
863
+ }) => ({
864
+ base,
865
+ lang,
866
+ title,
867
+ description,
868
+ head,
869
+ locales,
870
+ source,
871
+ dest,
872
+ temp,
873
+ cache,
874
+ public: publicDir,
875
+ host,
876
+ port,
877
+ open,
878
+ templateDev,
879
+ shouldPreload,
880
+ shouldPrefetch,
881
+ templateBuild,
882
+ templateBuildRenderer: templateRenderer,
883
+ bundler,
884
+ debug: debug7,
885
+ markdown,
886
+ pagePatterns,
887
+ permalinkPattern,
888
+ plugins,
889
+ theme
890
+ });
891
+
892
+ // src/app/resolveAppSiteData.ts
893
+ var resolveAppSiteData = (options) => ({
894
+ base: options.base,
895
+ lang: options.lang,
896
+ title: options.title,
897
+ description: options.description,
898
+ head: options.head,
899
+ locales: options.locales
900
+ });
901
+
902
+ // src/app/resolveAppVersion.ts
903
+ import { createRequire as createRequire3 } from "module";
904
+ import { fs as fs3 } from "@vuepress/utils";
905
+ var require4 = createRequire3(import.meta.url);
906
+ var resolveAppVersion = () => {
907
+ const pkgJson = fs3.readJsonSync(
908
+ require4.resolve("@vuepress/core/package.json")
909
+ );
910
+ return pkgJson.version;
911
+ };
912
+
913
+ // src/app/resolveAppWriteTemp.ts
914
+ import { fs as fs4 } from "@vuepress/utils";
915
+ var resolveAppWriteTemp = (dir) => {
916
+ const writeTemp = async (file, content) => {
917
+ const filePath = dir.temp(file);
918
+ await fs4.outputFile(filePath, content);
919
+ return filePath;
920
+ };
921
+ return writeTemp;
922
+ };
923
+
924
+ // src/app/resolveThemeInfo.ts
925
+ var resolveThemeInfo = (app, theme) => {
926
+ const themeObject = resolvePluginObject(app, theme);
927
+ const themeInfo = {
928
+ plugins: [...themeObject.plugins ?? [], themeObject],
929
+ templateBuild: themeObject.templateBuild,
930
+ templateBuildRenderer: themeObject.templateBuildRenderer,
931
+ templateDev: themeObject.templateDev
932
+ };
933
+ if (!themeObject.extends) {
934
+ return themeInfo;
935
+ }
936
+ const parentThemeInfo = resolveThemeInfo(app, themeObject.extends);
937
+ return {
938
+ plugins: [...parentThemeInfo.plugins, ...themeInfo.plugins],
939
+ templateBuild: themeObject.templateBuild ?? parentThemeInfo.templateBuild,
940
+ templateBuildRenderer: themeObject.templateBuildRenderer ?? parentThemeInfo.templateBuildRenderer,
941
+ templateDev: themeObject.templateDev ?? parentThemeInfo.templateDev
942
+ };
943
+ };
944
+
945
+ // src/app/setupAppThemeAndPlugins.ts
946
+ var setupAppThemeAndPlugins = (app, config) => {
947
+ const themeInfo = resolveThemeInfo(app, app.options.theme);
948
+ app.options.templateDev = config.templateDev ?? themeInfo.templateDev ?? app.options.templateDev;
949
+ app.options.templateBuild = config.templateBuild ?? themeInfo.templateBuild ?? app.options.templateBuild;
950
+ app.options.templateBuildRenderer = config.templateBuildRenderer ?? themeInfo.templateBuildRenderer ?? app.options.templateBuildRenderer;
951
+ [...themeInfo.plugins, ...app.options.plugins].flat().forEach((plugin) => app.use(plugin));
952
+ };
953
+
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
+ // src/app/createBuildApp.ts
982
+ var createBuildApp = (config) => {
983
+ const app = createBaseApp(config, true);
984
+ app.build = () => app.options.bundler.build(app);
985
+ return app;
986
+ };
987
+
988
+ // src/app/createDevApp.ts
989
+ var createDevApp = (config) => {
990
+ const app = createBaseApp(config, false);
991
+ app.dev = () => app.options.bundler.dev(app);
992
+ return app;
993
+ };
994
+ export {
995
+ appInit,
996
+ appPrepare,
997
+ appUse,
998
+ createAppDirFunction,
999
+ createBaseApp,
1000
+ createBuildApp,
1001
+ createDevApp,
1002
+ createHookQueue,
1003
+ createPage,
1004
+ createPluginApi,
1005
+ createPluginApiHooks,
1006
+ createPluginApiRegisterHooks,
1007
+ inferPagePath,
1008
+ normalizeAliasDefineHook,
1009
+ normalizeClientConfigFileHook,
1010
+ prepareClientConfigs,
1011
+ preparePageComponent,
1012
+ preparePageData,
1013
+ preparePagesComponents,
1014
+ preparePagesData,
1015
+ preparePagesRoutes,
1016
+ prepareSiteData,
1017
+ renderPageContent,
1018
+ resolveAppDir,
1019
+ resolveAppEnv,
1020
+ resolveAppOptions,
1021
+ resolveAppPages,
1022
+ resolveAppSiteData,
1023
+ resolveAppVersion,
1024
+ resolveAppWriteTemp,
1025
+ resolvePageComponentInfo,
1026
+ resolvePageDataInfo,
1027
+ resolvePageDate,
1028
+ resolvePageFileContent,
1029
+ resolvePageFilePath,
1030
+ resolvePageHtmlInfo,
1031
+ resolvePageKey,
1032
+ resolvePageLang,
1033
+ resolvePagePath,
1034
+ resolvePagePermalink,
1035
+ resolvePageRouteMeta,
1036
+ resolvePageSlug,
1037
+ resolvePluginObject,
1038
+ resolveThemeInfo
1039
+ };