vitepress 0.22.3 → 1.0.0-alpha.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.
Files changed (174) hide show
  1. package/README.md +3 -1
  2. package/bin/vitepress.js +1 -1
  3. package/client.d.ts +2 -3
  4. package/dist/client/app/components/ClientOnly.js +1 -1
  5. package/dist/client/app/composables/head.js +2 -2
  6. package/dist/client/app/data.js +2 -4
  7. package/dist/client/app/devtools.js +28 -0
  8. package/dist/client/app/index.js +11 -33
  9. package/dist/client/app/router.js +24 -14
  10. package/dist/client/index.d.ts +121 -129
  11. package/dist/client/index.js +0 -3
  12. package/dist/client/shared.js +30 -0
  13. package/dist/client/theme-default/Layout.vue +49 -180
  14. package/dist/client/theme-default/NotFound.vue +77 -16
  15. package/dist/client/theme-default/components/VPAlgoliaSearchBox.vue +127 -0
  16. package/dist/client/theme-default/components/VPBackdrop.vue +39 -0
  17. package/dist/client/theme-default/components/VPButton.vue +123 -0
  18. package/dist/client/theme-default/components/VPCarbonAds.vue +90 -0
  19. package/dist/client/theme-default/components/VPContent.vue +81 -0
  20. package/dist/client/theme-default/components/VPDoc.vue +192 -0
  21. package/dist/client/theme-default/components/VPDocAside.vue +46 -0
  22. package/dist/client/theme-default/components/VPDocAsideCarbonAds.vue +13 -0
  23. package/dist/client/theme-default/components/VPDocAsideOutline.vue +126 -0
  24. package/dist/client/theme-default/components/VPDocAsideSponsors.vue +32 -0
  25. package/dist/client/theme-default/components/VPDocFooter.vue +161 -0
  26. package/dist/client/theme-default/components/VPDocFooterLastUpdated.vue +43 -0
  27. package/dist/client/theme-default/components/VPFeature.vue +55 -0
  28. package/dist/client/theme-default/components/VPFeatures.vue +107 -0
  29. package/dist/client/theme-default/components/VPFlyout.vue +148 -0
  30. package/dist/client/theme-default/components/VPFooter.vue +53 -0
  31. package/dist/client/theme-default/components/VPHero.vue +315 -0
  32. package/dist/client/theme-default/components/VPHome.vue +35 -0
  33. package/dist/client/theme-default/components/VPHomeFeatures.vue +14 -0
  34. package/dist/client/theme-default/components/VPHomeHero.vue +18 -0
  35. package/dist/client/theme-default/components/VPHomeSponsors.vue +93 -0
  36. package/dist/client/theme-default/components/VPLink.vue +38 -0
  37. package/dist/client/theme-default/components/VPLocalNav.vue +108 -0
  38. package/dist/client/theme-default/components/VPMenu.vue +74 -0
  39. package/dist/client/theme-default/components/VPMenuGroup.vue +46 -0
  40. package/dist/client/theme-default/components/VPMenuLink.vue +55 -0
  41. package/dist/client/theme-default/components/VPNav.vue +55 -0
  42. package/dist/client/theme-default/components/VPNavBar.vue +129 -0
  43. package/dist/client/theme-default/components/VPNavBarAppearance.vue +25 -0
  44. package/dist/client/theme-default/components/VPNavBarExtra.vue +82 -0
  45. package/dist/client/theme-default/components/VPNavBarHamburger.vue +79 -0
  46. package/dist/client/theme-default/components/VPNavBarMenu.vue +29 -0
  47. package/dist/client/theme-default/components/VPNavBarMenuGroup.vue +12 -0
  48. package/dist/client/theme-default/components/VPNavBarMenuLink.vue +56 -0
  49. package/dist/client/theme-default/components/VPNavBarSearch.vue +270 -0
  50. package/dist/client/theme-default/components/VPNavBarSocialLinks.vue +27 -0
  51. package/dist/client/theme-default/components/VPNavBarTitle.vue +59 -0
  52. package/dist/client/theme-default/components/VPNavBarTranslations.vue +45 -0
  53. package/dist/client/theme-default/components/VPNavScreen.vue +100 -0
  54. package/dist/client/theme-default/components/VPNavScreenAppearance.vue +33 -0
  55. package/dist/client/theme-default/components/VPNavScreenMenu.vue +24 -0
  56. package/dist/client/theme-default/components/VPNavScreenMenuGroup.vue +117 -0
  57. package/dist/client/theme-default/components/VPNavScreenMenuGroupLink.vue +33 -0
  58. package/dist/client/theme-default/components/VPNavScreenMenuGroupSection.vue +35 -0
  59. package/dist/client/theme-default/components/VPNavScreenMenuLink.vue +34 -0
  60. package/dist/client/theme-default/components/VPNavScreenSocialLinks.vue +14 -0
  61. package/dist/client/theme-default/components/VPNavScreenTranslations.vue +73 -0
  62. package/dist/client/theme-default/components/VPPage.vue +5 -0
  63. package/dist/client/theme-default/components/VPSidebar.vue +122 -0
  64. package/dist/client/theme-default/components/VPSidebarGroup.vue +112 -0
  65. package/dist/client/theme-default/components/VPSidebarLink.vue +54 -0
  66. package/dist/client/theme-default/components/VPSkipLink.vue +72 -0
  67. package/dist/client/theme-default/components/VPSocialLink.vue +63 -0
  68. package/dist/client/theme-default/components/VPSocialLinks.vue +27 -0
  69. package/dist/client/theme-default/components/VPSponsors.vue +52 -0
  70. package/dist/client/theme-default/components/VPSponsorsGrid.vue +32 -0
  71. package/dist/client/theme-default/components/VPSwitch.vue +66 -0
  72. package/dist/client/theme-default/components/VPSwitchAppearance.vue +74 -0
  73. package/dist/client/theme-default/components/icons/VPIconAlignJustify.vue +8 -0
  74. package/dist/client/theme-default/components/icons/VPIconAlignLeft.vue +8 -0
  75. package/dist/client/theme-default/components/icons/VPIconAlignRight.vue +8 -0
  76. package/dist/client/theme-default/components/icons/{ArrowLeft.vue → VPIconArrowLeft.vue} +0 -0
  77. package/dist/client/theme-default/components/icons/{ArrowRight.vue → VPIconArrowRight.vue} +0 -0
  78. package/dist/client/theme-default/components/icons/VPIconChevronDown.vue +5 -0
  79. package/dist/client/theme-default/components/icons/VPIconChevronLeft.vue +5 -0
  80. package/dist/client/theme-default/components/icons/VPIconChevronRight.vue +5 -0
  81. package/dist/client/theme-default/components/icons/VPIconChevronUp.vue +5 -0
  82. package/dist/client/theme-default/components/icons/VPIconDiscord.vue +5 -0
  83. package/dist/client/theme-default/components/icons/VPIconEdit.vue +6 -0
  84. package/dist/client/theme-default/components/icons/VPIconExternalLink.vue +13 -0
  85. package/dist/client/theme-default/components/icons/VPIconFacebook.vue +5 -0
  86. package/dist/client/theme-default/components/icons/VPIconGitHub.vue +5 -0
  87. package/dist/client/theme-default/components/icons/VPIconHeart.vue +5 -0
  88. package/dist/client/theme-default/components/icons/VPIconInstagram.vue +5 -0
  89. package/dist/client/theme-default/components/icons/VPIconLanguages.vue +9 -0
  90. package/dist/client/theme-default/components/icons/VPIconLinkedIn.vue +5 -0
  91. package/dist/client/theme-default/components/icons/VPIconMinus.vue +5 -0
  92. package/dist/client/theme-default/components/icons/VPIconMinusSquare.vue +6 -0
  93. package/dist/client/theme-default/components/icons/VPIconMoon.vue +5 -0
  94. package/dist/client/theme-default/components/icons/VPIconMoreHorizontal.vue +7 -0
  95. package/dist/client/theme-default/components/icons/VPIconPlus.vue +5 -0
  96. package/dist/client/theme-default/components/icons/VPIconPlusSquare.vue +6 -0
  97. package/dist/client/theme-default/components/icons/VPIconSlack.vue +5 -0
  98. package/dist/client/theme-default/components/icons/VPIconSun.vue +13 -0
  99. package/dist/client/theme-default/components/icons/VPIconTwitter.vue +5 -0
  100. package/dist/client/theme-default/components/icons/VPIconYouTube.vue +5 -0
  101. package/dist/client/theme-default/composables/aside.js +17 -0
  102. package/dist/client/theme-default/composables/copy-code.js +33 -0
  103. package/dist/client/theme-default/composables/edit-link.js +11 -0
  104. package/dist/client/theme-default/composables/flyout.js +40 -0
  105. package/dist/client/theme-default/composables/nav.js +27 -1
  106. package/dist/client/theme-default/composables/outline.js +122 -0
  107. package/dist/client/theme-default/composables/prev-next.js +18 -0
  108. package/dist/client/theme-default/composables/sidebar.js +57 -0
  109. package/dist/client/theme-default/composables/sponsor-grid.js +94 -0
  110. package/dist/client/theme-default/fonts/inter-cyrillic-ext.woff2 +0 -0
  111. package/dist/client/theme-default/fonts/inter-cyrillic.woff2 +0 -0
  112. package/dist/client/theme-default/fonts/inter-greek-ext.woff2 +0 -0
  113. package/dist/client/theme-default/fonts/inter-greek.woff2 +0 -0
  114. package/dist/client/theme-default/fonts/inter-latin-ext.woff2 +0 -0
  115. package/dist/client/theme-default/fonts/inter-latin.woff2 +0 -0
  116. package/dist/client/theme-default/fonts/inter-vietnamese.woff2 +0 -0
  117. package/dist/client/theme-default/index.js +11 -4
  118. package/dist/client/theme-default/styles/base.css +215 -0
  119. package/dist/client/theme-default/styles/components/custom-block.css +90 -0
  120. package/dist/client/theme-default/styles/components/vp-code.css +7 -0
  121. package/dist/client/theme-default/styles/components/vp-doc.css +463 -0
  122. package/dist/client/theme-default/styles/components/vp-sponsor.css +130 -0
  123. package/dist/client/theme-default/styles/fonts.css +67 -0
  124. package/dist/client/theme-default/styles/utils.css +9 -0
  125. package/dist/client/theme-default/styles/vars.css +340 -54
  126. package/dist/client/theme-default/support/sidebar.js +29 -0
  127. package/dist/client/theme-default/support/utils.js +62 -0
  128. package/dist/node/cli.js +32 -31
  129. package/dist/node/index.d.ts +386 -318
  130. package/dist/node/index.js +22 -37
  131. package/dist/node/serve-42a92e2f.js +64813 -0
  132. package/dist/node-cjs/cli.cjs +304 -0
  133. package/dist/node-cjs/index.cjs +38 -0
  134. package/dist/{node/serve-777539c0.js → node-cjs/serve-507b373b.cjs} +27547 -28701
  135. package/package.json +61 -47
  136. package/theme.d.ts +7 -2
  137. package/types/default-theme.d.ts +134 -73
  138. package/types/shared.d.ts +19 -6
  139. package/dist/client/app/components/Debug.vue +0 -86
  140. package/dist/client/theme-default/components/AlgoliaSearchBox.vue +0 -188
  141. package/dist/client/theme-default/components/BuySellAds.vue +0 -152
  142. package/dist/client/theme-default/components/CarbonAds.vue +0 -99
  143. package/dist/client/theme-default/components/EditLink.vue +0 -38
  144. package/dist/client/theme-default/components/Home.vue +0 -31
  145. package/dist/client/theme-default/components/HomeFeatures.vue +0 -143
  146. package/dist/client/theme-default/components/HomeFooter.vue +0 -50
  147. package/dist/client/theme-default/components/HomeHero.vue +0 -161
  148. package/dist/client/theme-default/components/LastUpdated.vue +0 -60
  149. package/dist/client/theme-default/components/NavBar.vue +0 -60
  150. package/dist/client/theme-default/components/NavBarTitle.vue +0 -41
  151. package/dist/client/theme-default/components/NavDropdownLink.vue +0 -135
  152. package/dist/client/theme-default/components/NavDropdownLinkItem.vue +0 -76
  153. package/dist/client/theme-default/components/NavLink.vue +0 -61
  154. package/dist/client/theme-default/components/NavLinks.vue +0 -52
  155. package/dist/client/theme-default/components/NextAndPrevLinks.vue +0 -88
  156. package/dist/client/theme-default/components/Page.vue +0 -53
  157. package/dist/client/theme-default/components/PageFooter.vue +0 -44
  158. package/dist/client/theme-default/components/SideBar.vue +0 -60
  159. package/dist/client/theme-default/components/SideBarLink.js +0 -68
  160. package/dist/client/theme-default/components/SideBarLinks.vue +0 -12
  161. package/dist/client/theme-default/components/ToggleSideBarButton.vue +0 -46
  162. package/dist/client/theme-default/components/icons/OutboundLink.vue +0 -31
  163. package/dist/client/theme-default/composables/activeSidebarLink.js +0 -99
  164. package/dist/client/theme-default/composables/editLink.js +0 -49
  165. package/dist/client/theme-default/composables/navLink.js +0 -42
  166. package/dist/client/theme-default/composables/nextAndPrevLinks.js +0 -37
  167. package/dist/client/theme-default/composables/repo.js +0 -38
  168. package/dist/client/theme-default/composables/sideBar.js +0 -57
  169. package/dist/client/theme-default/styles/code.css +0 -299
  170. package/dist/client/theme-default/styles/custom-blocks.css +0 -76
  171. package/dist/client/theme-default/styles/layout.css +0 -236
  172. package/dist/client/theme-default/styles/sidebar-links.css +0 -107
  173. package/dist/client/theme-default/support/sideBar.js +0 -46
  174. package/dist/client/theme-default/utils.js +0 -63
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # (WIP) VitePress 📝💨
1
+ # VitePress (alpha) 📝💨
2
2
 
3
3
  [![Test](https://github.com/vuejs/vitepress/workflows/Test/badge.svg)](https://github.com/vuejs/vitepress/actions)
4
4
  [![npm](https://img.shields.io/npm/v/vitepress)](https://www.npmjs.com/package/vitepress)
@@ -7,6 +7,8 @@
7
7
 
8
8
  VitePress is [VuePress](https://vuepress.vuejs.org)' spiritual successor, built on top of [vite](https://github.com/vitejs/vite).
9
9
 
10
+ Currently, it's in the `alpha` stage. It is already suitable for out-of-the-box documentation use, but the config and theming API may still change between minor releases.
11
+
10
12
  ## Documentation
11
13
 
12
14
  To check out docs, visit [vitepress.vuejs.org](https://vitepress.vuejs.org).
package/bin/vitepress.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require('../dist/node/cli')
2
+ import('../dist/node/cli.js')
package/client.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- // re-export vite client types
2
- // with strict installers like pnpm, user won't be able to reference vite/client
3
- // in project root
1
+ // re-export vite client types. with strict installers like pnpm, user won't
2
+ // be able to reference vite/client in project root.
4
3
  /// <reference types="vite/client" />
@@ -1,4 +1,4 @@
1
- import { ref, onMounted, defineComponent } from 'vue';
1
+ import { defineComponent, ref, onMounted } from 'vue';
2
2
  export const ClientOnly = defineComponent({
3
3
  setup(_, { slots }) {
4
4
  const show = ref(false);
@@ -1,4 +1,5 @@
1
1
  import { watchEffect } from 'vue';
2
+ import { createTitle } from '../../shared';
2
3
  export function useUpdateHead(route, siteDataByRouteRef) {
3
4
  let managedHeadTags = [];
4
5
  let isFirstUpdate = true;
@@ -50,11 +51,10 @@ export function useUpdateHead(route, siteDataByRouteRef) {
50
51
  watchEffect(() => {
51
52
  const pageData = route.data;
52
53
  const siteData = siteDataByRouteRef.value;
53
- const pageTitle = pageData && pageData.title;
54
54
  const pageDescription = pageData && pageData.description;
55
55
  const frontmatterHead = pageData && pageData.frontmatter.head;
56
56
  // update title and description
57
- document.title = (pageTitle ? pageTitle + ` | ` : ``) + siteData.title;
57
+ document.title = createTitle(siteData, pageData);
58
58
  document
59
59
  .querySelector(`meta[name=description]`)
60
60
  .setAttribute('content', pageDescription || siteData.description);
@@ -1,6 +1,6 @@
1
1
  import { shallowRef, readonly, computed, inject } from 'vue';
2
2
  import serializedSiteData from '@siteData';
3
- import { resolveSiteDataByRoute } from '../shared';
3
+ import { resolveSiteDataByRoute, createTitle } from '../shared';
4
4
  import { withBase } from './utils';
5
5
  export const dataSymbol = Symbol();
6
6
  export const siteDataRef = shallowRef(parse(serializedSiteData));
@@ -29,9 +29,7 @@ export function initData(route) {
29
29
  return withBase(path || '/');
30
30
  }),
31
31
  title: computed(() => {
32
- return route.data.title
33
- ? route.data.title + ' | ' + site.value.title
34
- : site.value.title;
32
+ return createTitle(site.value, route.data);
35
33
  }),
36
34
  description: computed(() => {
37
35
  return route.data.description || site.value.description;
@@ -0,0 +1,28 @@
1
+ import { setupDevtoolsPlugin } from '@vue/devtools-api';
2
+ const COMPONENT_STATE_TYPE = 'VitePress';
3
+ export const setupDevtools = (app, router, data) => {
4
+ setupDevtoolsPlugin({
5
+ // fix recursive reference
6
+ app: app,
7
+ id: 'org.vuejs.vitepress',
8
+ label: 'VitePress',
9
+ packageName: 'vitepress',
10
+ homepage: 'https://vitepress.vuejs.org',
11
+ componentStateTypes: [COMPONENT_STATE_TYPE]
12
+ }, (api) => {
13
+ api.on.inspectComponent((payload) => {
14
+ payload.instanceData.state.push({
15
+ type: COMPONENT_STATE_TYPE,
16
+ key: 'route',
17
+ value: router.route,
18
+ editable: false
19
+ });
20
+ payload.instanceData.state.push({
21
+ type: COMPONENT_STATE_TYPE,
22
+ key: 'data',
23
+ value: data,
24
+ editable: false
25
+ });
26
+ });
27
+ });
28
+ };
@@ -1,9 +1,9 @@
1
- import { createApp as createClientApp, createSSRApp, defineAsyncComponent, h, onMounted, watch } from 'vue';
1
+ import { createApp as createClientApp, createSSRApp, h, onMounted, watch } from 'vue';
2
+ import Theme from '/@theme/index';
2
3
  import { inBrowser, pathToFile } from './utils';
3
4
  import { RouterSymbol, createRouter } from './router';
4
5
  import { siteDataRef, useData } from './data';
5
6
  import { useUpdateHead } from './composables/head';
6
- import Theme from '/@theme/index';
7
7
  import { usePrefetch } from './composables/preFetch';
8
8
  import { dataSymbol, initData } from './data';
9
9
  import { Content } from './components/Content';
@@ -28,21 +28,13 @@ const VitePressApp = {
28
28
  };
29
29
  export function createApp() {
30
30
  const router = newRouter();
31
- handleHMR(router);
32
31
  const app = newApp();
33
32
  app.provide(RouterSymbol, router);
34
33
  const data = initData(router.route);
35
34
  app.provide(dataSymbol, data);
36
- if (inBrowser) {
37
- // dynamically update head tags
38
- useUpdateHead(router.route, data.site);
39
- }
40
35
  // install global components
41
36
  app.component('Content', Content);
42
37
  app.component('ClientOnly', ClientOnly);
43
- app.component('Debug', import.meta.env.PROD
44
- ? () => null
45
- : defineAsyncComponent(() => import('./components/Debug.vue')));
46
38
  // expose $frontmatter
47
39
  Object.defineProperty(app.config.globalProperties, '$frontmatter', {
48
40
  get() {
@@ -56,7 +48,11 @@ export function createApp() {
56
48
  siteData: siteDataRef
57
49
  });
58
50
  }
59
- return { app, router };
51
+ // setup devtools in dev mode
52
+ if (import.meta.env.DEV || __VUE_PROD_DEVTOOLS__) {
53
+ import('./devtools').then(({ setupDevtools }) => setupDevtools(app, router, data));
54
+ }
55
+ return { app, router, data };
60
56
  }
61
57
  function newApp() {
62
58
  return import.meta.env.PROD
@@ -77,36 +73,18 @@ function newRouter() {
77
73
  if (isInitialPageLoad || initialPath === pageFilePath) {
78
74
  pageFilePath = pageFilePath.replace(/\.js$/, '.lean.js');
79
75
  }
80
- // in browser: native dynamic import
81
76
  if (inBrowser) {
82
77
  isInitialPageLoad = false;
83
- return import(/*@vite-ignore*/ pageFilePath);
84
78
  }
85
- // SSR: sync require
86
- // @ts-ignore
87
- return require(pageFilePath);
79
+ return import(/*@vite-ignore*/ pageFilePath);
88
80
  }, NotFound);
89
81
  }
90
- function handleHMR(router) {
91
- // update route.data on HMR updates of active page
92
- if (import.meta.hot) {
93
- // hot reload pageData
94
- import.meta.hot.on('vitepress:pageData', (payload) => {
95
- if (shouldHotReload(payload)) {
96
- router.route.data = payload.pageData;
97
- }
98
- });
99
- }
100
- }
101
- function shouldHotReload(payload) {
102
- const payloadPath = payload.path.replace(/(\bindex)?\.md$/, '');
103
- const locationPath = location.pathname.replace(/(\bindex)?\.html$/, '');
104
- return payloadPath === locationPath;
105
- }
106
82
  if (inBrowser) {
107
- const { app, router } = createApp();
83
+ const { app, router, data } = createApp();
108
84
  // wait until page component is fetched before mounting
109
85
  router.go().then(() => {
86
+ // dynamically update head tags
87
+ useUpdateHead(router.route, data.site);
110
88
  app.mount('#app');
111
89
  });
112
90
  }
@@ -1,18 +1,11 @@
1
1
  import { reactive, inject, markRaw, nextTick, readonly } from 'vue';
2
- import { inBrowser } from './utils';
2
+ import { notFoundPageData } from '../shared';
3
+ import { inBrowser, withBase } from './utils';
3
4
  import { siteDataRef } from './data';
4
5
  export const RouterSymbol = Symbol();
5
6
  // we are just using URL to parse the pathname and hash - the base doesn't
6
7
  // matter and is only passed to support same-host hrefs.
7
8
  const fakeHost = `http://a.com`;
8
- const notFoundPageData = {
9
- relativePath: '',
10
- title: '404',
11
- description: 'Not Found',
12
- headers: [],
13
- frontmatter: {},
14
- lastUpdated: 0
15
- };
16
9
  const getDefaultRoute = () => ({
17
10
  path: '/',
18
11
  component: null,
@@ -51,11 +44,11 @@ export function createRouter(loadPageModule, fallbackComponent) {
51
44
  if (!comp) {
52
45
  throw new Error(`Invalid route component: ${comp}`);
53
46
  }
54
- route.path = pendingPath;
47
+ route.path = inBrowser ? pendingPath : withBase(pendingPath);
55
48
  route.component = markRaw(comp);
56
49
  route.data = import.meta.env.PROD
57
- ? markRaw(JSON.parse(__pageData))
58
- : readonly(JSON.parse(__pageData));
50
+ ? markRaw(__pageData)
51
+ : readonly(__pageData);
59
52
  if (inBrowser) {
60
53
  nextTick(() => {
61
54
  if (targetLoc.hash && !scrollPosition) {
@@ -77,7 +70,7 @@ export function createRouter(loadPageModule, fallbackComponent) {
77
70
  }
78
71
  }
79
72
  catch (err) {
80
- if (!err.message.match(/fetch/)) {
73
+ if (!err.message.match(/fetch/) && !href.match(/^[\\/]404\.html$/)) {
81
74
  console.error(err);
82
75
  }
83
76
  // retry on fetch fail: the page to hash map may have been invalidated
@@ -94,7 +87,7 @@ export function createRouter(loadPageModule, fallbackComponent) {
94
87
  }
95
88
  if (latestPendingPath === pendingPath) {
96
89
  latestPendingPath = null;
97
- route.path = pendingPath;
90
+ route.path = inBrowser ? pendingPath : withBase(pendingPath);
98
91
  route.component = fallbackComponent ? markRaw(fallbackComponent) : null;
99
92
  route.data = notFoundPageData;
100
93
  }
@@ -140,6 +133,7 @@ export function createRouter(loadPageModule, fallbackComponent) {
140
133
  e.preventDefault();
141
134
  });
142
135
  }
136
+ handleHMR(route);
143
137
  return {
144
138
  route,
145
139
  go
@@ -190,3 +184,19 @@ function scrollTo(el, hash, smooth = false) {
190
184
  }
191
185
  }
192
186
  }
187
+ function handleHMR(route) {
188
+ // update route.data on HMR updates of active page
189
+ if (import.meta.hot) {
190
+ // hot reload pageData
191
+ import.meta.hot.on('vitepress:pageData', (payload) => {
192
+ if (shouldHotReload(payload)) {
193
+ route.data = payload.pageData;
194
+ }
195
+ });
196
+ }
197
+ }
198
+ function shouldHotReload(payload) {
199
+ const payloadPath = payload.path.replace(/(\bindex)?\.md$/, '');
200
+ const locationPath = location.pathname.replace(/(\bindex)?\.html$/, '');
201
+ return payloadPath === locationPath;
202
+ }
@@ -1,129 +1,121 @@
1
- import { AllowedComponentProps } from 'vue';
2
- import { App } from 'vue';
3
- import { Component } from 'vue';
4
- import { ComponentCustomProps } from 'vue';
5
- import { ComponentOptions } from 'vue';
6
- import { ComponentOptionsMixin } from 'vue';
7
- import { DefineComponent } from 'vue';
8
- import { EmitsOptions } from 'vue';
9
- import { ExtractPropTypes } from 'vue';
10
- import { Ref } from 'vue';
11
- import { RendererElement } from 'vue';
12
- import { RendererNode } from 'vue';
13
- import { VNode } from 'vue';
14
- import { VNodeProps } from 'vue';
15
-
16
- export declare const Content: DefineComponent< {}, () => VNode<RendererNode, RendererElement, {
17
- [key: string]: any;
18
- }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes< {}>>, {}>;
19
-
20
- export declare const Debug: ComponentOptions<{}, any, any, any, any, any, any, any>;
21
-
22
- export declare interface EnhanceAppContext {
23
- app: App;
24
- router: Router;
25
- siteData: Ref<SiteData>;
26
- }
27
-
28
- export declare type HeadConfig =
29
- | [string, Record<string, string>]
30
- | [string, Record<string, string>, string]
31
-
32
- export declare interface Header {
33
- level: number
34
- title: string
35
- slug: string
36
- }
37
-
38
- export declare const inBrowser: boolean;
39
-
40
- export declare interface LocaleConfig {
41
- lang: string
42
- title?: string
43
- description?: string
44
- head?: HeadConfig[]
45
- label?: string
46
- selectText?: string
47
- }
48
-
49
- export declare interface PageData {
50
- relativePath: string
51
- title: string
52
- description: string
53
- headers: Header[]
54
- frontmatter: Record<string, any>
55
- lastUpdated?: number
56
- }
57
-
58
- export declare interface Route {
59
- path: string;
60
- data: PageData;
61
- component: Component | null;
62
- }
63
-
64
- export declare interface Router {
65
- route: Route;
66
- go: (href?: string) => Promise<void>;
67
- }
68
-
69
- export declare interface SiteData<ThemeConfig = any> {
70
- base: string
71
- /**
72
- * Language of the site as it should be set on the `html` element.
73
- * @example `en-US`, `zh-CN`
74
- */
75
- lang: string
76
- title: string
77
- description: string
78
- head: HeadConfig[]
79
- themeConfig: ThemeConfig
80
- scrollOffset: number | string
81
- locales: Record<string, LocaleConfig>
82
- /**
83
- * Available locales for the site when it has defined `locales` in its
84
- * `themeConfig`. This object is otherwise empty. Keys are paths like `/` or
85
- * `/zh/`.
86
- */
87
- langs: Record<
88
- string,
89
- {
90
- /**
91
- * Lang attribute as set on the `<html>` element.
92
- * @example `en-US`, `zh-CN`
93
- */
94
- lang: string
95
- /**
96
- * Label to display in the language menu.
97
- * @example `English`, `简体中文`
98
- */
99
- label: string
100
- }
101
- >
102
- }
103
-
104
- export declare interface Theme {
105
- Layout: Component;
106
- NotFound?: Component;
107
- enhanceApp?: (ctx: EnhanceAppContext) => void;
108
- }
109
-
110
- export declare function useData<T = any>(): VitePressData<T>;
111
-
112
- export declare function useRoute(): Route;
113
-
114
- export declare function useRouter(): Router;
115
-
116
- export declare interface VitePressData<T = any> {
117
- site: Ref<SiteData<T>>;
118
- page: Ref<PageData>;
119
- theme: Ref<T>;
120
- frontmatter: Ref<PageData['frontmatter']>;
121
- title: Ref<string>;
122
- description: Ref<string>;
123
- lang: Ref<string>;
124
- localePath: Ref<string>;
125
- }
126
-
127
- export declare function withBase(path: string): string;
128
-
129
- export { }
1
+ import * as vue from 'vue';
2
+ import { Component, Ref, App } from 'vue';
3
+
4
+ // types shared between server and client
5
+
6
+
7
+ interface PageData {
8
+ relativePath: string
9
+ title: string
10
+ titleTemplate?: string | boolean
11
+ description: string
12
+ headers: Header[]
13
+ frontmatter: Record<string, any>
14
+ lastUpdated?: number
15
+ }
16
+
17
+ interface Header {
18
+ level: number
19
+ title: string
20
+ slug: string
21
+ }
22
+
23
+ interface SiteData<ThemeConfig = any> {
24
+ base: string
25
+
26
+ /**
27
+ * Language of the site as it should be set on the `html` element.
28
+ *
29
+ * @example `en-US`, `zh-CN`
30
+ */
31
+ lang: string
32
+
33
+ title: string
34
+ titleTemplate?: string | boolean
35
+ description: string
36
+ head: HeadConfig[]
37
+ appearance: boolean
38
+ themeConfig: ThemeConfig
39
+ scrollOffset: number | string
40
+ locales: Record<string, LocaleConfig>
41
+
42
+ /**
43
+ * Available locales for the site when it has defined `locales` in its
44
+ * `themeConfig`. This object is otherwise empty. Keys are paths like `/` or
45
+ * `/zh/`.
46
+ */
47
+ langs: Record<
48
+ string,
49
+ {
50
+ /**
51
+ * Lang attribute as set on the `<html>` element.
52
+ * @example `en-US`, `zh-CN`
53
+ */
54
+ lang: string
55
+ /**
56
+ * Label to display in the language menu.
57
+ * @example `English`, `简体中文`
58
+ */
59
+ label: string
60
+ }
61
+ >
62
+ }
63
+
64
+ type HeadConfig =
65
+ | [string, Record<string, string>]
66
+ | [string, Record<string, string>, string]
67
+
68
+ interface LocaleConfig {
69
+ lang: string
70
+ title?: string
71
+ titleTemplate?: string | boolean
72
+ description?: string
73
+ head?: HeadConfig[]
74
+ label?: string
75
+ selectText?: string
76
+ }
77
+
78
+ declare const inBrowser: boolean;
79
+
80
+ interface Route {
81
+ path: string;
82
+ data: PageData;
83
+ component: Component | null;
84
+ }
85
+ interface Router {
86
+ route: Route;
87
+ go: (href?: string) => Promise<void>;
88
+ }
89
+ declare function useRouter(): Router;
90
+ declare function useRoute(): Route;
91
+
92
+ interface VitePressData<T = any> {
93
+ site: Ref<SiteData<T>>;
94
+ page: Ref<PageData>;
95
+ theme: Ref<T>;
96
+ frontmatter: Ref<PageData['frontmatter']>;
97
+ title: Ref<string>;
98
+ description: Ref<string>;
99
+ lang: Ref<string>;
100
+ localePath: Ref<string>;
101
+ }
102
+ declare function useData<T = any>(): VitePressData<T>;
103
+
104
+ interface EnhanceAppContext {
105
+ app: App;
106
+ router: Router;
107
+ siteData: Ref<SiteData>;
108
+ }
109
+ interface Theme {
110
+ Layout: Component;
111
+ NotFound?: Component;
112
+ enhanceApp?: (ctx: EnhanceAppContext) => void;
113
+ }
114
+
115
+ declare function withBase(path: string): string;
116
+
117
+ declare const Content: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
118
+ [key: string]: any;
119
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, vue.EmitsOptions, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<vue.ExtractPropTypes<{}>>, {}>;
120
+
121
+ export { Content, EnhanceAppContext, HeadConfig, Header, LocaleConfig, PageData, Route, Router, SiteData, Theme, VitePressData, inBrowser, useData, useRoute, useRouter, withBase };
@@ -7,6 +7,3 @@ export { useRouter, useRoute } from './app/router';
7
7
  export { inBrowser, withBase } from './app/utils';
8
8
  // components
9
9
  export { Content } from './app/components/Content';
10
- import _Debug from './app/components/Debug.vue';
11
- const Debug = _Debug;
12
- export { Debug };
@@ -1,6 +1,15 @@
1
1
  export const EXTERNAL_URL_RE = /^https?:/i;
2
+ export const APPEARANCE_KEY = 'vitepress-theme-appearance';
2
3
  // @ts-ignore
3
4
  export const inBrowser = typeof window !== 'undefined';
5
+ export const notFoundPageData = {
6
+ relativePath: '',
7
+ title: '404',
8
+ description: 'Not Found',
9
+ headers: [],
10
+ frontmatter: {},
11
+ lastUpdated: 0
12
+ };
4
13
  function findMatchRoot(route, roots) {
5
14
  // first match to the routes with the most deep level.
6
15
  roots.sort((a, b) => {
@@ -52,6 +61,27 @@ export function resolveSiteDataByRoute(siteData, route) {
52
61
  langs: createLangDictionary(siteData)
53
62
  });
54
63
  }
64
+ /**
65
+ * Create the page title string based on configs.
66
+ */
67
+ export function createTitle(siteData, pageData) {
68
+ const title = pageData.title || siteData.title;
69
+ const template = pageData.titleTemplate ?? siteData.titleTemplate;
70
+ const templateString = createTitleTemplate(siteData.title, template);
71
+ return `${title}${templateString}`;
72
+ }
73
+ function createTitleTemplate(siteTitle, template) {
74
+ if (template === false) {
75
+ return '';
76
+ }
77
+ if (template === true || template === undefined) {
78
+ return ` | ${siteTitle}`;
79
+ }
80
+ if (siteTitle === template) {
81
+ return '';
82
+ }
83
+ return ` | ${template}`;
84
+ }
55
85
  /**
56
86
  * Clean up the route by removing the `base` path if it's set in config.
57
87
  */