vitepress 0.22.3 → 1.0.0-alpha.10

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 (193) hide show
  1. package/README.md +3 -1
  2. package/bin/vitepress.js +1 -1
  3. package/client.d.ts +4 -3
  4. package/dist/client/app/components/ClientOnly.js +1 -1
  5. package/dist/client/app/components/Content.js +1 -1
  6. package/dist/client/app/composables/head.js +8 -42
  7. package/dist/client/app/composables/preFetch.js +2 -2
  8. package/dist/client/app/data.js +9 -12
  9. package/dist/client/app/devtools.js +28 -0
  10. package/dist/client/app/index.js +25 -43
  11. package/dist/client/app/router.js +38 -30
  12. package/dist/client/app/ssr.js +9 -0
  13. package/dist/client/app/utils.js +4 -3
  14. package/dist/client/index.d.ts +128 -129
  15. package/dist/client/index.js +4 -7
  16. package/dist/client/shared.js +46 -2
  17. package/dist/client/theme-default/Layout.vue +59 -176
  18. package/dist/client/theme-default/NotFound.vue +77 -16
  19. package/dist/client/theme-default/components/VPAlgoliaSearchBox.vue +93 -0
  20. package/dist/client/theme-default/components/VPBackdrop.vue +39 -0
  21. package/dist/client/theme-default/components/VPButton.vue +124 -0
  22. package/dist/client/theme-default/components/VPCarbonAds.vue +90 -0
  23. package/dist/client/theme-default/components/VPContent.vue +84 -0
  24. package/dist/client/theme-default/components/VPDoc.vue +175 -0
  25. package/dist/client/theme-default/components/VPDocAside.vue +46 -0
  26. package/dist/client/theme-default/components/VPDocAsideCarbonAds.vue +13 -0
  27. package/dist/client/theme-default/components/VPDocAsideOutline.vue +128 -0
  28. package/dist/client/theme-default/components/VPDocAsideSponsors.vue +17 -0
  29. package/dist/client/theme-default/components/VPDocFooter.vue +167 -0
  30. package/dist/client/theme-default/components/VPDocFooterLastUpdated.vue +43 -0
  31. package/dist/client/theme-default/components/VPFeature.vue +55 -0
  32. package/dist/client/theme-default/components/VPFeatures.vue +107 -0
  33. package/dist/client/theme-default/components/VPFlyout.vue +156 -0
  34. package/dist/client/theme-default/components/VPFooter.vue +53 -0
  35. package/dist/client/theme-default/components/VPHero.vue +314 -0
  36. package/dist/client/theme-default/components/VPHome.vue +35 -0
  37. package/dist/client/theme-default/components/VPHomeFeatures.vue +14 -0
  38. package/dist/client/theme-default/components/VPHomeHero.vue +18 -0
  39. package/dist/client/theme-default/components/VPHomeSponsors.vue +93 -0
  40. package/dist/client/theme-default/components/VPImage.vue +38 -0
  41. package/dist/client/theme-default/components/VPLink.vue +39 -0
  42. package/dist/client/theme-default/components/VPLocalNav.vue +108 -0
  43. package/dist/client/theme-default/components/VPMenu.vue +82 -0
  44. package/dist/client/theme-default/components/VPMenuGroup.vue +46 -0
  45. package/dist/client/theme-default/components/VPMenuLink.vue +55 -0
  46. package/dist/client/theme-default/components/VPNav.vue +64 -0
  47. package/dist/client/theme-default/components/VPNavBar.vue +139 -0
  48. package/dist/client/theme-default/components/VPNavBarAppearance.vue +25 -0
  49. package/dist/client/theme-default/components/VPNavBarExtra.vue +82 -0
  50. package/dist/client/theme-default/components/VPNavBarHamburger.vue +79 -0
  51. package/dist/client/theme-default/components/VPNavBarMenu.vue +29 -0
  52. package/dist/client/theme-default/components/VPNavBarMenuGroup.vue +27 -0
  53. package/dist/client/theme-default/components/VPNavBarMenuLink.vue +56 -0
  54. package/dist/client/theme-default/components/VPNavBarSearch.vue +287 -0
  55. package/dist/client/theme-default/components/VPNavBarSocialLinks.vue +27 -0
  56. package/dist/client/theme-default/components/VPNavBarTitle.vue +62 -0
  57. package/dist/client/theme-default/components/VPNavBarTranslations.vue +45 -0
  58. package/dist/client/theme-default/components/VPNavScreen.vue +103 -0
  59. package/dist/client/theme-default/components/VPNavScreenAppearance.vue +33 -0
  60. package/dist/client/theme-default/components/VPNavScreenMenu.vue +24 -0
  61. package/dist/client/theme-default/components/VPNavScreenMenuGroup.vue +117 -0
  62. package/dist/client/theme-default/components/VPNavScreenMenuGroupLink.vue +33 -0
  63. package/dist/client/theme-default/components/VPNavScreenMenuGroupSection.vue +35 -0
  64. package/dist/client/theme-default/components/VPNavScreenMenuLink.vue +34 -0
  65. package/dist/client/theme-default/components/VPNavScreenSocialLinks.vue +14 -0
  66. package/dist/client/theme-default/components/VPNavScreenTranslations.vue +73 -0
  67. package/dist/client/theme-default/components/VPPage.vue +5 -0
  68. package/dist/client/theme-default/components/VPSidebar.vue +121 -0
  69. package/dist/client/theme-default/components/VPSidebarGroup.vue +124 -0
  70. package/dist/client/theme-default/components/VPSidebarLink.vue +69 -0
  71. package/dist/client/theme-default/components/VPSkipLink.vue +72 -0
  72. package/dist/client/theme-default/components/VPSocialLink.vue +49 -0
  73. package/dist/client/theme-default/components/VPSocialLinks.vue +27 -0
  74. package/dist/client/theme-default/components/VPSponsors.vue +46 -0
  75. package/dist/client/theme-default/components/VPSponsorsGrid.vue +50 -0
  76. package/dist/client/theme-default/components/VPSwitch.vue +66 -0
  77. package/dist/client/theme-default/components/VPSwitchAppearance.vue +74 -0
  78. package/dist/client/theme-default/components/VPTeamMembers.vue +55 -0
  79. package/dist/client/theme-default/components/VPTeamMembersItem.vue +215 -0
  80. package/dist/client/theme-default/components/VPTeamPage.vue +53 -0
  81. package/dist/client/theme-default/components/VPTeamPageSection.vue +77 -0
  82. package/dist/client/theme-default/components/VPTeamPageTitle.vue +63 -0
  83. package/dist/client/theme-default/components/icons/VPIconAlignJustify.vue +8 -0
  84. package/dist/client/theme-default/components/icons/VPIconAlignLeft.vue +8 -0
  85. package/dist/client/theme-default/components/icons/VPIconAlignRight.vue +8 -0
  86. package/dist/client/theme-default/components/icons/{ArrowLeft.vue → VPIconArrowLeft.vue} +0 -0
  87. package/dist/client/theme-default/components/icons/{ArrowRight.vue → VPIconArrowRight.vue} +0 -0
  88. package/dist/client/theme-default/components/icons/VPIconChevronDown.vue +5 -0
  89. package/dist/client/theme-default/components/icons/VPIconChevronLeft.vue +5 -0
  90. package/dist/client/theme-default/components/icons/VPIconChevronRight.vue +5 -0
  91. package/dist/client/theme-default/components/icons/VPIconChevronUp.vue +5 -0
  92. package/dist/client/theme-default/components/icons/VPIconEdit.vue +6 -0
  93. package/dist/client/theme-default/components/icons/VPIconExternalLink.vue +13 -0
  94. package/dist/client/theme-default/components/icons/VPIconHeart.vue +5 -0
  95. package/dist/client/theme-default/components/icons/VPIconLanguages.vue +9 -0
  96. package/dist/client/theme-default/components/icons/VPIconMinus.vue +5 -0
  97. package/dist/client/theme-default/components/icons/VPIconMinusSquare.vue +6 -0
  98. package/dist/client/theme-default/components/icons/VPIconMoon.vue +5 -0
  99. package/dist/client/theme-default/components/icons/VPIconMoreHorizontal.vue +7 -0
  100. package/dist/client/theme-default/components/icons/VPIconPlus.vue +5 -0
  101. package/dist/client/theme-default/components/icons/VPIconPlusSquare.vue +6 -0
  102. package/dist/client/theme-default/components/icons/VPIconSun.vue +13 -0
  103. package/dist/client/theme-default/composables/aside.js +17 -0
  104. package/dist/client/theme-default/composables/copy-code.js +71 -0
  105. package/dist/client/theme-default/composables/edit-link.js +11 -0
  106. package/dist/client/theme-default/composables/flyout.js +40 -0
  107. package/dist/client/theme-default/composables/nav.js +29 -1
  108. package/dist/client/theme-default/composables/outline.js +121 -0
  109. package/dist/client/theme-default/composables/prev-next.js +22 -0
  110. package/dist/client/theme-default/composables/sidebar.js +63 -0
  111. package/dist/client/theme-default/composables/sponsor-grid.js +94 -0
  112. package/dist/client/theme-default/fonts/inter-cyrillic-ext.woff2 +0 -0
  113. package/dist/client/theme-default/fonts/inter-cyrillic.woff2 +0 -0
  114. package/dist/client/theme-default/fonts/inter-greek-ext.woff2 +0 -0
  115. package/dist/client/theme-default/fonts/inter-greek.woff2 +0 -0
  116. package/dist/client/theme-default/fonts/inter-italic-cyrillic-ext.woff2 +0 -0
  117. package/dist/client/theme-default/fonts/inter-italic-cyrillic.woff2 +0 -0
  118. package/dist/client/theme-default/fonts/inter-italic-greek-ext.woff2 +0 -0
  119. package/dist/client/theme-default/fonts/inter-italic-greek.woff2 +0 -0
  120. package/dist/client/theme-default/fonts/inter-italic-latin-ext.woff2 +0 -0
  121. package/dist/client/theme-default/fonts/inter-italic-latin.woff2 +0 -0
  122. package/dist/client/theme-default/fonts/inter-italic-vietnamese.woff2 +0 -0
  123. package/dist/client/theme-default/fonts/inter-latin-ext.woff2 +0 -0
  124. package/dist/client/theme-default/fonts/inter-latin.woff2 +0 -0
  125. package/dist/client/theme-default/fonts/inter-roman-cyrillic-ext.woff2 +0 -0
  126. package/dist/client/theme-default/fonts/inter-roman-cyrillic.woff2 +0 -0
  127. package/dist/client/theme-default/fonts/inter-roman-greek-ext.woff2 +0 -0
  128. package/dist/client/theme-default/fonts/inter-roman-greek.woff2 +0 -0
  129. package/dist/client/theme-default/fonts/inter-roman-latin-ext.woff2 +0 -0
  130. package/dist/client/theme-default/fonts/inter-roman-latin.woff2 +0 -0
  131. package/dist/client/theme-default/fonts/inter-roman-vietnamese.woff2 +0 -0
  132. package/dist/client/theme-default/fonts/inter-vietnamese.woff2 +0 -0
  133. package/dist/client/theme-default/index.js +15 -4
  134. package/dist/client/theme-default/styles/base.css +215 -0
  135. package/dist/client/theme-default/styles/components/custom-block.css +90 -0
  136. package/dist/client/theme-default/styles/components/vp-code.css +7 -0
  137. package/dist/client/theme-default/styles/components/vp-doc.css +445 -0
  138. package/dist/client/theme-default/styles/components/vp-sponsor.css +155 -0
  139. package/dist/client/theme-default/styles/fonts.css +217 -0
  140. package/dist/client/theme-default/styles/utils.css +9 -0
  141. package/dist/client/theme-default/styles/vars.css +340 -54
  142. package/dist/client/theme-default/support/sidebar.js +37 -0
  143. package/dist/client/theme-default/support/socialIcons.js +11 -0
  144. package/dist/client/theme-default/support/utils.js +63 -0
  145. package/dist/node/cli.js +47 -34
  146. package/dist/node/index.d.ts +488 -318
  147. package/dist/node/index.js +23 -37
  148. package/dist/node/serve-a32ee2b7.js +66352 -0
  149. package/dist/node-cjs/cli.cjs +316 -0
  150. package/dist/node-cjs/index.cjs +39 -0
  151. package/dist/{node/serve-777539c0.js → node-cjs/serve-6a2c6464.cjs} +32619 -32234
  152. package/package.json +112 -80
  153. package/theme.d.ts +13 -3
  154. package/types/default-theme.d.ts +184 -75
  155. package/types/index.d.ts +35 -2
  156. package/types/shared.d.ts +26 -7
  157. package/dist/client/app/components/Debug.vue +0 -86
  158. package/dist/client/theme-default/components/AlgoliaSearchBox.vue +0 -188
  159. package/dist/client/theme-default/components/BuySellAds.vue +0 -152
  160. package/dist/client/theme-default/components/CarbonAds.vue +0 -99
  161. package/dist/client/theme-default/components/EditLink.vue +0 -38
  162. package/dist/client/theme-default/components/Home.vue +0 -31
  163. package/dist/client/theme-default/components/HomeFeatures.vue +0 -143
  164. package/dist/client/theme-default/components/HomeFooter.vue +0 -50
  165. package/dist/client/theme-default/components/HomeHero.vue +0 -161
  166. package/dist/client/theme-default/components/LastUpdated.vue +0 -60
  167. package/dist/client/theme-default/components/NavBar.vue +0 -60
  168. package/dist/client/theme-default/components/NavBarTitle.vue +0 -41
  169. package/dist/client/theme-default/components/NavDropdownLink.vue +0 -135
  170. package/dist/client/theme-default/components/NavDropdownLinkItem.vue +0 -76
  171. package/dist/client/theme-default/components/NavLink.vue +0 -61
  172. package/dist/client/theme-default/components/NavLinks.vue +0 -52
  173. package/dist/client/theme-default/components/NextAndPrevLinks.vue +0 -88
  174. package/dist/client/theme-default/components/Page.vue +0 -53
  175. package/dist/client/theme-default/components/PageFooter.vue +0 -44
  176. package/dist/client/theme-default/components/SideBar.vue +0 -60
  177. package/dist/client/theme-default/components/SideBarLink.js +0 -68
  178. package/dist/client/theme-default/components/SideBarLinks.vue +0 -12
  179. package/dist/client/theme-default/components/ToggleSideBarButton.vue +0 -46
  180. package/dist/client/theme-default/components/icons/OutboundLink.vue +0 -31
  181. package/dist/client/theme-default/composables/activeSidebarLink.js +0 -99
  182. package/dist/client/theme-default/composables/editLink.js +0 -49
  183. package/dist/client/theme-default/composables/navLink.js +0 -42
  184. package/dist/client/theme-default/composables/nextAndPrevLinks.js +0 -37
  185. package/dist/client/theme-default/composables/repo.js +0 -38
  186. package/dist/client/theme-default/composables/sideBar.js +0 -57
  187. package/dist/client/theme-default/config.js +0 -1
  188. package/dist/client/theme-default/styles/code.css +0 -299
  189. package/dist/client/theme-default/styles/custom-blocks.css +0 -76
  190. package/dist/client/theme-default/styles/layout.css +0 -236
  191. package/dist/client/theme-default/styles/sidebar-links.css +0 -107
  192. package/dist/client/theme-default/support/sideBar.js +0 -46
  193. 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,5 @@
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" />
4
+
5
+ export * from './dist/client/index.js'
@@ -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,5 +1,5 @@
1
1
  import { defineComponent, h } from 'vue';
2
- import { useRoute } from '../router';
2
+ import { useRoute } from '../router.js';
3
3
  export const Content = defineComponent({
4
4
  name: 'VitePressContent',
5
5
  setup() {
@@ -1,4 +1,5 @@
1
1
  import { watchEffect } from 'vue';
2
+ import { createTitle, mergeHead } from '../../shared.js';
2
3
  export function useUpdateHead(route, siteDataByRouteRef) {
3
4
  let managedHeadTags = [];
4
5
  let isFirstUpdate = true;
@@ -9,60 +10,25 @@ export function useUpdateHead(route, siteDataByRouteRef) {
9
10
  isFirstUpdate = false;
10
11
  return;
11
12
  }
12
- const newEls = [];
13
- const commonLength = Math.min(managedHeadTags.length, newTags.length);
14
- for (let i = 0; i < commonLength; i++) {
15
- let el = managedHeadTags[i];
16
- const [tag, attrs, innerHTML = ''] = newTags[i];
17
- if (el.tagName.toLocaleLowerCase() === tag) {
18
- for (const key in attrs) {
19
- if (el.getAttribute(key) !== attrs[key]) {
20
- el.setAttribute(key, attrs[key]);
21
- }
22
- }
23
- for (let i = 0; i < el.attributes.length; i++) {
24
- const name = el.attributes[i].name;
25
- if (!(name in attrs)) {
26
- el.removeAttribute(name);
27
- }
28
- }
29
- if (el.innerHTML !== innerHTML) {
30
- el.innerHTML = innerHTML;
31
- }
32
- }
33
- else {
34
- document.head.removeChild(el);
35
- el = createHeadElement(newTags[i]);
36
- document.head.append(el);
37
- }
38
- newEls.push(el);
39
- }
40
- managedHeadTags
41
- .slice(commonLength)
42
- .forEach((el) => document.head.removeChild(el));
43
- newTags.slice(commonLength).forEach((headConfig) => {
13
+ managedHeadTags.forEach((el) => document.head.removeChild(el));
14
+ managedHeadTags = [];
15
+ newTags.forEach((headConfig) => {
44
16
  const el = createHeadElement(headConfig);
45
17
  document.head.appendChild(el);
46
- newEls.push(el);
18
+ managedHeadTags.push(el);
47
19
  });
48
- managedHeadTags = newEls;
49
20
  };
50
21
  watchEffect(() => {
51
22
  const pageData = route.data;
52
23
  const siteData = siteDataByRouteRef.value;
53
- const pageTitle = pageData && pageData.title;
54
24
  const pageDescription = pageData && pageData.description;
55
- const frontmatterHead = pageData && pageData.frontmatter.head;
25
+ const frontmatterHead = (pageData && pageData.frontmatter.head) || [];
56
26
  // update title and description
57
- document.title = (pageTitle ? pageTitle + ` | ` : ``) + siteData.title;
27
+ document.title = createTitle(siteData, pageData);
58
28
  document
59
29
  .querySelector(`meta[name=description]`)
60
30
  .setAttribute('content', pageDescription || siteData.description);
61
- updateHeadTags([
62
- // site head can only change during dev
63
- ...(import.meta.env.DEV ? siteData.head : []),
64
- ...(frontmatterHead ? filterOutHeadDescription(frontmatterHead) : [])
65
- ]);
31
+ updateHeadTags(mergeHead(siteData.head, filterOutHeadDescription(frontmatterHead)));
66
32
  });
67
33
  }
68
34
  function createHeadElement([tag, attrs, innerHTML]) {
@@ -1,8 +1,8 @@
1
1
  // Customized pre-fetch for page chunks based on
2
2
  // https://github.com/GoogleChromeLabs/quicklink
3
- import { useRoute } from '../router';
3
+ import { useRoute } from '../router.js';
4
4
  import { onMounted, onUnmounted, watch } from 'vue';
5
- import { inBrowser, pathToFile } from '../utils';
5
+ import { inBrowser, pathToFile } from '../utils.js';
6
6
  const hasFetched = new Set();
7
7
  const createLink = () => document.createElement('link');
8
8
  const viaDOM = (url) => {
@@ -1,17 +1,16 @@
1
1
  import { shallowRef, readonly, computed, inject } from 'vue';
2
- import serializedSiteData from '@siteData';
3
- import { resolveSiteDataByRoute } from '../shared';
4
- import { withBase } from './utils';
2
+ import siteData from '@siteData';
3
+ import { resolveSiteDataByRoute, createTitle } from '../shared.js';
4
+ import { withBase } from './utils.js';
5
5
  export const dataSymbol = Symbol();
6
- export const siteDataRef = shallowRef(parse(serializedSiteData));
7
- function parse(data) {
8
- const parsed = JSON.parse(data);
9
- return (import.meta.env.DEV ? readonly(parsed) : parsed);
10
- }
6
+ // site data is a singleton
7
+ export const siteDataRef = shallowRef((import.meta.env.PROD ? siteData : readonly(siteData)));
11
8
  // hmr
12
9
  if (import.meta.hot) {
13
10
  import.meta.hot.accept('/@siteData', (m) => {
14
- siteDataRef.value = parse(m.default);
11
+ if (m) {
12
+ siteDataRef.value = m.default;
13
+ }
15
14
  });
16
15
  }
17
16
  // per-app data
@@ -29,9 +28,7 @@ export function initData(route) {
29
28
  return withBase(path || '/');
30
29
  }),
31
30
  title: computed(() => {
32
- return route.data.title
33
- ? route.data.title + ' | ' + site.value.title
34
- : site.value.title;
31
+ return createTitle(site.value, route.data);
35
32
  }),
36
33
  description: computed(() => {
37
34
  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,15 +1,15 @@
1
- import { createApp as createClientApp, createSSRApp, defineAsyncComponent, h, onMounted, watch } from 'vue';
2
- import { inBrowser, pathToFile } from './utils';
3
- import { RouterSymbol, createRouter } from './router';
4
- import { siteDataRef, useData } from './data';
5
- import { useUpdateHead } from './composables/head';
6
- import Theme from '/@theme/index';
7
- import { usePrefetch } from './composables/preFetch';
8
- import { dataSymbol, initData } from './data';
9
- import { Content } from './components/Content';
10
- import { ClientOnly } from './components/ClientOnly';
1
+ import { createApp as createClientApp, createSSRApp, defineComponent, h, onMounted, watch } from 'vue';
2
+ import Theme from '@theme/index';
3
+ import { inBrowser, pathToFile } from './utils.js';
4
+ import { RouterSymbol, createRouter } from './router.js';
5
+ import { siteDataRef, useData } from './data.js';
6
+ import { useUpdateHead } from './composables/head.js';
7
+ import { usePrefetch } from './composables/preFetch.js';
8
+ import { dataSymbol, initData } from './data.js';
9
+ import { Content } from './components/Content.js';
10
+ import { ClientOnly } from './components/ClientOnly.js';
11
11
  const NotFound = Theme.NotFound || (() => '404 Not Found');
12
- const VitePressApp = {
12
+ const VitePressApp = defineComponent({
13
13
  name: 'VitePressApp',
14
14
  setup() {
15
15
  const { site } = useData();
@@ -23,26 +23,22 @@ const VitePressApp = {
23
23
  // in prod mode, enable intersectionObserver based pre-fetch
24
24
  usePrefetch();
25
25
  }
26
+ if (Theme.setup)
27
+ Theme.setup();
26
28
  return () => h(Theme.Layout);
27
29
  }
28
- };
30
+ });
29
31
  export function createApp() {
30
32
  const router = newRouter();
31
- handleHMR(router);
32
33
  const app = newApp();
33
34
  app.provide(RouterSymbol, router);
34
35
  const data = initData(router.route);
35
36
  app.provide(dataSymbol, data);
36
- if (inBrowser) {
37
- // dynamically update head tags
38
- useUpdateHead(router.route, data.site);
39
- }
37
+ // provide this to avoid circular dependency in VPContent
38
+ app.provide('NotFound', NotFound);
40
39
  // install global components
41
40
  app.component('Content', Content);
42
41
  app.component('ClientOnly', ClientOnly);
43
- app.component('Debug', import.meta.env.PROD
44
- ? () => null
45
- : defineAsyncComponent(() => import('./components/Debug.vue')));
46
42
  // expose $frontmatter
47
43
  Object.defineProperty(app.config.globalProperties, '$frontmatter', {
48
44
  get() {
@@ -56,7 +52,11 @@ export function createApp() {
56
52
  siteData: siteDataRef
57
53
  });
58
54
  }
59
- return { app, router };
55
+ // setup devtools in dev mode
56
+ if (import.meta.env.DEV || __VUE_PROD_DEVTOOLS__) {
57
+ import('./devtools.js').then(({ setupDevtools }) => setupDevtools(app, router, data));
58
+ }
59
+ return { app, router, data };
60
60
  }
61
61
  function newApp() {
62
62
  return import.meta.env.PROD
@@ -77,36 +77,18 @@ function newRouter() {
77
77
  if (isInitialPageLoad || initialPath === pageFilePath) {
78
78
  pageFilePath = pageFilePath.replace(/\.js$/, '.lean.js');
79
79
  }
80
- // in browser: native dynamic import
81
80
  if (inBrowser) {
82
81
  isInitialPageLoad = false;
83
- return import(/*@vite-ignore*/ pageFilePath);
84
82
  }
85
- // SSR: sync require
86
- // @ts-ignore
87
- return require(pageFilePath);
83
+ return import(/*@vite-ignore*/ pageFilePath);
88
84
  }, NotFound);
89
85
  }
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
86
  if (inBrowser) {
107
- const { app, router } = createApp();
87
+ const { app, router, data } = createApp();
108
88
  // wait until page component is fetched before mounting
109
89
  router.go().then(() => {
90
+ // dynamically update head tags
91
+ useUpdateHead(router.route, data.site);
110
92
  app.mount('#app');
111
93
  });
112
94
  }
@@ -1,18 +1,11 @@
1
1
  import { reactive, inject, markRaw, nextTick, readonly } from 'vue';
2
- import { inBrowser } from './utils';
3
- import { siteDataRef } from './data';
2
+ import { notFoundPageData } from '../shared.js';
3
+ import { inBrowser, withBase } from './utils.js';
4
+ import { siteDataRef } from './data.js';
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,
@@ -21,11 +14,14 @@ const getDefaultRoute = () => ({
21
14
  export function createRouter(loadPageModule, fallbackComponent) {
22
15
  const route = reactive(getDefaultRoute());
23
16
  function go(href = inBrowser ? location.href : '/') {
24
- // ensure correct deep link so page refresh lands on correct files.
25
17
  const url = new URL(href, fakeHost);
26
- if (!url.pathname.endsWith('/') && !url.pathname.endsWith('.html')) {
27
- url.pathname += '.html';
28
- href = url.pathname + url.search + url.hash;
18
+ if (siteDataRef.value.cleanUrls === 'disabled') {
19
+ // ensure correct deep link so page refresh lands on correct files.
20
+ // if cleanUrls is enabled, the server should handle this
21
+ if (!url.pathname.endsWith('/') && !url.pathname.endsWith('.html')) {
22
+ url.pathname += '.html';
23
+ href = url.pathname + url.search + url.hash;
24
+ }
29
25
  }
30
26
  if (inBrowser) {
31
27
  // save scroll position before changing url
@@ -39,23 +35,18 @@ export function createRouter(loadPageModule, fallbackComponent) {
39
35
  const targetLoc = new URL(href, fakeHost);
40
36
  const pendingPath = (latestPendingPath = targetLoc.pathname);
41
37
  try {
42
- let page = loadPageModule(pendingPath);
43
- // only await if it returns a Promise - this allows sync resolution
44
- // on initial render in SSR.
45
- if ('then' in page && typeof page.then === 'function') {
46
- page = await page;
47
- }
38
+ let page = await loadPageModule(pendingPath);
48
39
  if (latestPendingPath === pendingPath) {
49
40
  latestPendingPath = null;
50
41
  const { default: comp, __pageData } = page;
51
42
  if (!comp) {
52
43
  throw new Error(`Invalid route component: ${comp}`);
53
44
  }
54
- route.path = pendingPath;
45
+ route.path = inBrowser ? pendingPath : withBase(pendingPath);
55
46
  route.component = markRaw(comp);
56
47
  route.data = import.meta.env.PROD
57
- ? markRaw(JSON.parse(__pageData))
58
- : readonly(JSON.parse(__pageData));
48
+ ? markRaw(__pageData)
49
+ : readonly(__pageData);
59
50
  if (inBrowser) {
60
51
  nextTick(() => {
61
52
  if (targetLoc.hash && !scrollPosition) {
@@ -77,7 +68,7 @@ export function createRouter(loadPageModule, fallbackComponent) {
77
68
  }
78
69
  }
79
70
  catch (err) {
80
- if (!err.message.match(/fetch/)) {
71
+ if (!/fetch/.test(err.message) && !/^\/404(\.html|\/)?$/.test(href)) {
81
72
  console.error(err);
82
73
  }
83
74
  // retry on fetch fail: the page to hash map may have been invalidated
@@ -94,7 +85,7 @@ export function createRouter(loadPageModule, fallbackComponent) {
94
85
  }
95
86
  if (latestPendingPath === pendingPath) {
96
87
  latestPendingPath = null;
97
- route.path = pendingPath;
88
+ route.path = inBrowser ? pendingPath : withBase(pendingPath);
98
89
  route.component = fallbackComponent ? markRaw(fallbackComponent) : null;
99
90
  route.data = notFoundPageData;
100
91
  }
@@ -104,7 +95,7 @@ export function createRouter(loadPageModule, fallbackComponent) {
104
95
  window.addEventListener('click', (e) => {
105
96
  const link = e.target.closest('a');
106
97
  if (link) {
107
- const { href, protocol, hostname, pathname, hash, target } = link;
98
+ const { href, origin, pathname, hash, search, target } = link;
108
99
  const currentUrl = window.location;
109
100
  const extMatch = pathname.match(/\.\w+$/);
110
101
  // only intercept inbound links
@@ -113,11 +104,12 @@ export function createRouter(loadPageModule, fallbackComponent) {
113
104
  !e.altKey &&
114
105
  !e.metaKey &&
115
106
  target !== `_blank` &&
116
- protocol === currentUrl.protocol &&
117
- hostname === currentUrl.hostname &&
107
+ origin === currentUrl.origin &&
108
+ // don't intercept if non-html extension is present
118
109
  !(extMatch && extMatch[0] !== '.html')) {
119
110
  e.preventDefault();
120
- if (pathname === currentUrl.pathname) {
111
+ if (pathname === currentUrl.pathname &&
112
+ search === currentUrl.search) {
121
113
  // scroll between hash anchors in the same page
122
114
  if (hash && hash !== currentUrl.hash) {
123
115
  history.pushState(null, '', hash);
@@ -140,6 +132,7 @@ export function createRouter(loadPageModule, fallbackComponent) {
140
132
  e.preventDefault();
141
133
  });
142
134
  }
135
+ handleHMR(route);
143
136
  return {
144
137
  route,
145
138
  go
@@ -150,7 +143,6 @@ export function useRouter() {
150
143
  if (!router) {
151
144
  throw new Error('useRouter() is called without provider.');
152
145
  }
153
- // @ts-ignore
154
146
  return router;
155
147
  }
156
148
  export function useRoute() {
@@ -190,3 +182,19 @@ function scrollTo(el, hash, smooth = false) {
190
182
  }
191
183
  }
192
184
  }
185
+ function handleHMR(route) {
186
+ // update route.data on HMR updates of active page
187
+ if (import.meta.hot) {
188
+ // hot reload pageData
189
+ import.meta.hot.on('vitepress:pageData', (payload) => {
190
+ if (shouldHotReload(payload)) {
191
+ route.data = payload.pageData;
192
+ }
193
+ });
194
+ }
195
+ }
196
+ function shouldHotReload(payload) {
197
+ const payloadPath = payload.path.replace(/(\bindex)?\.md$/, '');
198
+ const locationPath = location.pathname.replace(/(\bindex)?\.html$/, '');
199
+ return payloadPath === locationPath;
200
+ }
@@ -0,0 +1,9 @@
1
+ // entry for SSR
2
+ import { createApp } from './index.js';
3
+ // @ts-ignore pending vue release
4
+ import { renderToString } from 'vue/server-renderer';
5
+ export async function render(path) {
6
+ const { app, router } = createApp();
7
+ await router.go(path);
8
+ return renderToString(app);
9
+ }
@@ -1,5 +1,5 @@
1
- import { siteDataRef } from './data';
2
- import { inBrowser, EXTERNAL_URL_RE } from '../shared';
1
+ import { siteDataRef } from './data.js';
2
+ import { inBrowser, EXTERNAL_URL_RE } from '../shared.js';
3
3
  export { inBrowser };
4
4
  /**
5
5
  * Join two paths by resolving the slash collision.
@@ -31,7 +31,8 @@ export function pathToFile(path) {
31
31
  // /foo/bar.html -> ./foo_bar.md
32
32
  if (inBrowser) {
33
33
  const base = import.meta.env.BASE_URL;
34
- pagePath = pagePath.slice(base.length).replace(/\//g, '_') + '.md';
34
+ pagePath =
35
+ (pagePath.slice(base.length).replace(/\//g, '_') || 'index') + '.md';
35
36
  // client production build needs to account for page hash, which is
36
37
  // injected directly in the page's html
37
38
  const pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()];