@vuepress/theme-default 2.0.0-rc.8 → 2.0.0-rc.81
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/lib/client/components/VPAutoLink.vue +32 -0
- package/lib/client/components/VPDarkIcon.vue +8 -0
- package/lib/client/components/VPDropdownTransition.vue +43 -0
- package/lib/client/components/VPEditIcon.vue +12 -0
- package/lib/client/components/VPFadeSlideYTransition.vue +43 -0
- package/lib/client/components/VPHome.vue +37 -0
- package/lib/client/components/VPHomeFeatures.vue +65 -0
- package/lib/client/components/{HomeFooter.vue → VPHomeFooter.vue} +16 -3
- package/lib/client/components/VPHomeHero.vue +185 -0
- package/lib/client/components/VPLightIcon.vue +28 -0
- package/lib/client/components/VPNavbar.vue +134 -0
- package/lib/client/components/{NavbarBrand.vue → VPNavbarBrand.vue} +41 -16
- package/lib/client/components/VPNavbarDropdown.vue +328 -0
- package/lib/client/components/VPNavbarItems.vue +111 -0
- package/lib/client/components/VPPage.vue +69 -0
- package/lib/client/components/VPPageMeta.vue +133 -0
- package/lib/client/components/VPPageNav.vue +123 -0
- package/lib/client/components/VPSidebar.vue +120 -0
- package/lib/client/components/VPSidebarItem.vue +189 -0
- package/lib/client/components/{SidebarItems.vue → VPSidebarItems.vue} +27 -7
- package/lib/client/components/VPToggleColorModeButton.vue +55 -0
- package/lib/client/components/VPToggleSidebarButton.vue +92 -0
- package/lib/client/components/global/Badge.vue +84 -18
- package/lib/client/components/global/index.d.ts +1 -3
- package/lib/client/components/global/index.js +1 -3
- package/lib/client/composables/index.d.ts +9 -1
- package/lib/client/composables/index.js +9 -1
- package/lib/client/composables/useContributors.d.ts +3 -0
- package/lib/client/composables/useContributors.js +11 -0
- package/lib/client/composables/useDarkMode.d.ts +0 -1
- package/lib/client/composables/useDarkMode.js +19 -16
- package/lib/client/composables/useData.d.ts +13 -0
- package/lib/client/composables/useData.js +15 -0
- package/lib/client/composables/useEditLink.d.ts +3 -0
- package/lib/client/composables/useEditLink.js +28 -0
- package/lib/client/composables/useHeaders.d.ts +9 -0
- package/lib/client/composables/useHeaders.js +38 -0
- package/lib/client/composables/useLastUpdated.d.ts +2 -0
- package/lib/client/composables/useLastUpdated.js +14 -0
- package/lib/client/composables/useNavbarConfig.d.ts +3 -0
- package/lib/client/composables/useNavbarConfig.js +29 -0
- package/lib/client/composables/useNavbarRepo.d.ts +6 -0
- package/lib/client/composables/useNavbarRepo.js +38 -0
- package/lib/client/composables/useNavbarSelectLanguage.d.ts +6 -0
- package/lib/client/composables/useNavbarSelectLanguage.js +55 -0
- package/lib/client/composables/useNavigate.d.ts +1 -0
- package/lib/client/composables/useNavigate.js +22 -0
- package/lib/client/composables/useRelatedLinks.d.ts +8 -0
- package/lib/client/composables/useRelatedLinks.js +90 -0
- package/lib/client/composables/useScrollPromise.js +3 -1
- package/lib/client/composables/useSidebarItems.d.ts +21 -21
- package/lib/client/composables/useSidebarItems.js +96 -86
- package/lib/client/composables/useUpdateDeviceStatus.d.ts +1 -1
- package/lib/client/composables/useUpdateDeviceStatus.js +10 -5
- package/lib/client/config.d.ts +3 -2
- package/lib/client/config.js +8 -23
- package/lib/client/index.d.ts +2 -1
- package/lib/client/index.js +0 -1
- package/lib/client/layouts/Layout.vue +127 -54
- package/lib/client/layouts/NotFound.vue +25 -11
- package/lib/client/shim.d.ts +6 -5
- package/lib/client/styles/_mixins.scss +4 -4
- package/lib/client/styles/_variables.module.scss +1 -1
- package/lib/client/styles/_variables.scss +2 -1
- package/lib/client/styles/arrow.scss +24 -22
- package/lib/client/styles/code-group.scss +34 -30
- package/lib/client/styles/content/code.scss +23 -0
- package/lib/client/styles/content/index.scss +3 -0
- package/lib/client/styles/content/normalize.scss +39 -0
- package/lib/client/styles/{toc.scss → content/toc.scss} +1 -1
- package/lib/client/styles/external-link-icon.scss +36 -0
- package/lib/client/styles/index.scss +3 -13
- package/lib/client/styles/layout.scss +5 -197
- package/lib/client/styles/normalize.scss +1 -194
- package/lib/client/styles/plugins.scss +28 -0
- package/lib/client/styles/vars-dark.scss +20 -58
- package/lib/client/styles/vars.scss +54 -129
- package/lib/client/typings.d.ts +13 -0
- package/lib/client/typings.js +1 -0
- package/lib/client/utils/index.d.ts +2 -2
- package/lib/client/utils/index.js +2 -2
- package/lib/client/utils/isActiveSidebarItem.d.ts +3 -3
- package/lib/client/utils/isActiveSidebarItem.js +1 -1
- package/lib/client/utils/resolveAutoLink.d.ts +9 -0
- package/lib/client/utils/resolveAutoLink.js +17 -0
- package/lib/client/utils/resolveEditLink.d.ts +3 -3
- package/lib/client/utils/resolveEditLink.js +3 -3
- package/lib/client/utils/resolvePrefix.d.ts +1 -0
- package/lib/client/utils/resolvePrefix.js +4 -0
- package/lib/client/utils/resolveRepoType.d.ts +1 -1
- package/lib/client/utils/resolveRepoType.js +4 -4
- package/lib/node/defaultTheme.d.ts +2 -1
- package/lib/node/defaultTheme.js +52 -57
- package/lib/node/index.d.ts +2 -3
- package/lib/node/index.js +0 -3
- package/lib/node/typings.d.ts +59 -0
- package/lib/node/typings.js +1 -0
- package/lib/node/utils/assignDefaultLocaleOptions.js +3 -7
- package/lib/node/utils/index.d.ts +1 -1
- package/lib/node/utils/index.js +1 -1
- package/lib/node/utils/resolveMarkdownHintLocales.d.ts +9 -0
- package/lib/node/utils/resolveMarkdownHintLocales.js +19 -0
- package/lib/shared/index.d.ts +5 -3
- package/lib/shared/index.js +1 -3
- package/lib/shared/nav.d.ts +19 -30
- package/lib/shared/navbar.d.ts +21 -0
- package/lib/shared/navbar.js +1 -0
- package/lib/shared/options.d.ts +36 -65
- package/lib/shared/page.d.ts +9 -6
- package/lib/shared/sidebar.d.ts +26 -0
- package/lib/shared/sidebar.js +1 -0
- package/package.json +29 -27
- package/templates/build.html +16 -10
- package/lib/client/components/AutoLink.vue +0 -113
- package/lib/client/components/DropdownTransition.vue +0 -25
- package/lib/client/components/Home.vue +0 -15
- package/lib/client/components/HomeContent.vue +0 -5
- package/lib/client/components/HomeFeatures.vue +0 -22
- package/lib/client/components/HomeHero.vue +0 -97
- package/lib/client/components/Navbar.vue +0 -79
- package/lib/client/components/NavbarDropdown.vue +0 -126
- package/lib/client/components/NavbarItems.vue +0 -199
- package/lib/client/components/Page.vue +0 -31
- package/lib/client/components/PageMeta.vue +0 -124
- package/lib/client/components/PageNav.vue +0 -122
- package/lib/client/components/Sidebar.vue +0 -18
- package/lib/client/components/SidebarItem.vue +0 -87
- package/lib/client/components/ToggleColorModeButton.vue +0 -57
- package/lib/client/components/ToggleSidebarButton.vue +0 -24
- package/lib/client/components/global/CodeGroup.d.ts +0 -6
- package/lib/client/components/global/CodeGroup.js +0 -120
- package/lib/client/components/global/CodeGroupItem.vue +0 -27
- package/lib/client/composables/useThemeData.d.ts +0 -4
- package/lib/client/composables/useThemeData.js +0 -3
- package/lib/client/styles/badge.scss +0 -36
- package/lib/client/styles/code.scss +0 -263
- package/lib/client/styles/custom-container.scss +0 -142
- package/lib/client/styles/home.scss +0 -168
- package/lib/client/styles/navbar-dropdown.scss +0 -183
- package/lib/client/styles/navbar.scss +0 -197
- package/lib/client/styles/page.scss +0 -87
- package/lib/client/styles/sidebar.scss +0 -134
- package/lib/client/styles/transitions.scss +0 -22
- package/lib/client/utils/getNavLink.d.ts +0 -15
- package/lib/client/utils/getNavLink.js +0 -18
- package/lib/client/utils/getResolveRouteWithRedirect.d.ts +0 -5
- package/lib/client/utils/getResolveRouteWithRedirect.js +0 -22
- package/lib/node/utils/resolveContainerPluginOptions.d.ts +0 -8
- package/lib/node/utils/resolveContainerPluginOptions.js +0 -17
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
import type { VNode } from 'vue'
|
|
3
|
+
|
|
4
|
+
withDefaults(
|
|
5
|
+
defineProps<{
|
|
6
|
+
/**
|
|
7
|
+
* The type of the badge
|
|
8
|
+
*/
|
|
9
|
+
type?: string
|
|
10
|
+
/**
|
|
11
|
+
* The text of the badge
|
|
12
|
+
*/
|
|
13
|
+
text?: string
|
|
14
|
+
/**
|
|
15
|
+
* The vertical align of the badge
|
|
16
|
+
*/
|
|
17
|
+
vertical?: string
|
|
18
|
+
}>(),
|
|
19
|
+
{
|
|
20
|
+
type: 'tip',
|
|
21
|
+
text: '',
|
|
22
|
+
vertical: undefined,
|
|
17
23
|
},
|
|
18
|
-
|
|
24
|
+
)
|
|
19
25
|
|
|
20
26
|
defineSlots<{
|
|
21
|
-
default?: () =>
|
|
27
|
+
default?: () => VNode | VNode[] | string | null
|
|
22
28
|
}>()
|
|
23
29
|
</script>
|
|
24
30
|
|
|
25
31
|
<template>
|
|
26
32
|
<span
|
|
27
|
-
class="badge"
|
|
33
|
+
class="vp-badge"
|
|
28
34
|
:class="type"
|
|
29
35
|
:style="{
|
|
30
36
|
verticalAlign: vertical,
|
|
@@ -33,3 +39,63 @@ defineSlots<{
|
|
|
33
39
|
<slot>{{ text }}</slot>
|
|
34
40
|
</span>
|
|
35
41
|
</template>
|
|
42
|
+
|
|
43
|
+
<style lang="scss">
|
|
44
|
+
.vp-badge {
|
|
45
|
+
display: inline-block;
|
|
46
|
+
vertical-align: top;
|
|
47
|
+
|
|
48
|
+
height: 1.3em;
|
|
49
|
+
padding: 0 6px;
|
|
50
|
+
border-radius: 3px;
|
|
51
|
+
|
|
52
|
+
background: var(--vp-c-accent-soft);
|
|
53
|
+
color: var(--vp-c-accent);
|
|
54
|
+
|
|
55
|
+
font-size: 0.875em;
|
|
56
|
+
line-height: 1.3;
|
|
57
|
+
|
|
58
|
+
transition:
|
|
59
|
+
background var(--vp-t-color),
|
|
60
|
+
color var(--vp-t-color);
|
|
61
|
+
|
|
62
|
+
& + & {
|
|
63
|
+
margin-inline-start: 5px;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&.tip {
|
|
67
|
+
background: var(--badge-c-tip-bg);
|
|
68
|
+
color: var(--badge-c-tip-text);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
&.warning {
|
|
72
|
+
background: var(--badge-c-warning-bg);
|
|
73
|
+
color: var(--badge-c-warning-text);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
&.danger {
|
|
77
|
+
background: var(--badge-c-danger-bg);
|
|
78
|
+
color: var(--badge-c-danger-text);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
&.important {
|
|
82
|
+
background: var(--badge-c-important-bg);
|
|
83
|
+
color: var(--badge-c-important-text);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
&.info {
|
|
87
|
+
background: var(--badge-c-info-bg);
|
|
88
|
+
color: var(--badge-c-info-text);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
&.note {
|
|
92
|
+
background: var(--badge-c-note-bg);
|
|
93
|
+
color: var(--badge-c-note-text);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// update the vertical align for the badge in toc
|
|
97
|
+
.table-of-contents & {
|
|
98
|
+
vertical-align: middle;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
</style>
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
export * from './useContributors.js';
|
|
1
2
|
export * from './useDarkMode.js';
|
|
3
|
+
export * from './useData.js';
|
|
4
|
+
export * from './useEditLink.js';
|
|
5
|
+
export * from './useLastUpdated.js';
|
|
6
|
+
export * from './useNavigate.js';
|
|
7
|
+
export * from './useNavbarConfig.js';
|
|
8
|
+
export * from './useNavbarRepo.js';
|
|
9
|
+
export * from './useNavbarSelectLanguage.js';
|
|
10
|
+
export * from './useRelatedLinks.js';
|
|
2
11
|
export * from './useScrollPromise.js';
|
|
3
12
|
export * from './useSidebarItems.js';
|
|
4
|
-
export * from './useThemeData.js';
|
|
5
13
|
export * from './useUpdateDeviceStatus.js';
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
export * from './useContributors.js';
|
|
1
2
|
export * from './useDarkMode.js';
|
|
3
|
+
export * from './useData.js';
|
|
4
|
+
export * from './useEditLink.js';
|
|
5
|
+
export * from './useLastUpdated.js';
|
|
6
|
+
export * from './useNavigate.js';
|
|
7
|
+
export * from './useNavbarConfig.js';
|
|
8
|
+
export * from './useNavbarRepo.js';
|
|
9
|
+
export * from './useNavbarSelectLanguage.js';
|
|
10
|
+
export * from './useRelatedLinks.js';
|
|
2
11
|
export * from './useScrollPromise.js';
|
|
3
12
|
export * from './useSidebarItems.js';
|
|
4
|
-
export * from './useThemeData.js';
|
|
5
13
|
export * from './useUpdateDeviceStatus.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useData } from '@theme/useData';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
export const useContributors = () => {
|
|
4
|
+
const { themeLocale, page, frontmatter } = useData();
|
|
5
|
+
return computed(() => {
|
|
6
|
+
const showContributors = frontmatter.value.contributors ?? themeLocale.value.contributors ?? true;
|
|
7
|
+
if (!showContributors)
|
|
8
|
+
return null;
|
|
9
|
+
return page.value.git?.contributors ?? null;
|
|
10
|
+
});
|
|
11
|
+
};
|
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { useData } from '@theme/useData';
|
|
2
|
+
import { usePreferredDark, useStorage, watchImmediate } from '@vueuse/core';
|
|
3
|
+
import { computed, inject, onMounted, onUnmounted, provide } from 'vue';
|
|
4
4
|
export const darkModeSymbol = Symbol(__VUEPRESS_DEV__ ? 'darkMode' : '');
|
|
5
|
+
const applyDarkModeToHTML = (isDarkMode) => {
|
|
6
|
+
const update = (value = isDarkMode.value) => {
|
|
7
|
+
// set `class="dark"` on `<html>` element
|
|
8
|
+
const el = window.document.documentElement;
|
|
9
|
+
// set `data-theme="light|dark"` on `<html>` element
|
|
10
|
+
el.dataset.theme = value ? 'dark' : 'light';
|
|
11
|
+
};
|
|
12
|
+
onMounted(() => {
|
|
13
|
+
watchImmediate(isDarkMode, update);
|
|
14
|
+
});
|
|
15
|
+
onUnmounted(() => {
|
|
16
|
+
update();
|
|
17
|
+
});
|
|
18
|
+
};
|
|
5
19
|
/**
|
|
6
20
|
* Inject dark mode global computed
|
|
7
21
|
*/
|
|
@@ -16,7 +30,7 @@ export const useDarkMode = () => {
|
|
|
16
30
|
* Create dark mode ref and provide as global computed in setup
|
|
17
31
|
*/
|
|
18
32
|
export const setupDarkMode = () => {
|
|
19
|
-
const themeLocale =
|
|
33
|
+
const { themeLocale } = useData();
|
|
20
34
|
const isDarkPreferred = usePreferredDark();
|
|
21
35
|
const darkStorage = useStorage('vuepress-color-scheme', themeLocale.value.colorMode);
|
|
22
36
|
const isDarkMode = computed({
|
|
@@ -42,16 +56,5 @@ export const setupDarkMode = () => {
|
|
|
42
56
|
},
|
|
43
57
|
});
|
|
44
58
|
provide(darkModeSymbol, isDarkMode);
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
export const updateHtmlDarkClass = (isDarkMode) => {
|
|
48
|
-
const update = (value = isDarkMode.value) => {
|
|
49
|
-
// set `class="dark"` on `<html>` element
|
|
50
|
-
const htmlEl = window?.document.querySelector('html');
|
|
51
|
-
htmlEl?.classList.toggle('dark', value);
|
|
52
|
-
};
|
|
53
|
-
onMounted(() => {
|
|
54
|
-
watch(isDarkMode, update, { immediate: true });
|
|
55
|
-
});
|
|
56
|
-
onUnmounted(() => update());
|
|
59
|
+
applyDarkModeToHTML(isDarkMode);
|
|
57
60
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ThemeDataRef, ThemeLocaleDataRef } from '@vuepress/plugin-theme-data/client';
|
|
2
|
+
import type { ClientData, PageDataRef, PageFrontmatterRef, PageLangRef, SiteDataRef, SiteLocaleDataRef } from 'vuepress/client';
|
|
3
|
+
import type { DefaultThemeData, DefaultThemeNormalPageFrontmatter, DefaultThemePageData } from '../../shared/index.js';
|
|
4
|
+
export interface Data<PageFrontmatter extends Record<string, unknown> = DefaultThemeNormalPageFrontmatter, PageData extends Record<string, unknown> = DefaultThemePageData> extends Pick<ClientData, 'layouts' | 'pageComponent' | 'pageHead' | 'pageHeadTitle' | 'pageLayout' | 'redirects' | 'routeLocale' | 'routePath' | 'routes'> {
|
|
5
|
+
page: PageDataRef<PageData>;
|
|
6
|
+
frontmatter: PageFrontmatterRef<PageFrontmatter>;
|
|
7
|
+
lang: PageLangRef;
|
|
8
|
+
site: SiteDataRef;
|
|
9
|
+
siteLocale: SiteLocaleDataRef;
|
|
10
|
+
theme: ThemeDataRef<DefaultThemeData>;
|
|
11
|
+
themeLocale: ThemeLocaleDataRef<DefaultThemeData>;
|
|
12
|
+
}
|
|
13
|
+
export declare const useData: <PageFrontmatter extends Record<string, unknown> = DefaultThemeNormalPageFrontmatter, PageData extends Record<string, unknown> = DefaultThemePageData>() => Data<PageFrontmatter, PageData>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useThemeData, useThemeLocaleData, } from '@vuepress/plugin-theme-data/client';
|
|
2
|
+
import { useClientData } from 'vuepress/client';
|
|
3
|
+
export const useData = () => {
|
|
4
|
+
const { pageData, pageFrontmatter, pageLang, siteData, siteLocaleData, ...rest } = useClientData();
|
|
5
|
+
return {
|
|
6
|
+
...rest,
|
|
7
|
+
page: pageData,
|
|
8
|
+
frontmatter: pageFrontmatter,
|
|
9
|
+
lang: pageLang,
|
|
10
|
+
site: siteData,
|
|
11
|
+
siteLocale: siteLocaleData,
|
|
12
|
+
theme: useThemeData(),
|
|
13
|
+
themeLocale: useThemeLocaleData(),
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { resolveEditLink } from '@theme/resolveEditLink';
|
|
2
|
+
import { useData } from '@theme/useData';
|
|
3
|
+
import { computed } from 'vue';
|
|
4
|
+
export const useEditLink = () => {
|
|
5
|
+
const { frontmatter, page, themeLocale } = useData();
|
|
6
|
+
return computed(() => {
|
|
7
|
+
const showEditLink = frontmatter.value.editLink ?? themeLocale.value.editLink ?? true;
|
|
8
|
+
if (!showEditLink) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const { repo, docsRepo = repo, docsBranch = 'main', docsDir = '', editLinkText, } = themeLocale.value;
|
|
12
|
+
if (!docsRepo)
|
|
13
|
+
return null;
|
|
14
|
+
const editLink = resolveEditLink({
|
|
15
|
+
docsRepo,
|
|
16
|
+
docsBranch,
|
|
17
|
+
docsDir,
|
|
18
|
+
filePathRelative: page.value.filePathRelative,
|
|
19
|
+
editLinkPattern: frontmatter.value.editLinkPattern ?? themeLocale.value.editLinkPattern,
|
|
20
|
+
});
|
|
21
|
+
if (!editLink)
|
|
22
|
+
return null;
|
|
23
|
+
return {
|
|
24
|
+
text: editLinkText ?? 'Edit this page',
|
|
25
|
+
link: editLink,
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HeaderItem } from '@vuepress/helper/client';
|
|
2
|
+
import type { InjectionKey, Ref } from 'vue';
|
|
3
|
+
export type HeadersRef = Ref<HeaderItem[]>;
|
|
4
|
+
export declare const headersSymbol: InjectionKey<HeadersRef>;
|
|
5
|
+
/**
|
|
6
|
+
* Inject headers
|
|
7
|
+
*/
|
|
8
|
+
export declare const useHeaders: () => HeadersRef;
|
|
9
|
+
export declare const setupHeaders: () => void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useData } from '@theme/useData';
|
|
2
|
+
import { getHeaders } from '@vuepress/helper/client';
|
|
3
|
+
import { injectLocal, provideLocal } from '@vueuse/core';
|
|
4
|
+
import { computed, ref } from 'vue';
|
|
5
|
+
import { onContentUpdated } from 'vuepress/client';
|
|
6
|
+
export const headersSymbol = Symbol('headers');
|
|
7
|
+
/**
|
|
8
|
+
* Inject headers
|
|
9
|
+
*/
|
|
10
|
+
export const useHeaders = () => {
|
|
11
|
+
const headers = injectLocal(headersSymbol);
|
|
12
|
+
if (!headers) {
|
|
13
|
+
throw new Error('useHeaders() is called without provider.');
|
|
14
|
+
}
|
|
15
|
+
return headers;
|
|
16
|
+
};
|
|
17
|
+
export const setupHeaders = () => {
|
|
18
|
+
const { frontmatter, themeLocale } = useData();
|
|
19
|
+
const headersRef = ref([]);
|
|
20
|
+
const levels = computed(() => frontmatter.value.sidebarDepth ?? themeLocale.value.sidebarDepth ?? 2);
|
|
21
|
+
const updateHeaders = () => {
|
|
22
|
+
if (levels.value <= 0) {
|
|
23
|
+
headersRef.value = [];
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
headersRef.value = getHeaders({
|
|
27
|
+
levels: [2, levels.value + 1],
|
|
28
|
+
ignore: ['.vp-badge'],
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
provideLocal(headersSymbol, headersRef);
|
|
32
|
+
onContentUpdated((reason) => {
|
|
33
|
+
if (reason === 'beforeUnmount')
|
|
34
|
+
headersRef.value = [];
|
|
35
|
+
else
|
|
36
|
+
updateHeaders();
|
|
37
|
+
});
|
|
38
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useData } from '@theme/useData';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
export const useLastUpdated = () => {
|
|
4
|
+
const { frontmatter, page, themeLocale } = useData();
|
|
5
|
+
return computed(() => {
|
|
6
|
+
const showLastUpdated = frontmatter.value.lastUpdated ?? themeLocale.value.lastUpdated ?? true;
|
|
7
|
+
if (!showLastUpdated)
|
|
8
|
+
return null;
|
|
9
|
+
if (!page.value.git?.updatedTime)
|
|
10
|
+
return null;
|
|
11
|
+
const updatedDate = new Date(page.value.git.updatedTime);
|
|
12
|
+
return updatedDate.toLocaleString();
|
|
13
|
+
});
|
|
14
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { resolveAutoLink } from '@theme/resolveAutoLink';
|
|
2
|
+
import { resolvePrefix } from '@theme/resolvePrefix';
|
|
3
|
+
import { useData } from '@theme/useData';
|
|
4
|
+
import { isLinkRelative } from '@vuepress/helper/client';
|
|
5
|
+
import { computed } from 'vue';
|
|
6
|
+
import { isString } from 'vuepress/shared';
|
|
7
|
+
const resolveNavbarItem = (item, prefix = '') => {
|
|
8
|
+
if (isString(item)) {
|
|
9
|
+
return resolveAutoLink(resolvePrefix(prefix, item));
|
|
10
|
+
}
|
|
11
|
+
if ('children' in item) {
|
|
12
|
+
return {
|
|
13
|
+
...item,
|
|
14
|
+
children: item.children.map((child) => resolveNavbarItem(child, resolvePrefix(prefix, item.prefix))),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
...item,
|
|
19
|
+
link: isLinkRelative(item.link)
|
|
20
|
+
? resolveAutoLink(resolvePrefix(prefix, item.link)).link
|
|
21
|
+
: item.link,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export const useNavbarConfig = () => {
|
|
25
|
+
const { themeLocale } = useData();
|
|
26
|
+
return computed(() =>
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
28
|
+
(themeLocale.value.navbar || []).map((item) => resolveNavbarItem(item)));
|
|
29
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { resolveRepoType } from '@theme/resolveRepoType';
|
|
2
|
+
import { useData } from '@theme/useData';
|
|
3
|
+
import { computed } from 'vue';
|
|
4
|
+
import { isLinkHttp } from 'vuepress/shared';
|
|
5
|
+
/**
|
|
6
|
+
* Get navbar config of repository link
|
|
7
|
+
*/
|
|
8
|
+
export const useNavbarRepo = () => {
|
|
9
|
+
const { themeLocale } = useData();
|
|
10
|
+
const repo = computed(() => themeLocale.value.repo);
|
|
11
|
+
const repoType = computed(() => repo.value ? resolveRepoType(repo.value) : null);
|
|
12
|
+
const repoLink = computed(() => {
|
|
13
|
+
if (repo.value && !isLinkHttp(repo.value)) {
|
|
14
|
+
return `https://github.com/${repo.value}`;
|
|
15
|
+
}
|
|
16
|
+
return repo.value;
|
|
17
|
+
});
|
|
18
|
+
const repoLabel = computed(() => {
|
|
19
|
+
if (!repoLink.value)
|
|
20
|
+
return null;
|
|
21
|
+
if (themeLocale.value.repoLabel)
|
|
22
|
+
return themeLocale.value.repoLabel;
|
|
23
|
+
if (repoType.value === null)
|
|
24
|
+
return 'Source';
|
|
25
|
+
return repoType.value;
|
|
26
|
+
});
|
|
27
|
+
return computed(() => {
|
|
28
|
+
if (!repoLink.value || !repoLabel.value) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
return [
|
|
32
|
+
{
|
|
33
|
+
text: repoLabel.value,
|
|
34
|
+
link: repoLink.value,
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
});
|
|
38
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useData } from '@theme/useData';
|
|
2
|
+
import { useRoutePaths } from '@vuepress/helper/client';
|
|
3
|
+
import { computed } from 'vue';
|
|
4
|
+
import { useRoute } from 'vuepress/client';
|
|
5
|
+
/**
|
|
6
|
+
* Get navbar config of select language dropdown
|
|
7
|
+
*/
|
|
8
|
+
export const useNavbarSelectLanguage = () => {
|
|
9
|
+
const route = useRoute();
|
|
10
|
+
const routePaths = useRoutePaths();
|
|
11
|
+
const { routeLocale, site, siteLocale, theme, themeLocale } = useData();
|
|
12
|
+
return computed(() => {
|
|
13
|
+
const localePaths = Object.keys(site.value.locales);
|
|
14
|
+
// do not display language selection dropdown if there is only one language
|
|
15
|
+
if (localePaths.length < 2) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
const currentPath = route.path;
|
|
19
|
+
const currentFullPath = route.fullPath;
|
|
20
|
+
const languageDropdown = {
|
|
21
|
+
text: `${themeLocale.value.selectLanguageText}`,
|
|
22
|
+
ariaLabel: `${themeLocale.value.selectLanguageAriaLabel ??
|
|
23
|
+
themeLocale.value.selectLanguageText}`,
|
|
24
|
+
children: localePaths.map((targetLocalePath) => {
|
|
25
|
+
// target locale config of this language link
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
27
|
+
const targetSiteLocale = site.value.locales?.[targetLocalePath] ?? {};
|
|
28
|
+
const targetThemeLocale = theme.value.locales?.[targetLocalePath] ?? {};
|
|
29
|
+
const targetLang = `${targetSiteLocale.lang}`;
|
|
30
|
+
const text = targetThemeLocale.selectLanguageName ?? targetLang;
|
|
31
|
+
// if the target language is current language
|
|
32
|
+
// stay at current link
|
|
33
|
+
if (targetLang === siteLocale.value.lang) {
|
|
34
|
+
return {
|
|
35
|
+
text,
|
|
36
|
+
activeMatch: '.',
|
|
37
|
+
link: route.fullPath,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// if the target language is not current language
|
|
41
|
+
// try to link to the corresponding page of current page
|
|
42
|
+
// or fallback to homepage
|
|
43
|
+
const targetLocalePage = currentPath.replace(routeLocale.value, targetLocalePath);
|
|
44
|
+
return {
|
|
45
|
+
text,
|
|
46
|
+
// try to keep current hash and params across languages
|
|
47
|
+
link: routePaths.value.some((item) => item === targetLocalePage)
|
|
48
|
+
? currentFullPath.replace(currentPath, targetLocalePage)
|
|
49
|
+
: (targetThemeLocale.home ?? targetLocalePath),
|
|
50
|
+
};
|
|
51
|
+
}),
|
|
52
|
+
};
|
|
53
|
+
return [languageDropdown];
|
|
54
|
+
});
|
|
55
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useNavigate: () => ((url: string) => void);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isLinkAbsolute, isLinkWithProtocol } from '@vuepress/helper/client';
|
|
2
|
+
import { useRoute, useRouter } from 'vuepress/client';
|
|
3
|
+
export const useNavigate = () => {
|
|
4
|
+
const router = useRouter();
|
|
5
|
+
const route = useRoute();
|
|
6
|
+
return (url) => {
|
|
7
|
+
if (url)
|
|
8
|
+
if (isLinkAbsolute(url)) {
|
|
9
|
+
// Inner absolute path
|
|
10
|
+
if (route.fullPath !== url)
|
|
11
|
+
router.push(url);
|
|
12
|
+
}
|
|
13
|
+
else if (isLinkWithProtocol(url)) {
|
|
14
|
+
// external url
|
|
15
|
+
window.open(url);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
// relative url
|
|
19
|
+
router.push(encodeURI(url));
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ComputedRef } from 'vue';
|
|
2
|
+
import type { AutoLinkOptions } from '../../shared/index.js';
|
|
3
|
+
interface RelatedLinks {
|
|
4
|
+
prevLink: ComputedRef<AutoLinkOptions | null>;
|
|
5
|
+
nextLink: ComputedRef<AutoLinkOptions | null>;
|
|
6
|
+
}
|
|
7
|
+
export declare const useRelatedLinks: () => RelatedLinks;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { resolveAutoLink } from '@theme/resolveAutoLink';
|
|
2
|
+
import { useData } from '@theme/useData';
|
|
3
|
+
import { useSidebarItems } from '@theme/useSidebarItems';
|
|
4
|
+
import { computed } from 'vue';
|
|
5
|
+
import { resolveRoute, useRoutePath } from 'vuepress/client';
|
|
6
|
+
import { isPlainObject, isString } from 'vuepress/shared';
|
|
7
|
+
const resolveFromFrontmatterConfig = (config, currentPath) => {
|
|
8
|
+
if (config === false) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (isString(config)) {
|
|
12
|
+
return resolveAutoLink(config, currentPath);
|
|
13
|
+
}
|
|
14
|
+
if (isPlainObject(config)) {
|
|
15
|
+
return {
|
|
16
|
+
...config,
|
|
17
|
+
link: resolveAutoLink(config.link, currentPath).link,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Resolve `prev` or `next` config from sidebar items
|
|
24
|
+
*/
|
|
25
|
+
const resolveFromSidebarItems = (sidebarItems, currentPath, offset) => {
|
|
26
|
+
const linkIndex = sidebarItems.findIndex((item) => item.link === currentPath);
|
|
27
|
+
if (linkIndex !== -1) {
|
|
28
|
+
const targetItem = sidebarItems[linkIndex + offset];
|
|
29
|
+
if (!targetItem)
|
|
30
|
+
return null;
|
|
31
|
+
if (targetItem.link)
|
|
32
|
+
return targetItem;
|
|
33
|
+
if ('prefix' in targetItem && !resolveRoute(targetItem.prefix).notFound)
|
|
34
|
+
return {
|
|
35
|
+
...targetItem,
|
|
36
|
+
link: targetItem.prefix,
|
|
37
|
+
};
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
for (const item of sidebarItems) {
|
|
41
|
+
if ('children' in item) {
|
|
42
|
+
const childResult = resolveFromSidebarItems(item.children, currentPath, offset);
|
|
43
|
+
if (childResult) {
|
|
44
|
+
return childResult;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const prefixIndex = sidebarItems.findIndex((item) => 'prefix' in item && item.prefix === currentPath);
|
|
49
|
+
if (prefixIndex !== -1) {
|
|
50
|
+
const targetItem = sidebarItems[prefixIndex + offset];
|
|
51
|
+
if (!targetItem)
|
|
52
|
+
return null;
|
|
53
|
+
if (targetItem.link)
|
|
54
|
+
return targetItem;
|
|
55
|
+
if ('prefix' in targetItem && !resolveRoute(targetItem.prefix).notFound)
|
|
56
|
+
return {
|
|
57
|
+
...targetItem,
|
|
58
|
+
link: targetItem.prefix,
|
|
59
|
+
};
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
};
|
|
64
|
+
export const useRelatedLinks = () => {
|
|
65
|
+
const { frontmatter, themeLocale } = useData();
|
|
66
|
+
const sidebarItems = useSidebarItems();
|
|
67
|
+
const routePath = useRoutePath();
|
|
68
|
+
const prevLink = computed(() => {
|
|
69
|
+
const prevConfig = resolveFromFrontmatterConfig(frontmatter.value.prev, routePath.value);
|
|
70
|
+
return prevConfig === false
|
|
71
|
+
? null
|
|
72
|
+
: (prevConfig ??
|
|
73
|
+
(themeLocale.value.prev === false
|
|
74
|
+
? null
|
|
75
|
+
: resolveFromSidebarItems(sidebarItems.value, routePath.value, -1)));
|
|
76
|
+
});
|
|
77
|
+
const nextLink = computed(() => {
|
|
78
|
+
const nextConfig = resolveFromFrontmatterConfig(frontmatter.value.next, routePath.value);
|
|
79
|
+
return nextConfig === false
|
|
80
|
+
? null
|
|
81
|
+
: (nextConfig ??
|
|
82
|
+
(themeLocale.value.next === false
|
|
83
|
+
? null
|
|
84
|
+
: resolveFromSidebarItems(sidebarItems.value, routePath.value, 1)));
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
prevLink,
|
|
88
|
+
nextLink,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
@@ -3,7 +3,9 @@ let promiseResolve = null;
|
|
|
3
3
|
const scrollPromise = {
|
|
4
4
|
wait: () => promise,
|
|
5
5
|
pending: () => {
|
|
6
|
-
promise = new Promise((resolve) =>
|
|
6
|
+
promise = new Promise((resolve) => {
|
|
7
|
+
promiseResolve = resolve;
|
|
8
|
+
});
|
|
7
9
|
},
|
|
8
10
|
resolve: () => {
|
|
9
11
|
promiseResolve?.();
|