@vuepress/core 2.0.0-beta.6 → 2.0.0-beta.60

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