vitepress 0.22.4 → 1.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/bin/vitepress.js +1 -1
- package/client.d.ts +4 -3
- package/dist/client/app/components/ClientOnly.js +10 -10
- package/dist/client/app/components/Content.js +11 -11
- package/dist/client/app/composables/head.js +51 -85
- package/dist/client/app/composables/preFetch.js +94 -94
- package/dist/client/app/data.js +44 -47
- package/dist/client/app/devtools.js +28 -0
- package/dist/client/app/index.js +94 -110
- package/dist/client/app/router.js +200 -192
- package/dist/client/app/ssr.js +9 -0
- package/dist/client/app/theme.js +1 -1
- package/dist/client/app/utils.js +47 -46
- package/dist/client/index.d.ts +108 -113
- package/dist/client/index.js +9 -12
- package/dist/client/shared.js +109 -65
- package/dist/client/theme-default/Layout.vue +59 -176
- package/dist/client/theme-default/NotFound.vue +77 -16
- package/dist/client/theme-default/components/VPAlgoliaSearchBox.vue +93 -0
- package/dist/client/theme-default/components/VPBackdrop.vue +39 -0
- package/dist/client/theme-default/components/VPButton.vue +124 -0
- package/dist/client/theme-default/components/VPCarbonAds.vue +90 -0
- package/dist/client/theme-default/components/VPContent.vue +84 -0
- package/dist/client/theme-default/components/VPDoc.vue +175 -0
- package/dist/client/theme-default/components/VPDocAside.vue +46 -0
- package/dist/client/theme-default/components/VPDocAsideCarbonAds.vue +13 -0
- package/dist/client/theme-default/components/VPDocAsideOutline.vue +122 -0
- package/dist/client/theme-default/components/VPDocAsideSponsors.vue +17 -0
- package/dist/client/theme-default/components/VPDocFooter.vue +167 -0
- package/dist/client/theme-default/components/VPDocFooterLastUpdated.vue +43 -0
- package/dist/client/theme-default/components/VPFeature.vue +55 -0
- package/dist/client/theme-default/components/VPFeatures.vue +107 -0
- package/dist/client/theme-default/components/VPFlyout.vue +156 -0
- package/dist/client/theme-default/components/VPFooter.vue +53 -0
- package/dist/client/theme-default/components/VPHero.vue +314 -0
- package/dist/client/theme-default/components/VPHome.vue +35 -0
- package/dist/client/theme-default/components/VPHomeFeatures.vue +14 -0
- package/dist/client/theme-default/components/VPHomeHero.vue +18 -0
- package/dist/client/theme-default/components/VPHomeSponsors.vue +93 -0
- package/dist/client/theme-default/components/VPImage.vue +38 -0
- package/dist/client/theme-default/components/VPLink.vue +39 -0
- package/dist/client/theme-default/components/VPLocalNav.vue +108 -0
- package/dist/client/theme-default/components/VPMenu.vue +82 -0
- package/dist/client/theme-default/components/VPMenuGroup.vue +46 -0
- package/dist/client/theme-default/components/VPMenuLink.vue +55 -0
- package/dist/client/theme-default/components/VPNav.vue +64 -0
- package/dist/client/theme-default/components/VPNavBar.vue +139 -0
- package/dist/client/theme-default/components/VPNavBarAppearance.vue +25 -0
- package/dist/client/theme-default/components/VPNavBarExtra.vue +82 -0
- package/dist/client/theme-default/components/VPNavBarHamburger.vue +79 -0
- package/dist/client/theme-default/components/VPNavBarMenu.vue +29 -0
- package/dist/client/theme-default/components/VPNavBarMenuGroup.vue +27 -0
- package/dist/client/theme-default/components/VPNavBarMenuLink.vue +56 -0
- package/dist/client/theme-default/components/VPNavBarSearch.vue +287 -0
- package/dist/client/theme-default/components/VPNavBarSocialLinks.vue +27 -0
- package/dist/client/theme-default/components/VPNavBarTitle.vue +62 -0
- package/dist/client/theme-default/components/VPNavBarTranslations.vue +45 -0
- package/dist/client/theme-default/components/VPNavScreen.vue +103 -0
- package/dist/client/theme-default/components/VPNavScreenAppearance.vue +33 -0
- package/dist/client/theme-default/components/VPNavScreenMenu.vue +24 -0
- package/dist/client/theme-default/components/VPNavScreenMenuGroup.vue +117 -0
- package/dist/client/theme-default/components/VPNavScreenMenuGroupLink.vue +33 -0
- package/dist/client/theme-default/components/VPNavScreenMenuGroupSection.vue +35 -0
- package/dist/client/theme-default/components/VPNavScreenMenuLink.vue +34 -0
- package/dist/client/theme-default/components/VPNavScreenSocialLinks.vue +14 -0
- package/dist/client/theme-default/components/VPNavScreenTranslations.vue +73 -0
- package/dist/client/theme-default/components/VPPage.vue +5 -0
- package/dist/client/theme-default/components/VPSidebar.vue +121 -0
- package/dist/client/theme-default/components/VPSidebarGroup.vue +124 -0
- package/dist/client/theme-default/components/VPSidebarLink.vue +69 -0
- package/dist/client/theme-default/components/VPSkipLink.vue +72 -0
- package/dist/client/theme-default/components/VPSocialLink.vue +49 -0
- package/dist/client/theme-default/components/VPSocialLinks.vue +27 -0
- package/dist/client/theme-default/components/VPSponsors.vue +46 -0
- package/dist/client/theme-default/components/VPSponsorsGrid.vue +50 -0
- package/dist/client/theme-default/components/VPSwitch.vue +66 -0
- package/dist/client/theme-default/components/VPSwitchAppearance.vue +74 -0
- package/dist/client/theme-default/components/VPTeamMembers.vue +55 -0
- package/dist/client/theme-default/components/VPTeamMembersItem.vue +215 -0
- package/dist/client/theme-default/components/VPTeamPage.vue +53 -0
- package/dist/client/theme-default/components/VPTeamPageSection.vue +77 -0
- package/dist/client/theme-default/components/VPTeamPageTitle.vue +63 -0
- package/dist/client/theme-default/components/icons/VPIconAlignJustify.vue +8 -0
- package/dist/client/theme-default/components/icons/VPIconAlignLeft.vue +8 -0
- package/dist/client/theme-default/components/icons/VPIconAlignRight.vue +8 -0
- package/dist/client/theme-default/components/icons/{ArrowLeft.vue → VPIconArrowLeft.vue} +0 -0
- package/dist/client/theme-default/components/icons/{ArrowRight.vue → VPIconArrowRight.vue} +0 -0
- package/dist/client/theme-default/components/icons/VPIconChevronDown.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconChevronLeft.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconChevronRight.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconChevronUp.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconEdit.vue +6 -0
- package/dist/client/theme-default/components/icons/VPIconExternalLink.vue +13 -0
- package/dist/client/theme-default/components/icons/VPIconHeart.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconLanguages.vue +9 -0
- package/dist/client/theme-default/components/icons/VPIconMinus.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconMinusSquare.vue +6 -0
- package/dist/client/theme-default/components/icons/VPIconMoon.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconMoreHorizontal.vue +7 -0
- package/dist/client/theme-default/components/icons/VPIconPlus.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconPlusSquare.vue +6 -0
- package/dist/client/theme-default/components/icons/VPIconSun.vue +13 -0
- package/dist/client/theme-default/composables/aside.js +17 -0
- package/dist/client/theme-default/composables/copy-code.js +71 -0
- package/dist/client/theme-default/composables/edit-link.js +11 -0
- package/dist/client/theme-default/composables/flyout.js +40 -0
- package/dist/client/theme-default/composables/nav.js +53 -25
- package/dist/client/theme-default/composables/outline.js +96 -0
- package/dist/client/theme-default/composables/prev-next.js +22 -0
- package/dist/client/theme-default/composables/sidebar.js +63 -0
- package/dist/client/theme-default/composables/sponsor-grid.js +94 -0
- package/dist/client/theme-default/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-cyrillic.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-greek-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-greek.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-italic-cyrillic-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-italic-cyrillic.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-italic-greek-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-italic-greek.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-italic-latin-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-italic-latin.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-italic-vietnamese.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-latin-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-latin.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-cyrillic-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-cyrillic.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-greek-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-greek.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-latin-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-latin.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-vietnamese.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-vietnamese.woff2 +0 -0
- package/dist/client/theme-default/index.js +23 -12
- package/dist/client/theme-default/styles/base.css +215 -0
- package/dist/client/theme-default/styles/components/custom-block.css +90 -0
- package/dist/client/theme-default/styles/components/vp-code.css +7 -0
- package/dist/client/theme-default/styles/components/vp-doc.css +445 -0
- package/dist/client/theme-default/styles/components/vp-sponsor.css +155 -0
- package/dist/client/theme-default/styles/fonts.css +217 -0
- package/dist/client/theme-default/styles/utils.css +9 -0
- package/dist/client/theme-default/styles/vars.css +340 -54
- package/dist/client/theme-default/support/sidebar.js +37 -0
- package/dist/client/theme-default/support/socialIcons.js +11 -0
- package/dist/client/theme-default/support/utils.js +63 -0
- package/dist/node/cli.js +40 -32
- package/dist/node/index.d.ts +439 -278
- package/dist/node/index.js +23 -37
- package/dist/node/serve-d62982a1.js +66392 -0
- package/dist/node-cjs/cli.cjs +316 -0
- package/dist/node-cjs/index.cjs +39 -0
- package/dist/{node/serve-3035f99b.js → node-cjs/serve-dd119bdb.cjs} +33134 -22707
- package/package.json +115 -79
- package/theme.d.ts +13 -3
- package/types/default-theme.d.ts +183 -74
- package/types/index.d.ts +35 -2
- package/types/shared.d.ts +22 -8
- package/dist/client/app/components/Debug.vue +0 -86
- package/dist/client/theme-default/components/AlgoliaSearchBox.vue +0 -188
- package/dist/client/theme-default/components/BuySellAds.vue +0 -152
- package/dist/client/theme-default/components/CarbonAds.vue +0 -99
- package/dist/client/theme-default/components/EditLink.vue +0 -38
- package/dist/client/theme-default/components/Home.vue +0 -31
- package/dist/client/theme-default/components/HomeFeatures.vue +0 -143
- package/dist/client/theme-default/components/HomeFooter.vue +0 -50
- package/dist/client/theme-default/components/HomeHero.vue +0 -161
- package/dist/client/theme-default/components/LastUpdated.vue +0 -60
- package/dist/client/theme-default/components/NavBar.vue +0 -60
- package/dist/client/theme-default/components/NavBarTitle.vue +0 -41
- package/dist/client/theme-default/components/NavDropdownLink.vue +0 -135
- package/dist/client/theme-default/components/NavDropdownLinkItem.vue +0 -76
- package/dist/client/theme-default/components/NavLink.vue +0 -61
- package/dist/client/theme-default/components/NavLinks.vue +0 -52
- package/dist/client/theme-default/components/NextAndPrevLinks.vue +0 -88
- package/dist/client/theme-default/components/Page.vue +0 -53
- package/dist/client/theme-default/components/PageFooter.vue +0 -44
- package/dist/client/theme-default/components/SideBar.vue +0 -60
- package/dist/client/theme-default/components/SideBarLink.js +0 -68
- package/dist/client/theme-default/components/SideBarLinks.vue +0 -12
- package/dist/client/theme-default/components/ToggleSideBarButton.vue +0 -46
- package/dist/client/theme-default/components/icons/OutboundLink.vue +0 -31
- package/dist/client/theme-default/composables/activeSidebarLink.js +0 -99
- package/dist/client/theme-default/composables/editLink.js +0 -49
- package/dist/client/theme-default/composables/navLink.js +0 -42
- package/dist/client/theme-default/composables/nextAndPrevLinks.js +0 -37
- package/dist/client/theme-default/composables/repo.js +0 -38
- package/dist/client/theme-default/composables/sideBar.js +0 -57
- package/dist/client/theme-default/config.js +0 -1
- package/dist/client/theme-default/styles/code.css +0 -299
- package/dist/client/theme-default/styles/custom-blocks.css +0 -76
- package/dist/client/theme-default/styles/layout.css +0 -236
- package/dist/client/theme-default/styles/sidebar-links.css +0 -107
- package/dist/client/theme-default/support/sideBar.js +0 -46
- package/dist/client/theme-default/utils.js +0 -63
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# (
|
|
1
|
+
# VitePress (alpha) 📝💨
|
|
2
2
|
|
|
3
3
|
[](https://github.com/vuejs/vitepress/actions)
|
|
4
4
|
[](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
|
-
|
|
2
|
+
import('../dist/node/cli.js')
|
package/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// re-export vite client types
|
|
2
|
-
//
|
|
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,10 +1,10 @@
|
|
|
1
|
-
import { ref, onMounted
|
|
2
|
-
export const ClientOnly = defineComponent({
|
|
3
|
-
setup(_, { slots }) {
|
|
4
|
-
const show = ref(false);
|
|
5
|
-
onMounted(() => {
|
|
6
|
-
show.value = true;
|
|
7
|
-
});
|
|
8
|
-
return () => (show.value && slots.default ? slots.default() : null);
|
|
9
|
-
}
|
|
10
|
-
});
|
|
1
|
+
import { defineComponent, ref, onMounted } from 'vue';
|
|
2
|
+
export const ClientOnly = defineComponent({
|
|
3
|
+
setup(_, { slots }) {
|
|
4
|
+
const show = ref(false);
|
|
5
|
+
onMounted(() => {
|
|
6
|
+
show.value = true;
|
|
7
|
+
});
|
|
8
|
+
return () => (show.value && slots.default ? slots.default() : null);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { defineComponent, h } from 'vue';
|
|
2
|
-
import { useRoute } from '../router';
|
|
3
|
-
export const Content = defineComponent({
|
|
4
|
-
name: 'VitePressContent',
|
|
5
|
-
setup() {
|
|
6
|
-
const route = useRoute();
|
|
7
|
-
return () => h('div', { style: { position: 'relative' } }, [
|
|
8
|
-
route.component ? h(route.component) : null
|
|
9
|
-
]);
|
|
10
|
-
}
|
|
11
|
-
});
|
|
1
|
+
import { defineComponent, h } from 'vue';
|
|
2
|
+
import { useRoute } from '../router.js';
|
|
3
|
+
export const Content = defineComponent({
|
|
4
|
+
name: 'VitePressContent',
|
|
5
|
+
setup() {
|
|
6
|
+
const route = useRoute();
|
|
7
|
+
return () => h('div', { style: { position: 'relative' } }, [
|
|
8
|
+
route.component ? h(route.component) : null
|
|
9
|
+
]);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
@@ -1,85 +1,51 @@
|
|
|
1
|
-
import { watchEffect } from 'vue';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
let
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const siteData = siteDataByRouteRef.value;
|
|
53
|
-
const pageTitle = pageData && pageData.title;
|
|
54
|
-
const pageDescription = pageData && pageData.description;
|
|
55
|
-
const frontmatterHead = pageData && pageData.frontmatter.head;
|
|
56
|
-
// update title and description
|
|
57
|
-
document.title = (pageTitle ? pageTitle + ` | ` : ``) + siteData.title;
|
|
58
|
-
document
|
|
59
|
-
.querySelector(`meta[name=description]`)
|
|
60
|
-
.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
|
-
]);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
function createHeadElement([tag, attrs, innerHTML]) {
|
|
69
|
-
const el = document.createElement(tag);
|
|
70
|
-
for (const key in attrs) {
|
|
71
|
-
el.setAttribute(key, attrs[key]);
|
|
72
|
-
}
|
|
73
|
-
if (innerHTML) {
|
|
74
|
-
el.innerHTML = innerHTML;
|
|
75
|
-
}
|
|
76
|
-
return el;
|
|
77
|
-
}
|
|
78
|
-
function isMetaDescription(headConfig) {
|
|
79
|
-
return (headConfig[0] === 'meta' &&
|
|
80
|
-
headConfig[1] &&
|
|
81
|
-
headConfig[1].name === 'description');
|
|
82
|
-
}
|
|
83
|
-
function filterOutHeadDescription(head) {
|
|
84
|
-
return head.filter((h) => !isMetaDescription(h));
|
|
85
|
-
}
|
|
1
|
+
import { watchEffect } from 'vue';
|
|
2
|
+
import { createTitle, mergeHead } from '../../shared.js';
|
|
3
|
+
export function useUpdateHead(route, siteDataByRouteRef) {
|
|
4
|
+
let managedHeadTags = [];
|
|
5
|
+
let isFirstUpdate = true;
|
|
6
|
+
const updateHeadTags = (newTags) => {
|
|
7
|
+
if (import.meta.env.PROD && isFirstUpdate) {
|
|
8
|
+
// in production, the initial meta tags are already pre-rendered so we
|
|
9
|
+
// skip the first update.
|
|
10
|
+
isFirstUpdate = false;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
managedHeadTags.forEach((el) => document.head.removeChild(el));
|
|
14
|
+
managedHeadTags = [];
|
|
15
|
+
newTags.forEach((headConfig) => {
|
|
16
|
+
const el = createHeadElement(headConfig);
|
|
17
|
+
document.head.appendChild(el);
|
|
18
|
+
managedHeadTags.push(el);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
watchEffect(() => {
|
|
22
|
+
const pageData = route.data;
|
|
23
|
+
const siteData = siteDataByRouteRef.value;
|
|
24
|
+
const pageDescription = pageData && pageData.description;
|
|
25
|
+
const frontmatterHead = (pageData && pageData.frontmatter.head) || [];
|
|
26
|
+
// update title and description
|
|
27
|
+
document.title = createTitle(siteData, pageData);
|
|
28
|
+
document
|
|
29
|
+
.querySelector(`meta[name=description]`)
|
|
30
|
+
.setAttribute('content', pageDescription || siteData.description);
|
|
31
|
+
updateHeadTags(mergeHead(siteData.head, filterOutHeadDescription(frontmatterHead)));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function createHeadElement([tag, attrs, innerHTML]) {
|
|
35
|
+
const el = document.createElement(tag);
|
|
36
|
+
for (const key in attrs) {
|
|
37
|
+
el.setAttribute(key, attrs[key]);
|
|
38
|
+
}
|
|
39
|
+
if (innerHTML) {
|
|
40
|
+
el.innerHTML = innerHTML;
|
|
41
|
+
}
|
|
42
|
+
return el;
|
|
43
|
+
}
|
|
44
|
+
function isMetaDescription(headConfig) {
|
|
45
|
+
return (headConfig[0] === 'meta' &&
|
|
46
|
+
headConfig[1] &&
|
|
47
|
+
headConfig[1].name === 'description');
|
|
48
|
+
}
|
|
49
|
+
function filterOutHeadDescription(head) {
|
|
50
|
+
return head.filter((h) => !isMetaDescription(h));
|
|
51
|
+
}
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
// Customized pre-fetch for page chunks based on
|
|
2
|
-
// https://github.com/GoogleChromeLabs/quicklink
|
|
3
|
-
import { useRoute } from '../router';
|
|
4
|
-
import { onMounted, onUnmounted, watch } from 'vue';
|
|
5
|
-
import { inBrowser, pathToFile } from '../utils';
|
|
6
|
-
const hasFetched = new Set();
|
|
7
|
-
const createLink = () => document.createElement('link');
|
|
8
|
-
const viaDOM = (url) => {
|
|
9
|
-
const link = createLink();
|
|
10
|
-
link.rel = `prefetch`;
|
|
11
|
-
link.href = url;
|
|
12
|
-
document.head.appendChild(link);
|
|
13
|
-
};
|
|
14
|
-
const viaXHR = (url) => {
|
|
15
|
-
const req = new XMLHttpRequest();
|
|
16
|
-
req.open('GET', url, (req.withCredentials = true));
|
|
17
|
-
req.send();
|
|
18
|
-
};
|
|
19
|
-
let link;
|
|
20
|
-
const doFetch = inBrowser &&
|
|
21
|
-
(link = createLink()) &&
|
|
22
|
-
link.relList &&
|
|
23
|
-
link.relList.supports &&
|
|
24
|
-
link.relList.supports('prefetch')
|
|
25
|
-
? viaDOM
|
|
26
|
-
: viaXHR;
|
|
27
|
-
export function usePrefetch() {
|
|
28
|
-
if (!inBrowser) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (!window.IntersectionObserver) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
let conn;
|
|
35
|
-
if ((conn = navigator.connection) &&
|
|
36
|
-
(conn.saveData || /2g/.test(conn.effectiveType))) {
|
|
37
|
-
// Don't prefetch if using 2G or if Save-Data is enabled.
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const rIC = window.requestIdleCallback || setTimeout;
|
|
41
|
-
let observer = null;
|
|
42
|
-
const observeLinks = () => {
|
|
43
|
-
if (observer) {
|
|
44
|
-
observer.disconnect();
|
|
45
|
-
}
|
|
46
|
-
observer = new IntersectionObserver((entries) => {
|
|
47
|
-
entries.forEach((entry) => {
|
|
48
|
-
if (entry.isIntersecting) {
|
|
49
|
-
const link = entry.target;
|
|
50
|
-
observer.unobserve(link);
|
|
51
|
-
const { pathname } = link;
|
|
52
|
-
if (!hasFetched.has(pathname)) {
|
|
53
|
-
hasFetched.add(pathname);
|
|
54
|
-
const pageChunkPath = pathToFile(pathname);
|
|
55
|
-
doFetch(pageChunkPath);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
rIC(() => {
|
|
61
|
-
document.querySelectorAll('#app a').forEach((link) => {
|
|
62
|
-
const { target, hostname, pathname } = link;
|
|
63
|
-
const extMatch = pathname.match(/\.\w+$/);
|
|
64
|
-
if (extMatch && extMatch[0] !== '.html') {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (
|
|
68
|
-
// only prefetch same tab navigation, since a new tab will load
|
|
69
|
-
// the lean js chunk instead.
|
|
70
|
-
target !== `_blank` &&
|
|
71
|
-
// only prefetch inbound links
|
|
72
|
-
hostname === location.hostname) {
|
|
73
|
-
if (pathname !== location.pathname) {
|
|
74
|
-
observer.observe(link);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
// No need to prefetch chunk for the current page, but also mark
|
|
78
|
-
// it as already fetched. This is because the initial page uses its
|
|
79
|
-
// lean chunk, and if we don't mark it, navigation to another page
|
|
80
|
-
// with a link back to the first page will fetch its full chunk
|
|
81
|
-
// which isn't needed.
|
|
82
|
-
hasFetched.add(pathname);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
onMounted(observeLinks);
|
|
89
|
-
const route = useRoute();
|
|
90
|
-
watch(() => route.path, observeLinks);
|
|
91
|
-
onUnmounted(() => {
|
|
92
|
-
observer && observer.disconnect();
|
|
93
|
-
});
|
|
94
|
-
}
|
|
1
|
+
// Customized pre-fetch for page chunks based on
|
|
2
|
+
// https://github.com/GoogleChromeLabs/quicklink
|
|
3
|
+
import { useRoute } from '../router.js';
|
|
4
|
+
import { onMounted, onUnmounted, watch } from 'vue';
|
|
5
|
+
import { inBrowser, pathToFile } from '../utils.js';
|
|
6
|
+
const hasFetched = new Set();
|
|
7
|
+
const createLink = () => document.createElement('link');
|
|
8
|
+
const viaDOM = (url) => {
|
|
9
|
+
const link = createLink();
|
|
10
|
+
link.rel = `prefetch`;
|
|
11
|
+
link.href = url;
|
|
12
|
+
document.head.appendChild(link);
|
|
13
|
+
};
|
|
14
|
+
const viaXHR = (url) => {
|
|
15
|
+
const req = new XMLHttpRequest();
|
|
16
|
+
req.open('GET', url, (req.withCredentials = true));
|
|
17
|
+
req.send();
|
|
18
|
+
};
|
|
19
|
+
let link;
|
|
20
|
+
const doFetch = inBrowser &&
|
|
21
|
+
(link = createLink()) &&
|
|
22
|
+
link.relList &&
|
|
23
|
+
link.relList.supports &&
|
|
24
|
+
link.relList.supports('prefetch')
|
|
25
|
+
? viaDOM
|
|
26
|
+
: viaXHR;
|
|
27
|
+
export function usePrefetch() {
|
|
28
|
+
if (!inBrowser) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!window.IntersectionObserver) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
let conn;
|
|
35
|
+
if ((conn = navigator.connection) &&
|
|
36
|
+
(conn.saveData || /2g/.test(conn.effectiveType))) {
|
|
37
|
+
// Don't prefetch if using 2G or if Save-Data is enabled.
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const rIC = window.requestIdleCallback || setTimeout;
|
|
41
|
+
let observer = null;
|
|
42
|
+
const observeLinks = () => {
|
|
43
|
+
if (observer) {
|
|
44
|
+
observer.disconnect();
|
|
45
|
+
}
|
|
46
|
+
observer = new IntersectionObserver((entries) => {
|
|
47
|
+
entries.forEach((entry) => {
|
|
48
|
+
if (entry.isIntersecting) {
|
|
49
|
+
const link = entry.target;
|
|
50
|
+
observer.unobserve(link);
|
|
51
|
+
const { pathname } = link;
|
|
52
|
+
if (!hasFetched.has(pathname)) {
|
|
53
|
+
hasFetched.add(pathname);
|
|
54
|
+
const pageChunkPath = pathToFile(pathname);
|
|
55
|
+
doFetch(pageChunkPath);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
rIC(() => {
|
|
61
|
+
document.querySelectorAll('#app a').forEach((link) => {
|
|
62
|
+
const { target, hostname, pathname } = link;
|
|
63
|
+
const extMatch = pathname.match(/\.\w+$/);
|
|
64
|
+
if (extMatch && extMatch[0] !== '.html') {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (
|
|
68
|
+
// only prefetch same tab navigation, since a new tab will load
|
|
69
|
+
// the lean js chunk instead.
|
|
70
|
+
target !== `_blank` &&
|
|
71
|
+
// only prefetch inbound links
|
|
72
|
+
hostname === location.hostname) {
|
|
73
|
+
if (pathname !== location.pathname) {
|
|
74
|
+
observer.observe(link);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// No need to prefetch chunk for the current page, but also mark
|
|
78
|
+
// it as already fetched. This is because the initial page uses its
|
|
79
|
+
// lean chunk, and if we don't mark it, navigation to another page
|
|
80
|
+
// with a link back to the first page will fetch its full chunk
|
|
81
|
+
// which isn't needed.
|
|
82
|
+
hasFetched.add(pathname);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
onMounted(observeLinks);
|
|
89
|
+
const route = useRoute();
|
|
90
|
+
watch(() => route.path, observeLinks);
|
|
91
|
+
onUnmounted(() => {
|
|
92
|
+
observer && observer.disconnect();
|
|
93
|
+
});
|
|
94
|
+
}
|
package/dist/client/app/data.js
CHANGED
|
@@ -1,47 +1,44 @@
|
|
|
1
|
-
import { shallowRef, readonly, computed, inject } from 'vue';
|
|
2
|
-
import
|
|
3
|
-
import { resolveSiteDataByRoute } from '../shared';
|
|
4
|
-
import { withBase } from './utils';
|
|
5
|
-
export const dataSymbol = Symbol();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
site,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
return data;
|
|
47
|
-
}
|
|
1
|
+
import { shallowRef, readonly, computed, inject } from 'vue';
|
|
2
|
+
import siteData from '@siteData';
|
|
3
|
+
import { resolveSiteDataByRoute, createTitle } from '../shared.js';
|
|
4
|
+
import { withBase } from './utils.js';
|
|
5
|
+
export const dataSymbol = Symbol();
|
|
6
|
+
// site data is a singleton
|
|
7
|
+
export const siteDataRef = shallowRef((import.meta.env.PROD ? siteData : readonly(siteData)));
|
|
8
|
+
// hmr
|
|
9
|
+
if (import.meta.hot) {
|
|
10
|
+
import.meta.hot.accept('/@siteData', (m) => {
|
|
11
|
+
if (m) {
|
|
12
|
+
siteDataRef.value = m.default;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
// per-app data
|
|
17
|
+
export function initData(route) {
|
|
18
|
+
const site = computed(() => resolveSiteDataByRoute(siteDataRef.value, route.path));
|
|
19
|
+
return {
|
|
20
|
+
site,
|
|
21
|
+
theme: computed(() => site.value.themeConfig),
|
|
22
|
+
page: computed(() => route.data),
|
|
23
|
+
frontmatter: computed(() => route.data.frontmatter),
|
|
24
|
+
lang: computed(() => site.value.lang),
|
|
25
|
+
localePath: computed(() => {
|
|
26
|
+
const { langs, lang } = site.value;
|
|
27
|
+
const path = Object.keys(langs).find((langPath) => langs[langPath].lang === lang);
|
|
28
|
+
return withBase(path || '/');
|
|
29
|
+
}),
|
|
30
|
+
title: computed(() => {
|
|
31
|
+
return createTitle(site.value, route.data);
|
|
32
|
+
}),
|
|
33
|
+
description: computed(() => {
|
|
34
|
+
return route.data.description || site.value.description;
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function useData() {
|
|
39
|
+
const data = inject(dataSymbol);
|
|
40
|
+
if (!data) {
|
|
41
|
+
throw new Error('vitepress data not properly injected in app');
|
|
42
|
+
}
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
@@ -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
|
+
};
|