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