vitepress 0.20.9 → 0.21.2

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.
@@ -9,8 +9,8 @@ const getDefaultRoute = () => ({
9
9
  component: null,
10
10
  // this will be set upon initial page load, which is before
11
11
  // the app is mounted, so it's guaranteed to be available in
12
- // components
13
- data: null
12
+ // components. We just need enough data for 404 pages to render.
13
+ data: { frontmatter: {} }
14
14
  });
15
15
  export function createRouter(loadPageModule, fallbackComponent) {
16
16
  const route = reactive(getDefaultRoute());
@@ -55,7 +55,7 @@ const { lang } = useData()
55
55
  // if the user has multiple locales, the search results should be filtered
56
56
  // based on the language
57
57
  const facetFilters: string[] = props.multilang
58
- ? ['language:' + lang.value]
58
+ ? ['lang:' + lang.value]
59
59
  : []
60
60
 
61
61
  if (props.options.searchParameters?.facetFilters) {
@@ -66,10 +66,10 @@ watch(
66
66
  lang,
67
67
  (newLang, oldLang) => {
68
68
  const index = facetFilters.findIndex(
69
- (filter) => filter === 'language:' + oldLang
69
+ (filter) => filter === 'lang:' + oldLang
70
70
  )
71
71
  if (index > -1) {
72
- facetFilters.splice(index, 1, 'language:' + newLang)
72
+ facetFilters.splice(index, 1, 'lang:' + newLang)
73
73
  }
74
74
  }
75
75
  )
@@ -24,6 +24,9 @@ const { site, theme, localePath } = useData()
24
24
  font-size: 1.3rem;
25
25
  font-weight: 600;
26
26
  color: var(--c-text);
27
+ display: flex;
28
+ justify-content: center;
29
+ align-items: center;
27
30
  }
28
31
 
29
32
  .nav-bar-title:hover {
@@ -15,7 +15,7 @@ export function useSideBar() {
15
15
  if (frontSidebar === false) {
16
16
  return [];
17
17
  }
18
- // if it's `atuo`, render headers of the current page
18
+ // if it's `auto`, render headers of the current page
19
19
  if (frontSidebar === 'auto') {
20
20
  return resolveAutoSidebar(headers, sidebarDepth);
21
21
  }
package/dist/node/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var serve = require('./serve-61783397.js');
3
+ var serve = require('./serve-3fb9b386.js');
4
4
  require('fs');
5
5
  require('path');
6
6
  require('url');
@@ -15,10 +15,162 @@ export declare const createMarkdownRenderer: (srcDir: string, options?: Markdown
15
15
 
16
16
  export declare function createServer(root?: string, serverOptions?: ServerOptions): Promise<ViteDevServer>;
17
17
 
18
+ export declare namespace DefaultTheme {
19
+ export interface Config {
20
+ logo?: string
21
+ nav?: NavItem[] | false
22
+ sidebar?: SideBarConfig | MultiSideBarConfig
23
+
24
+ /**
25
+ * GitHub repository following the format <user>/<project>.
26
+ *
27
+ * @example `"vuejs/vue-next"`
28
+ */
29
+ repo?: string
30
+
31
+ /**
32
+ * Customize the header label. Defaults to GitHub/Gitlab/Bitbucket
33
+ * depending on the provided repo.
34
+ *
35
+ * @example `"Contribute!"`
36
+ */
37
+ repoLabel?: string
38
+
39
+ /**
40
+ * If your docs are in a different repository from your main project.
41
+ *
42
+ * @example `"vuejs/docs-next"`
43
+ */
44
+ docsRepo?: string
45
+
46
+ /**
47
+ * If your docs are not at the root of the repo.
48
+ *
49
+ * @example `"docs"`
50
+ */
51
+ docsDir?: string
52
+
53
+ /**
54
+ * If your docs are in a different branch. Defaults to `master`.
55
+ *
56
+ * @example `"next"`
57
+ */
58
+ docsBranch?: string
59
+
60
+ /**
61
+ * Enable links to edit pages at the bottom of the page.
62
+ */
63
+ editLinks?: boolean
64
+
65
+ /**
66
+ * Custom text for edit link. Defaults to "Edit this page".
67
+ */
68
+ editLinkText?: string
69
+
70
+ /**
71
+ * Show last updated time at the bottom of the page. Defaults to `false`.
72
+ * If given a string, it will be displayed as a prefix (default value:
73
+ * "Last Updated").
74
+ */
75
+ lastUpdated?: string | boolean
76
+
77
+ prevLinks?: boolean
78
+ nextLinks?: boolean
79
+
80
+ locales?: Record<string, LocaleConfig & Omit<Config, 'locales'>>
81
+
82
+ algolia?: AlgoliaSearchOptions
83
+
84
+ carbonAds?: {
85
+ carbon: string
86
+ custom?: string
87
+ placement: string
88
+ }
89
+ }
90
+
91
+ // navbar --------------------------------------------------------------------
92
+
93
+ export type NavItem = NavItemWithLink | NavItemWithChildren
94
+
95
+ export interface NavItemBase {
96
+ text: string
97
+ target?: string
98
+ rel?: string
99
+ ariaLabel?: string
100
+ activeMatch?: string
101
+ }
102
+
103
+ export interface NavItemWithLink extends NavItemBase {
104
+ link: string
105
+ }
106
+
107
+ export interface NavItemWithChildren extends NavItemBase {
108
+ items: NavItemWithLink[]
109
+ }
110
+
111
+ // sidebar -------------------------------------------------------------------
112
+
113
+ export type SideBarConfig = SideBarItem[] | 'auto' | false
114
+
115
+ export interface MultiSideBarConfig {
116
+ [path: string]: SideBarConfig
117
+ }
118
+
119
+ export type SideBarItem = SideBarLink | SideBarGroup
120
+
121
+ export interface SideBarLink {
122
+ text: string
123
+ link: string
124
+ }
125
+
126
+ export interface SideBarGroup {
127
+ text: string
128
+ link?: string
129
+
130
+ /**
131
+ * @default false
132
+ */
133
+ collapsable?: boolean
134
+
135
+ children: SideBarItem[]
136
+ }
137
+
138
+ // algolia ------------------------------------------------------------------
139
+ // partially copied from @docsearch/react/dist/esm/DocSearch.d.ts
140
+ export interface AlgoliaSearchOptions {
141
+ appId?: string
142
+ apiKey: string
143
+ indexName: string
144
+ placeholder?: string
145
+ searchParameters?: any
146
+ disableUserPersonalization?: boolean
147
+ initialQuery?: string
148
+ }
149
+
150
+ // locales -------------------------------------------------------------------
151
+
152
+ export interface LocaleConfig {
153
+ /**
154
+ * Text for the language dropdown.
155
+ */
156
+ selectText?: string
157
+
158
+ /**
159
+ * Label for this locale in the language dropdown.
160
+ */
161
+ label?: string
162
+ }
163
+ }
164
+
18
165
  /**
19
166
  * Type config helper
20
167
  */
21
- export declare function defineConfig(config: RawConfigExports): RawConfigExports;
168
+ export declare function defineConfig(config: UserConfig<DefaultTheme.Config>): UserConfig<DefaultTheme.Config>;
169
+
170
+ /**
171
+ * Type config helper for custom theme config
172
+ */
173
+ export declare function defineConfigWithTheme<ThemeConfig>(config: UserConfig<ThemeConfig>): UserConfig<ThemeConfig>;
22
174
 
23
175
  export declare type HeadConfig =
24
176
  | [string, Record<string, string>]
@@ -60,15 +212,13 @@ export declare interface MarkdownParsedData {
60
212
  headers?: Header[];
61
213
  }
62
214
 
63
- export declare interface MarkdownRenderer {
215
+ export declare interface MarkdownRenderer extends MarkdownIt {
216
+ __path: string;
217
+ __relativePath: string;
64
218
  __data: MarkdownParsedData;
65
- render: (src: string, env?: any) => {
66
- html: string;
67
- data: any;
68
- };
69
219
  }
70
220
 
71
- export declare type RawConfigExports = UserConfig | Promise<UserConfig> | (() => UserConfig | Promise<UserConfig>);
221
+ export declare type RawConfigExports<ThemeConfig = any> = UserConfig<ThemeConfig> | Promise<UserConfig<ThemeConfig>> | (() => UserConfig<ThemeConfig> | Promise<UserConfig<ThemeConfig>>);
72
222
 
73
223
  export declare function resolveConfig(root?: string, command?: 'serve' | 'build', mode?: string): Promise<SiteConfig>;
74
224
 
@@ -130,7 +280,7 @@ export declare interface SiteData<ThemeConfig = any> {
130
280
  }
131
281
 
132
282
  export declare interface UserConfig<ThemeConfig = any> {
133
- extends?: RawConfigExports;
283
+ extends?: RawConfigExports<ThemeConfig>;
134
284
  lang?: string;
135
285
  base?: string;
136
286
  title?: string;
@@ -140,7 +290,7 @@ export declare interface UserConfig<ThemeConfig = any> {
140
290
  locales?: Record<string, LocaleConfig>;
141
291
  markdown?: MarkdownOptions;
142
292
  /**
143
- * Opitons to pass on to `@vitejs/plugin-vue`
293
+ * Options to pass on to `@vitejs/plugin-vue`
144
294
  */
145
295
  vue?: Options;
146
296
  /**
@@ -149,6 +299,7 @@ export declare interface UserConfig<ThemeConfig = any> {
149
299
  vite?: UserConfig_2;
150
300
  srcDir?: string;
151
301
  srcExclude?: string[];
302
+ outDir?: string;
152
303
  shouldPreload?: (link: string, page: string) => boolean;
153
304
  /**
154
305
  * Enable MPA / zero-JS mode
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var serve = require('./serve-61783397.js');
5
+ var serve = require('./serve-3fb9b386.js');
6
6
  require('vite');
7
7
  require('readline');
8
8
  require('assert');
@@ -29,6 +29,7 @@ exports.build = serve.build;
29
29
  exports.createMarkdownRenderer = serve.createMarkdownRenderer;
30
30
  exports.createServer = serve.createServer;
31
31
  exports.defineConfig = serve.defineConfig;
32
+ exports.defineConfigWithTheme = serve.defineConfigWithTheme;
32
33
  exports.resolveConfig = serve.resolveConfig;
33
34
  exports.resolveSiteData = serve.resolveSiteData;
34
35
  exports.resolveSiteDataByRoute = serve.resolveSiteDataByRoute;
@@ -13349,10 +13349,14 @@ const resolve = (root, file) => vite.normalizePath(path__default["default"].reso
13349
13349
  function defineConfig(config) {
13350
13350
  return config;
13351
13351
  }
13352
+ function defineConfigWithTheme(config) {
13353
+ return config;
13354
+ }
13352
13355
  async function resolveConfig(root = process.cwd(), command = "serve", mode = "development") {
13353
13356
  const [userConfig, configPath] = await resolveUserConfig(root, command, mode);
13354
13357
  const site = await resolveSiteData(root, userConfig);
13355
13358
  const srcDir = path__default["default"].resolve(root, userConfig.srcDir || ".");
13359
+ const outDir = userConfig.outDir ? path__default["default"].resolve(root, userConfig.outDir) : resolve(root, "dist");
13356
13360
  const userThemeDir = resolve(root, "theme");
13357
13361
  const themeDir = await lib$1.pathExists(userThemeDir) ? userThemeDir : DEFAULT_THEME_PATH;
13358
13362
  const pages = (await globby(["**.md"], {
@@ -13366,8 +13370,8 @@ async function resolveConfig(root = process.cwd(), command = "serve", mode = "de
13366
13370
  themeDir,
13367
13371
  pages,
13368
13372
  configPath,
13369
- outDir: resolve(root, "dist"),
13370
- tempDir: path__default["default"].resolve(APP_PATH, "temp"),
13373
+ outDir,
13374
+ tempDir: resolve(root, ".temp"),
13371
13375
  markdown: userConfig.markdown,
13372
13376
  alias: resolveAliases(themeDir),
13373
13377
  vue: userConfig.vue,
@@ -13377,7 +13381,7 @@ async function resolveConfig(root = process.cwd(), command = "serve", mode = "de
13377
13381
  };
13378
13382
  return config;
13379
13383
  }
13380
- const supportedConfigExtensions = ["js", "ts", ".mjs", "mts"];
13384
+ const supportedConfigExtensions = ["js", "ts", "mjs", "mts"];
13381
13385
  async function resolveUserConfig(root, command, mode) {
13382
13386
  var _a;
13383
13387
  let configPath;
@@ -34187,10 +34191,11 @@ var require$$0$4 = {
34187
34191
  };
34188
34192
 
34189
34193
  const parseEmojis = (str) => {
34190
- return String(str).replace(/:(.+?):/g, (placeholder, key) => require$$0$4[key] || placeholder);
34194
+ return str.replace(/:(.+?):/g, (placeholder, key) => require$$0$4[key] || placeholder);
34191
34195
  };
34192
- const unescapeHtml = (html) => String(html).replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&#x3A;/g, ":").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
34193
- const removeMarkdownTokens = (str) => String(str).replace(/(\[(.[^\]]+)\]\((.[^)]+)\))/g, "$2").replace(/(`|\*{1,3}|_)(.*?[^\\])\1/g, "$2").replace(/(\\)(\*|_|`|\!|<|\$)/g, "$2");
34196
+ const unescapeHtml = (html) => html.replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&#x3A;/g, ":").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
34197
+ const removeMarkdownTokens = (str) => str.replace(/(\[(.[^\]]+)\]\((.[^)]+)\))/g, "$2").replace(/(`|\*{1,3}|_)(.*?[^\\])\1/g, "$2").replace(/(\\)(\*|_|`|\!|<|\$)/g, "$2");
34198
+ const remvoeCustomAnchor = (str) => str.replace(/\{#([a-z0-9\-_]+?)\}\s*$/, "");
34194
34199
  const trim = (str) => str.trim();
34195
34200
  const removeNonCodeWrappedHTML = (str) => {
34196
34201
  return String(str).replace(/(^|[^><`\\])<.*>([^><`]|$)/g, "$1$2");
@@ -34204,7 +34209,7 @@ const compose = (...processors) => {
34204
34209
  return (str) => next(prev(str));
34205
34210
  });
34206
34211
  };
34207
- const parseHeader = compose(unescapeHtml, parseEmojis, removeMarkdownTokens, trim);
34212
+ const parseHeader = compose(unescapeHtml, parseEmojis, remvoeCustomAnchor, removeMarkdownTokens, trim);
34208
34213
  const deeplyParseHeader = compose(removeNonCodeWrappedHTML, parseHeader);
34209
34214
 
34210
34215
  /*!
@@ -34901,7 +34906,7 @@ var markdownItContainer = function container_plugin(md, name, options) {
34901
34906
  };
34902
34907
 
34903
34908
  const containerPlugin = (md) => {
34904
- md.use(...createContainer("tip", "TIP")).use(...createContainer("info", "INFO")).use(...createContainer("warning", "WARNING")).use(...createContainer("danger", "WARNING")).use(markdownItContainer, "v-pre", {
34909
+ md.use(...createContainer("tip", "TIP")).use(...createContainer("info", "INFO")).use(...createContainer("warning", "WARNING")).use(...createContainer("danger", "WARNING")).use(...createContainer("details", "Details")).use(markdownItContainer, "v-pre", {
34905
34910
  render: (tokens, idx) => tokens[idx].nesting === 1 ? `<div v-pre>
34906
34911
  ` : `</div>
34907
34912
  `
@@ -34916,10 +34921,15 @@ function createContainer(klass, defaultTitle) {
34916
34921
  const token = tokens[idx];
34917
34922
  const info = token.info.trim().slice(klass.length).trim();
34918
34923
  if (token.nesting === 1) {
34924
+ if (klass === "details") {
34925
+ return `<details class="${klass} custom-block">${info ? `<summary>${info}</summary>` : ""}
34926
+ `;
34927
+ }
34919
34928
  return `<div class="${klass} custom-block"><p class="custom-block-title">${info || defaultTitle}</p>
34920
34929
  `;
34921
34930
  } else {
34922
- return `</div>
34931
+ return klass === "details" ? `</details>
34932
+ ` : `</div>
34923
34933
  `;
34924
34934
  }
34925
34935
  }
@@ -35075,6 +35085,9 @@ const linkPlugin = (md, externalAttrs) => {
35075
35085
  Object.entries(externalAttrs).forEach(([key, val]) => {
35076
35086
  token.attrSet(key, val);
35077
35087
  });
35088
+ if (url.replace(EXTERNAL_URL_RE, "").startsWith("//localhost:")) {
35089
+ pushLink(url);
35090
+ }
35078
35091
  } else if (!url.startsWith("#") && !url.startsWith("mailto:")) {
35079
35092
  normalizeHref(hrefAttr);
35080
35093
  }
@@ -35102,14 +35115,17 @@ const linkPlugin = (md, externalAttrs) => {
35102
35115
  if (!url.startsWith("/") && !/^\.\//.test(url)) {
35103
35116
  url = "./" + url;
35104
35117
  }
35118
+ pushLink(url.replace(/\.html$/, ""));
35119
+ hrefAttr[1] = decodeURI(url);
35120
+ }
35121
+ function pushLink(link) {
35105
35122
  const data = md.__data;
35106
35123
  const links = data.links || (data.links = []);
35107
- links.push(url.replace(/\.html$/, ""));
35108
- hrefAttr[1] = decodeURI(url);
35124
+ links.push(link);
35109
35125
  }
35110
35126
  };
35111
35127
 
35112
- const extractHeaderPlugin = (md, include = ["h2", "h3"]) => {
35128
+ const headingPlugin = (md, include = ["h2", "h3"]) => {
35113
35129
  md.renderer.rules.heading_open = (tokens, i, options, env, self) => {
35114
35130
  const token = tokens[i];
35115
35131
  if (include.includes(token.tag)) {
@@ -36278,7 +36294,7 @@ const createMarkdownRenderer = (srcDir, options = {}) => {
36278
36294
  linkify: true,
36279
36295
  highlight
36280
36296
  }, options));
36281
- md.use(componentPlugin).use(highlightLinePlugin).use(preWrapperPlugin).use(snippetPlugin, srcDir).use(hoistPlugin).use(containerPlugin).use(extractHeaderPlugin).use(linkPlugin, __spreadValues$2({
36297
+ md.use(componentPlugin).use(highlightLinePlugin).use(preWrapperPlugin).use(snippetPlugin, srcDir).use(hoistPlugin).use(containerPlugin).use(headingPlugin).use(linkPlugin, __spreadValues$2({
36282
36298
  target: "_blank",
36283
36299
  rel: "noopener noreferrer"
36284
36300
  }, options.externalLinks)).use(markdownItAttrs, options.attrs).use(b, __spreadValues$2({
@@ -36295,16 +36311,6 @@ const createMarkdownRenderer = (srcDir, options = {}) => {
36295
36311
  if (options.lineNumbers) {
36296
36312
  md.use(lineNumberPlugin);
36297
36313
  }
36298
- const render = md.render;
36299
- const wrappedRender = (src) => {
36300
- md.__data = {};
36301
- const html = render.call(md, src);
36302
- return {
36303
- html,
36304
- data: md.__data
36305
- };
36306
- };
36307
- md.render = wrappedRender;
36308
36314
  return md;
36309
36315
  };
36310
36316
 
@@ -36336,7 +36342,11 @@ function createMarkdownToVueRenderFn(srcDir, options = {}, pages, userDefines, i
36336
36342
  return content2;
36337
36343
  });
36338
36344
  const { content, data: frontmatter } = grayMatter(src);
36339
- let { html, data } = md.render(content);
36345
+ md.__path = file;
36346
+ md.__relativePath = relativePath;
36347
+ md.__data = {};
36348
+ let html = md.render(content);
36349
+ const data = md.__data;
36340
36350
  if (isBuild) {
36341
36351
  html = html.replace(/\bimport\.meta/g, "import.<wbr/>meta").replace(/\bprocess\.env/g, "process.<wbr/>env");
36342
36352
  if (userDefineRegex) {
@@ -36344,17 +36354,24 @@ function createMarkdownToVueRenderFn(srcDir, options = {}, pages, userDefines, i
36344
36354
  }
36345
36355
  }
36346
36356
  const deadLinks = [];
36357
+ const recordDeadLink = (url) => {
36358
+ console.warn(source.yellow(`
36359
+ (!) Found dead link ${source.cyan(url)} in file ${source.white.dim(file)}`));
36360
+ deadLinks.push(url);
36361
+ };
36347
36362
  if (data.links) {
36348
36363
  const dir2 = path__default["default"].dirname(file);
36349
36364
  for (let url of data.links) {
36365
+ if (url.replace(EXTERNAL_URL_RE, "").startsWith("//localhost:")) {
36366
+ recordDeadLink(url);
36367
+ continue;
36368
+ }
36350
36369
  url = url.replace(/[?#].*$/, "").replace(/\.(html|md)$/, "");
36351
36370
  if (url.endsWith("/"))
36352
36371
  url += `index`;
36353
- const resolved = slash(url.startsWith("/") ? url.slice(1) : path__default["default"].relative(srcDir, path__default["default"].resolve(dir2, url)));
36372
+ const resolved = decodeURIComponent(slash(url.startsWith("/") ? url.slice(1) : path__default["default"].relative(srcDir, path__default["default"].resolve(dir2, url))));
36354
36373
  if (!pages.includes(resolved) && !fs__default["default"].existsSync(path__default["default"].resolve(dir2, publicDir, `${resolved}.html`))) {
36355
- console.warn(source.yellow(`
36356
- (!) Found dead link ${source.cyan(url)} in file ${source.white.dim(file)}`));
36357
- deadLinks.push(url);
36374
+ recordDeadLink(url);
36358
36375
  }
36359
36376
  }
36360
36377
  }
@@ -36362,7 +36379,7 @@ function createMarkdownToVueRenderFn(srcDir, options = {}, pages, userDefines, i
36362
36379
  title: inferTitle(frontmatter, content),
36363
36380
  description: inferDescription(frontmatter),
36364
36381
  frontmatter,
36365
- headers: data.headers,
36382
+ headers: data.headers || [],
36366
36383
  relativePath,
36367
36384
  lastUpdated: Math.round(fs__default["default"].statSync(file).mtimeMs)
36368
36385
  };
@@ -36594,7 +36611,11 @@ function createVitePressPlugin(root, siteConfig, ssr = false, pageToHashMap, cli
36594
36611
  },
36595
36612
  load(id) {
36596
36613
  if (id === SITE_DATA_REQUEST_PATH) {
36597
- return `export default ${JSON.stringify(JSON.stringify(siteData))}`;
36614
+ let data = siteData;
36615
+ if (config.command === "build") {
36616
+ data = __spreadProps$1(__spreadValues$1({}, siteData), { head: [] });
36617
+ }
36618
+ return `export default ${JSON.stringify(JSON.stringify(data))}`;
36598
36619
  }
36599
36620
  },
36600
36621
  transform(code, id) {
@@ -40087,7 +40108,7 @@ async function renderPage(config, page, result, appChunk, cssChunk, pageToHashMa
40087
40108
  ${stylesheetLink}
40088
40109
  ${preloadLinksString}
40089
40110
  ${prefetchLinkString}
40090
- ${renderHead(head)}
40111
+ ${await renderHead(head)}
40091
40112
  </head>
40092
40113
  <body>
40093
40114
  <div id="app">${content}</div>
@@ -40111,14 +40132,19 @@ function resolvePageImports(config, page, result, appChunk) {
40111
40132
  ];
40112
40133
  }
40113
40134
  function renderHead(head) {
40114
- return head.map(([tag, attrs = {}, innerHTML = ""]) => {
40135
+ return Promise.all(head.map(async ([tag, attrs = {}, innerHTML = ""]) => {
40115
40136
  const openTag = `<${tag}${renderAttrs(attrs)}>`;
40116
40137
  if (tag !== "link" && tag !== "meta") {
40138
+ if (tag === "script") {
40139
+ innerHTML = (await vite.transformWithEsbuild(innerHTML, "inline-script.js", {
40140
+ minify: true
40141
+ })).code.trim();
40142
+ }
40117
40143
  return `${openTag}${innerHTML}</${tag}>`;
40118
40144
  } else {
40119
40145
  return openTag;
40120
40146
  }
40121
- }).join("\n ");
40147
+ })).then((tags) => tags.join("\n "));
40122
40148
  }
40123
40149
  function renderAttrs(attrs) {
40124
40150
  return Object.keys(attrs).map((key) => {
@@ -65090,9 +65116,20 @@ class Polka extends Router {
65090
65116
 
65091
65117
  var polka = opts => new Polka(opts);
65092
65118
 
65119
+ function trimChar(str, char) {
65120
+ while (str.charAt(0) === char) {
65121
+ str = str.substring(1);
65122
+ }
65123
+ while (str.charAt(str.length - 1) === char) {
65124
+ str = str.substring(0, str.length - 1);
65125
+ }
65126
+ return str;
65127
+ }
65093
65128
  async function serve(options = {}) {
65129
+ var _a, _b;
65094
65130
  const port = options.port !== void 0 ? options.port : 5e3;
65095
65131
  const site = await resolveConfig(options.root, "serve", "production");
65132
+ const base = trimChar((_b = (_a = site == null ? void 0 : site.site) == null ? void 0 : _a.base) != null ? _b : "", "/");
65096
65133
  const compress = compression$1();
65097
65134
  const serve2 = sirv(site.outDir, {
65098
65135
  etag: true,
@@ -65105,18 +65142,28 @@ async function serve(options = {}) {
65105
65142
  }
65106
65143
  }
65107
65144
  });
65108
- polka().use(compress, serve2).listen(port, (err) => {
65109
- if (err)
65110
- throw err;
65111
- console.log(`Built site served at http://localhost:${port}/
65145
+ if (base) {
65146
+ polka().use(base, compress, serve2).listen(port, (err) => {
65147
+ if (err)
65148
+ throw err;
65149
+ console.log(`Built site served at http://localhost:${port}/${base}/
65112
65150
  `);
65113
- });
65151
+ });
65152
+ } else {
65153
+ polka().use(compress, serve2).listen(port, (err) => {
65154
+ if (err)
65155
+ throw err;
65156
+ console.log(`Built site served at http://localhost:${port}/
65157
+ `);
65158
+ });
65159
+ }
65114
65160
  }
65115
65161
 
65116
65162
  exports.build = build;
65117
65163
  exports.createMarkdownRenderer = createMarkdownRenderer;
65118
65164
  exports.createServer = createServer;
65119
65165
  exports.defineConfig = defineConfig;
65166
+ exports.defineConfigWithTheme = defineConfigWithTheme;
65120
65167
  exports.resolveConfig = resolveConfig;
65121
65168
  exports.resolveSiteData = resolveSiteData;
65122
65169
  exports.resolveSiteDataByRoute = resolveSiteDataByRoute;
@@ -15,10 +15,162 @@ export declare const createMarkdownRenderer: (srcDir: string, options?: Markdown
15
15
 
16
16
  export declare function createServer(root?: string, serverOptions?: ServerOptions): Promise<ViteDevServer>;
17
17
 
18
+ export declare namespace DefaultTheme {
19
+ export interface Config {
20
+ logo?: string
21
+ nav?: NavItem[] | false
22
+ sidebar?: SideBarConfig | MultiSideBarConfig
23
+
24
+ /**
25
+ * GitHub repository following the format <user>/<project>.
26
+ *
27
+ * @example `"vuejs/vue-next"`
28
+ */
29
+ repo?: string
30
+
31
+ /**
32
+ * Customize the header label. Defaults to GitHub/Gitlab/Bitbucket
33
+ * depending on the provided repo.
34
+ *
35
+ * @example `"Contribute!"`
36
+ */
37
+ repoLabel?: string
38
+
39
+ /**
40
+ * If your docs are in a different repository from your main project.
41
+ *
42
+ * @example `"vuejs/docs-next"`
43
+ */
44
+ docsRepo?: string
45
+
46
+ /**
47
+ * If your docs are not at the root of the repo.
48
+ *
49
+ * @example `"docs"`
50
+ */
51
+ docsDir?: string
52
+
53
+ /**
54
+ * If your docs are in a different branch. Defaults to `master`.
55
+ *
56
+ * @example `"next"`
57
+ */
58
+ docsBranch?: string
59
+
60
+ /**
61
+ * Enable links to edit pages at the bottom of the page.
62
+ */
63
+ editLinks?: boolean
64
+
65
+ /**
66
+ * Custom text for edit link. Defaults to "Edit this page".
67
+ */
68
+ editLinkText?: string
69
+
70
+ /**
71
+ * Show last updated time at the bottom of the page. Defaults to `false`.
72
+ * If given a string, it will be displayed as a prefix (default value:
73
+ * "Last Updated").
74
+ */
75
+ lastUpdated?: string | boolean
76
+
77
+ prevLinks?: boolean
78
+ nextLinks?: boolean
79
+
80
+ locales?: Record<string, LocaleConfig & Omit<Config, 'locales'>>
81
+
82
+ algolia?: AlgoliaSearchOptions
83
+
84
+ carbonAds?: {
85
+ carbon: string
86
+ custom?: string
87
+ placement: string
88
+ }
89
+ }
90
+
91
+ // navbar --------------------------------------------------------------------
92
+
93
+ export type NavItem = NavItemWithLink | NavItemWithChildren
94
+
95
+ export interface NavItemBase {
96
+ text: string
97
+ target?: string
98
+ rel?: string
99
+ ariaLabel?: string
100
+ activeMatch?: string
101
+ }
102
+
103
+ export interface NavItemWithLink extends NavItemBase {
104
+ link: string
105
+ }
106
+
107
+ export interface NavItemWithChildren extends NavItemBase {
108
+ items: NavItemWithLink[]
109
+ }
110
+
111
+ // sidebar -------------------------------------------------------------------
112
+
113
+ export type SideBarConfig = SideBarItem[] | 'auto' | false
114
+
115
+ export interface MultiSideBarConfig {
116
+ [path: string]: SideBarConfig
117
+ }
118
+
119
+ export type SideBarItem = SideBarLink | SideBarGroup
120
+
121
+ export interface SideBarLink {
122
+ text: string
123
+ link: string
124
+ }
125
+
126
+ export interface SideBarGroup {
127
+ text: string
128
+ link?: string
129
+
130
+ /**
131
+ * @default false
132
+ */
133
+ collapsable?: boolean
134
+
135
+ children: SideBarItem[]
136
+ }
137
+
138
+ // algolia ------------------------------------------------------------------
139
+ // partially copied from @docsearch/react/dist/esm/DocSearch.d.ts
140
+ export interface AlgoliaSearchOptions {
141
+ appId?: string
142
+ apiKey: string
143
+ indexName: string
144
+ placeholder?: string
145
+ searchParameters?: any
146
+ disableUserPersonalization?: boolean
147
+ initialQuery?: string
148
+ }
149
+
150
+ // locales -------------------------------------------------------------------
151
+
152
+ export interface LocaleConfig {
153
+ /**
154
+ * Text for the language dropdown.
155
+ */
156
+ selectText?: string
157
+
158
+ /**
159
+ * Label for this locale in the language dropdown.
160
+ */
161
+ label?: string
162
+ }
163
+ }
164
+
18
165
  /**
19
166
  * Type config helper
20
167
  */
21
- export declare function defineConfig(config: RawConfigExports): RawConfigExports;
168
+ export declare function defineConfig(config: UserConfig<DefaultTheme.Config>): UserConfig<DefaultTheme.Config>;
169
+
170
+ /**
171
+ * Type config helper for custom theme config
172
+ */
173
+ export declare function defineConfigWithTheme<ThemeConfig>(config: UserConfig<ThemeConfig>): UserConfig<ThemeConfig>;
22
174
 
23
175
  export declare type HeadConfig =
24
176
  | [string, Record<string, string>]
@@ -60,15 +212,13 @@ export declare interface MarkdownParsedData {
60
212
  headers?: Header[];
61
213
  }
62
214
 
63
- export declare interface MarkdownRenderer {
215
+ export declare interface MarkdownRenderer extends MarkdownIt {
216
+ __path: string;
217
+ __relativePath: string;
64
218
  __data: MarkdownParsedData;
65
- render: (src: string, env?: any) => {
66
- html: string;
67
- data: any;
68
- };
69
219
  }
70
220
 
71
- export declare type RawConfigExports = UserConfig | Promise<UserConfig> | (() => UserConfig | Promise<UserConfig>);
221
+ export declare type RawConfigExports<ThemeConfig = any> = UserConfig<ThemeConfig> | Promise<UserConfig<ThemeConfig>> | (() => UserConfig<ThemeConfig> | Promise<UserConfig<ThemeConfig>>);
72
222
 
73
223
  export declare function resolveConfig(root?: string, command?: 'serve' | 'build', mode?: string): Promise<SiteConfig>;
74
224
 
@@ -130,7 +280,7 @@ export declare interface SiteData<ThemeConfig = any> {
130
280
  }
131
281
 
132
282
  export declare interface UserConfig<ThemeConfig = any> {
133
- extends?: RawConfigExports;
283
+ extends?: RawConfigExports<ThemeConfig>;
134
284
  lang?: string;
135
285
  base?: string;
136
286
  title?: string;
@@ -140,7 +290,7 @@ export declare interface UserConfig<ThemeConfig = any> {
140
290
  locales?: Record<string, LocaleConfig>;
141
291
  markdown?: MarkdownOptions;
142
292
  /**
143
- * Opitons to pass on to `@vitejs/plugin-vue`
293
+ * Options to pass on to `@vitejs/plugin-vue`
144
294
  */
145
295
  vue?: Options;
146
296
  /**
@@ -149,6 +299,7 @@ export declare interface UserConfig<ThemeConfig = any> {
149
299
  vite?: UserConfig_2;
150
300
  srcDir?: string;
151
301
  srcExclude?: string[];
302
+ outDir?: string;
152
303
  shouldPreload?: (link: string, page: string) => boolean;
153
304
  /**
154
305
  * Enable MPA / zero-JS mode
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitepress",
3
- "version": "0.20.9",
3
+ "version": "0.21.2",
4
4
  "description": "Vite & Vue powered static site generator",
5
5
  "main": "dist/node/index.js",
6
6
  "typings": "types/index.d.ts",
@@ -131,5 +131,6 @@
131
131
  "docs-build": "npm run build && node ./bin/vitepress build docs",
132
132
  "docs-serve": "node ./bin/vitepress serve docs",
133
133
  "ci-docs": "run-s build docs-build"
134
- }
134
+ },
135
+ "readme": "# (WIP) VitePress 📝💨\n\n[![Test](https://github.com/vuejs/vitepress/workflows/Test/badge.svg)](https://github.com/vuejs/vitepress/actions)\n[![npm](https://img.shields.io/npm/v/vitepress)](https://www.npmjs.com/package/vitepress)\n\n---\n\nVitePress is [VuePress](http://vuepress.vuejs.org/)' spiritual successor, built on top of [vite](https://github.com/vuejs/vite).\n\n## Documentation\n\nTo check out docs, visit [vitepress.vuejs.org](https://vitepress.vuejs.org).\n\n## Changelog\n\nDetailed changes for each release are documented in the [CHANGELOG](https://github.com/vuejs/vitepress/blob/master/CHANGELOG.md).\n\n## Contribution\n\nPlease make sure to read the [Contributing Guide](./.github/contributing.md) before making a pull request.\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n\nCopyright (c) 2019-present, Yuxi (Evan) You\n"
135
136
  }
@@ -0,0 +1,146 @@
1
+ export namespace DefaultTheme {
2
+ export interface Config {
3
+ logo?: string
4
+ nav?: NavItem[] | false
5
+ sidebar?: SideBarConfig | MultiSideBarConfig
6
+
7
+ /**
8
+ * GitHub repository following the format <user>/<project>.
9
+ *
10
+ * @example `"vuejs/vue-next"`
11
+ */
12
+ repo?: string
13
+
14
+ /**
15
+ * Customize the header label. Defaults to GitHub/Gitlab/Bitbucket
16
+ * depending on the provided repo.
17
+ *
18
+ * @example `"Contribute!"`
19
+ */
20
+ repoLabel?: string
21
+
22
+ /**
23
+ * If your docs are in a different repository from your main project.
24
+ *
25
+ * @example `"vuejs/docs-next"`
26
+ */
27
+ docsRepo?: string
28
+
29
+ /**
30
+ * If your docs are not at the root of the repo.
31
+ *
32
+ * @example `"docs"`
33
+ */
34
+ docsDir?: string
35
+
36
+ /**
37
+ * If your docs are in a different branch. Defaults to `master`.
38
+ *
39
+ * @example `"next"`
40
+ */
41
+ docsBranch?: string
42
+
43
+ /**
44
+ * Enable links to edit pages at the bottom of the page.
45
+ */
46
+ editLinks?: boolean
47
+
48
+ /**
49
+ * Custom text for edit link. Defaults to "Edit this page".
50
+ */
51
+ editLinkText?: string
52
+
53
+ /**
54
+ * Show last updated time at the bottom of the page. Defaults to `false`.
55
+ * If given a string, it will be displayed as a prefix (default value:
56
+ * "Last Updated").
57
+ */
58
+ lastUpdated?: string | boolean
59
+
60
+ prevLinks?: boolean
61
+ nextLinks?: boolean
62
+
63
+ locales?: Record<string, LocaleConfig & Omit<Config, 'locales'>>
64
+
65
+ algolia?: AlgoliaSearchOptions
66
+
67
+ carbonAds?: {
68
+ carbon: string
69
+ custom?: string
70
+ placement: string
71
+ }
72
+ }
73
+
74
+ // navbar --------------------------------------------------------------------
75
+
76
+ export type NavItem = NavItemWithLink | NavItemWithChildren
77
+
78
+ export interface NavItemBase {
79
+ text: string
80
+ target?: string
81
+ rel?: string
82
+ ariaLabel?: string
83
+ activeMatch?: string
84
+ }
85
+
86
+ export interface NavItemWithLink extends NavItemBase {
87
+ link: string
88
+ }
89
+
90
+ export interface NavItemWithChildren extends NavItemBase {
91
+ items: NavItemWithLink[]
92
+ }
93
+
94
+ // sidebar -------------------------------------------------------------------
95
+
96
+ export type SideBarConfig = SideBarItem[] | 'auto' | false
97
+
98
+ export interface MultiSideBarConfig {
99
+ [path: string]: SideBarConfig
100
+ }
101
+
102
+ export type SideBarItem = SideBarLink | SideBarGroup
103
+
104
+ export interface SideBarLink {
105
+ text: string
106
+ link: string
107
+ }
108
+
109
+ export interface SideBarGroup {
110
+ text: string
111
+ link?: string
112
+
113
+ /**
114
+ * @default false
115
+ */
116
+ collapsable?: boolean
117
+
118
+ children: SideBarItem[]
119
+ }
120
+
121
+ // algolia ------------------------------------------------------------------
122
+ // partially copied from @docsearch/react/dist/esm/DocSearch.d.ts
123
+ export interface AlgoliaSearchOptions {
124
+ appId?: string
125
+ apiKey: string
126
+ indexName: string
127
+ placeholder?: string
128
+ searchParameters?: any
129
+ disableUserPersonalization?: boolean
130
+ initialQuery?: string
131
+ }
132
+
133
+ // locales -------------------------------------------------------------------
134
+
135
+ export interface LocaleConfig {
136
+ /**
137
+ * Text for the language dropdown.
138
+ */
139
+ selectText?: string
140
+
141
+ /**
142
+ * Label for this locale in the language dropdown.
143
+ */
144
+ label?: string
145
+ }
146
+ }
package/types/index.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- export * from './shared'
2
1
  export * from '../dist/node/index'
3
2
  export * from '../dist/client/index'
4
- export * from '../dist/client/theme-default/config'
package/types/shared.d.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  // types shared between server and client
2
2
 
3
- export interface LocaleConfig {
4
- lang: string
5
- title?: string
6
- description?: string
7
- head?: HeadConfig[]
8
- label?: string
9
- selectText?: string
3
+ export { DefaultTheme } from './default-theme'
4
+
5
+ export interface PageData {
6
+ relativePath: string
7
+ title: string
8
+ description: string
9
+ headers: Header[]
10
+ frontmatter: Record<string, any>
11
+ lastUpdated: number
10
12
  }
11
13
 
12
14
  export interface SiteData<ThemeConfig = any> {
@@ -47,17 +49,17 @@ export type HeadConfig =
47
49
  | [string, Record<string, string>]
48
50
  | [string, Record<string, string>, string]
49
51
 
50
- export interface PageData {
51
- relativePath: string
52
- title: string
53
- description: string
54
- headers: Header[]
55
- frontmatter: Record<string, any>
56
- lastUpdated: number
57
- }
58
-
59
52
  export interface Header {
60
53
  level: number
61
54
  title: string
62
55
  slug: string
63
56
  }
57
+
58
+ export interface LocaleConfig {
59
+ lang: string
60
+ title?: string
61
+ description?: string
62
+ head?: HeadConfig[]
63
+ label?: string
64
+ selectText?: string
65
+ }