vitepress 0.20.2 → 0.20.6

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/node/cli.js CHANGED
@@ -1,6 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var serve = require('./serve-c378302d.js');
3
+ var serve = require('./serve-13371594.js');
4
+ require('fs');
5
+ require('path');
6
+ require('url');
4
7
  require('vite');
5
8
  require('readline');
6
9
  require('assert');
@@ -8,11 +11,8 @@ require('events');
8
11
  require('stream');
9
12
  require('util');
10
13
  require('buffer');
11
- require('path');
12
- require('fs');
13
14
  require('punycode');
14
15
  require('prismjs');
15
- require('url');
16
16
  require('querystring');
17
17
  require('tty');
18
18
  require('net');
@@ -11,6 +11,8 @@ export declare function build(root: string, buildOptions?: BuildOptions & {
11
11
  mpa?: string;
12
12
  }): Promise<void>;
13
13
 
14
+ export declare const createMarkdownRenderer: (srcDir: string, options?: MarkdownOptions) => MarkdownRenderer;
15
+
14
16
  export declare function createServer(root?: string, serverOptions?: ServerOptions): Promise<ViteDevServer>;
15
17
 
16
18
  /**
@@ -22,6 +24,12 @@ export declare type HeadConfig =
22
24
  | [string, Record<string, string>]
23
25
  | [string, Record<string, string>, string]
24
26
 
27
+ export declare interface Header {
28
+ level: number
29
+ title: string
30
+ slug: string
31
+ }
32
+
25
33
  export declare interface LocaleConfig {
26
34
  lang: string
27
35
  title?: string
@@ -46,6 +54,20 @@ export declare interface MarkdownOptions extends MarkdownIt.Options {
46
54
  externalLinks?: Record<string, string>;
47
55
  }
48
56
 
57
+ export declare interface MarkdownParsedData {
58
+ hoistedTags?: string[];
59
+ links?: string[];
60
+ headers?: Header[];
61
+ }
62
+
63
+ export declare interface MarkdownRenderer {
64
+ __data: MarkdownParsedData;
65
+ render: (src: string, env?: any) => {
66
+ html: string;
67
+ data: any;
68
+ };
69
+ }
70
+
49
71
  export declare type RawConfigExports = UserConfig | Promise<UserConfig> | (() => UserConfig | Promise<UserConfig>);
50
72
 
51
73
  export declare function resolveConfig(root?: string, command?: 'serve' | 'build', mode?: string): Promise<SiteConfig>;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var serve = require('./serve-c378302d.js');
5
+ var serve = require('./serve-13371594.js');
6
6
  require('vite');
7
7
  require('readline');
8
8
  require('assert');
@@ -26,6 +26,7 @@ require('http');
26
26
 
27
27
 
28
28
  exports.build = serve.build;
29
+ exports.createMarkdownRenderer = serve.createMarkdownRenderer;
29
30
  exports.createServer = serve.createServer;
30
31
  exports.defineConfig = serve.defineConfig;
31
32
  exports.resolveConfig = serve.resolveConfig;
@@ -36431,6 +36431,79 @@ const getHeadMetaContent = (head, name) => {
36431
36431
  return meta && meta[1].content;
36432
36432
  };
36433
36433
 
36434
+ const loaderMatch = /\.data\.(j|t)s$/;
36435
+ let server;
36436
+ const idToLoaderModulesMap = Object.create(null);
36437
+ let idToPendingPromiseMap = Object.create(null);
36438
+ let isBuild = false;
36439
+ const staticDataPlugin = {
36440
+ name: "vitepress:data",
36441
+ configResolved(config) {
36442
+ isBuild = config.command === "build";
36443
+ },
36444
+ configureServer(_server) {
36445
+ server = _server;
36446
+ },
36447
+ async load(id) {
36448
+ var _a;
36449
+ if (loaderMatch.test(id)) {
36450
+ let _resolve;
36451
+ if (isBuild) {
36452
+ if (idToPendingPromiseMap[id]) {
36453
+ return idToPendingPromiseMap[id];
36454
+ }
36455
+ idToPendingPromiseMap[id] = new Promise((r) => {
36456
+ _resolve = r;
36457
+ });
36458
+ }
36459
+ const base = path$p.dirname(id);
36460
+ let pattern;
36461
+ let loader;
36462
+ const existing = idToLoaderModulesMap[id];
36463
+ if (existing) {
36464
+ ({ pattern, loader } = existing);
36465
+ } else {
36466
+ const loaderModule = (_a = await vite.loadConfigFromFile({}, id)) == null ? void 0 : _a.config;
36467
+ pattern = loaderModule.watch;
36468
+ if (pattern && pattern.startsWith("./")) {
36469
+ pattern = pattern.slice(2);
36470
+ }
36471
+ loader = loaderModule.load;
36472
+ }
36473
+ const data = await loader();
36474
+ if (server) {
36475
+ idToLoaderModulesMap[id] = { base, pattern, loader };
36476
+ }
36477
+ const result = `export const data = JSON.parse(${JSON.stringify(JSON.stringify(data))})`;
36478
+ if (_resolve)
36479
+ _resolve(result);
36480
+ return result;
36481
+ }
36482
+ },
36483
+ transform(_code, id) {
36484
+ if (server && loaderMatch.test(id)) {
36485
+ const { base, pattern } = idToLoaderModulesMap[id];
36486
+ server._globImporters[id] = {
36487
+ module: server.moduleGraph.getModuleById(id),
36488
+ importGlobs: [{ base, pattern }]
36489
+ };
36490
+ }
36491
+ return null;
36492
+ },
36493
+ handleHotUpdate(ctx) {
36494
+ for (const id in idToLoaderModulesMap) {
36495
+ const { base, pattern } = idToLoaderModulesMap[id];
36496
+ const isLoaderFile = vite.normalizePath(ctx.file) === id;
36497
+ if (isLoaderFile) {
36498
+ delete idToLoaderModulesMap[id];
36499
+ }
36500
+ if (isLoaderFile || pattern && micromatch_1.isMatch(path$p.relative(base, ctx.file), pattern)) {
36501
+ ctx.modules.push(server.moduleGraph.getModuleById(id));
36502
+ }
36503
+ }
36504
+ }
36505
+ };
36506
+
36434
36507
  var __defProp$1 = Object.defineProperty;
36435
36508
  var __defProps$1 = Object.defineProperties;
36436
36509
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
@@ -36624,7 +36697,12 @@ function createVitePressPlugin(root, siteConfig, ssr = false, pageToHashMap, cli
36624
36697
  }
36625
36698
  }
36626
36699
  };
36627
- return [vitePressPlugin, vuePlugin, ...(userViteConfig == null ? void 0 : userViteConfig.plugins) || []];
36700
+ return [
36701
+ vitePressPlugin,
36702
+ vuePlugin,
36703
+ ...(userViteConfig == null ? void 0 : userViteConfig.plugins) || [],
36704
+ staticDataPlugin
36705
+ ];
36628
36706
  }
36629
36707
 
36630
36708
  async function createServer(root = process.cwd(), serverOptions = {}) {
@@ -65020,6 +65098,7 @@ async function serve(options = {}) {
65020
65098
  }
65021
65099
 
65022
65100
  exports.build = build;
65101
+ exports.createMarkdownRenderer = createMarkdownRenderer;
65023
65102
  exports.createServer = createServer;
65024
65103
  exports.defineConfig = defineConfig;
65025
65104
  exports.resolveConfig = resolveConfig;
@@ -0,0 +1,163 @@
1
+ import { AliasOptions } from 'vite';
2
+ import anchor from 'markdown-it-anchor';
3
+ import { BuildOptions } from 'vite';
4
+ import MarkdownIt from 'markdown-it';
5
+ import { Options } from '@vitejs/plugin-vue';
6
+ import { ServerOptions } from 'vite';
7
+ import { UserConfig as UserConfig_2 } from 'vite';
8
+ import { ViteDevServer } from 'vite';
9
+
10
+ export declare function build(root: string, buildOptions?: BuildOptions & {
11
+ mpa?: string;
12
+ }): Promise<void>;
13
+
14
+ export declare const createMarkdownRenderer: (srcDir: string, options?: MarkdownOptions) => MarkdownRenderer;
15
+
16
+ export declare function createServer(root?: string, serverOptions?: ServerOptions): Promise<ViteDevServer>;
17
+
18
+ /**
19
+ * Type config helper
20
+ */
21
+ export declare function defineConfig(config: RawConfigExports): RawConfigExports;
22
+
23
+ export declare type HeadConfig =
24
+ | [string, Record<string, string>]
25
+ | [string, Record<string, string>, string]
26
+
27
+ export declare interface Header {
28
+ level: number
29
+ title: string
30
+ slug: string
31
+ }
32
+
33
+ export declare interface LocaleConfig {
34
+ lang: string
35
+ title?: string
36
+ description?: string
37
+ head?: HeadConfig[]
38
+ label?: string
39
+ selectText?: string
40
+ }
41
+
42
+ export declare interface MarkdownOptions extends MarkdownIt.Options {
43
+ lineNumbers?: boolean;
44
+ config?: (md: MarkdownIt) => void;
45
+ anchor?: {
46
+ permalink?: anchor.AnchorOptions['permalink'];
47
+ };
48
+ attrs?: {
49
+ leftDelimiter?: string;
50
+ rightDelimiter?: string;
51
+ allowedAttributes?: string[];
52
+ };
53
+ toc?: any;
54
+ externalLinks?: Record<string, string>;
55
+ }
56
+
57
+ export declare interface MarkdownParsedData {
58
+ hoistedTags?: string[];
59
+ links?: string[];
60
+ headers?: Header[];
61
+ }
62
+
63
+ export declare interface MarkdownRenderer {
64
+ __data: MarkdownParsedData;
65
+ render: (src: string, env?: any) => {
66
+ html: string;
67
+ data: any;
68
+ };
69
+ }
70
+
71
+ export declare type RawConfigExports = UserConfig | Promise<UserConfig> | (() => UserConfig | Promise<UserConfig>);
72
+
73
+ export declare function resolveConfig(root?: string, command?: 'serve' | 'build', mode?: string): Promise<SiteConfig>;
74
+
75
+ export declare function resolveSiteData(root: string, userConfig?: UserConfig, command?: 'serve' | 'build', mode?: string): Promise<SiteData>;
76
+
77
+ export declare function resolveSiteDataByRoute(siteData: SiteData, route: string): SiteData;
78
+
79
+ export declare function serve(options?: ServeOptions): Promise<void>;
80
+
81
+ export declare interface ServeOptions {
82
+ root?: string;
83
+ port?: number;
84
+ }
85
+
86
+ export declare interface SiteConfig<ThemeConfig = any> {
87
+ root: string;
88
+ srcDir: string;
89
+ site: SiteData<ThemeConfig>;
90
+ configPath: string | undefined;
91
+ themeDir: string;
92
+ outDir: string;
93
+ tempDir: string;
94
+ alias: AliasOptions;
95
+ pages: string[];
96
+ markdown: MarkdownOptions | undefined;
97
+ vue: Options | undefined;
98
+ vite: UserConfig_2 | undefined;
99
+ mpa: boolean;
100
+ }
101
+
102
+ export declare interface SiteData<ThemeConfig = any> {
103
+ base: string
104
+ /**
105
+ * Language of the site as it should be set on the `html` element.
106
+ * @example `en-US`, `zh-CN`
107
+ */
108
+ lang: string
109
+ title: string
110
+ description: string
111
+ head: HeadConfig[]
112
+ themeConfig: ThemeConfig
113
+ locales: Record<string, LocaleConfig>
114
+ /**
115
+ * Available locales for the site when it has defined `locales` in its
116
+ * `themeConfig`. This object is otherwise empty. Keys are paths like `/` or
117
+ * `/zh/`.
118
+ */
119
+ langs: Record<
120
+ string,
121
+ {
122
+ /**
123
+ * Lang attribute as set on the `<html>` element.
124
+ * @example `en-US`, `zh-CN`
125
+ */
126
+ lang: string
127
+ /**
128
+ * Label to display in the language menu.
129
+ * @example `English`, `简体中文`
130
+ */
131
+ label: string
132
+ }
133
+ >
134
+ }
135
+
136
+ export declare interface UserConfig<ThemeConfig = any> {
137
+ extends?: RawConfigExports;
138
+ lang?: string;
139
+ base?: string;
140
+ title?: string;
141
+ description?: string;
142
+ head?: HeadConfig[];
143
+ themeConfig?: ThemeConfig;
144
+ locales?: Record<string, LocaleConfig>;
145
+ markdown?: MarkdownOptions;
146
+ /**
147
+ * Opitons to pass on to `@vitejs/plugin-vue`
148
+ */
149
+ vue?: Options;
150
+ /**
151
+ * Vite config
152
+ */
153
+ vite?: UserConfig_2;
154
+ srcDir?: string;
155
+ srcExclude?: string[];
156
+ /**
157
+ * Enable MPA / zero-JS mode
158
+ * @experimental
159
+ */
160
+ mpa?: boolean;
161
+ }
162
+
163
+ export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitepress",
3
- "version": "0.20.2",
3
+ "version": "0.20.6",
4
4
  "description": "Vite & Vue powered static site generator",
5
5
  "main": "dist/node/index.js",
6
6
  "typings": "types/index.d.ts",
@@ -44,10 +44,10 @@
44
44
  "dependencies": {
45
45
  "@docsearch/css": "^3.0.0-alpha.41",
46
46
  "@docsearch/js": "^3.0.0-alpha.41",
47
- "@vitejs/plugin-vue": "^1.10.1",
47
+ "@vitejs/plugin-vue": "^2.0.0",
48
48
  "prismjs": "^1.25.0",
49
- "vite": "^2.7.0-beta.8",
50
- "vue": "^3.2.24"
49
+ "vite": "^2.7.0",
50
+ "vue": "^3.2.26"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@microsoft/api-extractor": "^7.18.9",
@@ -63,6 +63,7 @@
63
63
  "@types/koa-static": "^4.0.1",
64
64
  "@types/lru-cache": "^5.1.0",
65
65
  "@types/markdown-it": "^12.0.1",
66
+ "@types/micromatch": "^4.0.2",
66
67
  "@types/node": "^15.6.1",
67
68
  "@types/polka": "^0.5.3",
68
69
  "chalk": "^4.1.1",
@@ -75,6 +76,7 @@
75
76
  "esbuild": "^0.13.4",
76
77
  "escape-html": "^1.0.3",
77
78
  "execa": "^5.0.0",
79
+ "fast-glob": "^3.2.7",
78
80
  "fs-extra": "^10.0.0",
79
81
  "globby": "^11.0.3",
80
82
  "gray-matter": "^4.0.3",
@@ -87,6 +89,7 @@
87
89
  "markdown-it-container": "^3.0.0",
88
90
  "markdown-it-emoji": "^2.0.0",
89
91
  "markdown-it-table-of-contents": "^0.5.2",
92
+ "micromatch": "^4.0.4",
90
93
  "minimist": "^1.2.5",
91
94
  "npm-run-all": "^4.1.5",
92
95
  "ora": "^5.4.0",