@vuepress/theme-default 2.0.0-rc.4 → 2.0.0-rc.41
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/VPDarkIcon.vue +8 -0
- package/lib/client/components/{DropdownTransition.vue → VPDropdownTransition.vue} +10 -1
- package/lib/client/components/VPEditIcon.vue +12 -0
- package/lib/client/components/VPHome.vue +38 -0
- package/lib/client/components/VPHomeFeatures.vue +68 -0
- package/lib/client/components/{HomeFooter.vue → VPHomeFooter.vue} +16 -2
- package/lib/client/components/{HomeHero.vue → VPHomeHero.vue} +108 -7
- package/lib/client/components/VPLightIcon.vue +28 -0
- package/lib/client/components/VPNavbar.vue +125 -0
- package/lib/client/components/{NavbarBrand.vue → VPNavbarBrand.vue} +39 -6
- package/lib/client/components/VPNavbarDropdown.vue +320 -0
- package/lib/client/components/VPNavbarItems.vue +110 -0
- package/lib/client/components/VPPage.vue +69 -0
- package/lib/client/components/VPPageMeta.vue +132 -0
- package/lib/client/components/VPPageNav.vue +118 -0
- package/lib/client/components/VPSidebar.vue +112 -0
- package/lib/client/components/VPSidebarItem.vue +167 -0
- package/lib/client/components/{SidebarItems.vue → VPSidebarItems.vue} +31 -7
- package/lib/client/components/VPToggleColorModeButton.vue +54 -0
- package/lib/client/components/VPToggleSidebarButton.vue +92 -0
- package/lib/client/components/global/Badge.vue +60 -18
- package/lib/client/components/global/CodeGroup.d.ts +1 -0
- package/lib/client/components/global/CodeGroup.js +24 -4
- package/lib/client/components/global/CodeGroupItem.vue +5 -16
- package/lib/client/composables/index.d.ts +8 -0
- package/lib/client/composables/index.js +8 -0
- package/lib/client/composables/useContributors.d.ts +3 -0
- package/lib/client/composables/useContributors.js +14 -0
- package/lib/client/composables/useDarkMode.d.ts +0 -1
- package/lib/client/composables/useDarkMode.js +14 -13
- package/lib/client/composables/useEditLink.d.ts +3 -0
- package/lib/client/composables/useEditLink.js +31 -0
- package/lib/client/composables/useLastUpdated.d.ts +2 -0
- package/lib/client/composables/useLastUpdated.js +17 -0
- package/lib/client/composables/useNavbarConfig.d.ts +3 -0
- package/lib/client/composables/useNavbarConfig.js +25 -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 +58 -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 +91 -0
- package/lib/client/composables/useSidebarItems.d.ts +17 -12
- package/lib/client/composables/useSidebarItems.js +87 -52
- package/lib/client/composables/useUpdateDeviceStatus.js +5 -4
- package/lib/client/config.d.ts +2 -2
- package/lib/client/config.js +12 -13
- package/lib/client/index.d.ts +2 -1
- package/lib/client/index.js +1 -1
- package/lib/client/layouts/Layout.vue +121 -20
- package/lib/client/layouts/NotFound.vue +18 -4
- package/lib/client/shim.d.ts +3 -3
- package/lib/client/styles/_mixins.scss +4 -4
- package/lib/client/styles/_variables.module.scss +1 -1
- package/lib/client/styles/_variables.scss +1 -0
- package/lib/client/styles/arrow.scss +18 -24
- package/lib/client/styles/code-group.scss +34 -29
- package/lib/client/styles/content/code.scss +23 -0
- package/lib/client/styles/{custom-container.scss → content/custom-container.scss} +13 -13
- package/lib/client/styles/content/index.scss +4 -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 +37 -0
- package/lib/client/styles/index.scss +3 -13
- package/lib/client/styles/layout.scss +3 -199
- package/lib/client/styles/normalize.scss +20 -148
- package/lib/client/styles/plugins.scss +20 -0
- package/lib/client/styles/vars-dark.scss +17 -12
- package/lib/client/styles/vars.scss +72 -34
- package/lib/client/typings.d.ts +13 -0
- package/lib/client/typings.js +1 -0
- package/lib/client/utils/getAutoLink.d.ts +9 -0
- package/lib/client/utils/getAutoLink.js +17 -0
- package/lib/client/utils/index.d.ts +3 -2
- package/lib/client/utils/index.js +3 -2
- package/lib/client/utils/isActiveSidebarItem.d.ts +3 -3
- package/lib/client/utils/isActiveSidebarItem.js +3 -3
- package/lib/client/utils/isLinkInternal.d.ts +1 -0
- package/lib/client/utils/isLinkInternal.js +2 -0
- package/lib/client/utils/resolveEditLink.d.ts +1 -1
- package/lib/client/utils/resolvePrefix.d.ts +1 -0
- package/lib/client/utils/resolvePrefix.js +4 -0
- package/lib/node/defaultTheme.js +83 -24
- package/lib/node/index.d.ts +2 -1
- package/lib/node/index.js +1 -1
- package/lib/node/utils/assignDefaultLocaleOptions.js +1 -1
- package/lib/node/utils/resolveContainerPluginOptions.d.ts +3 -3
- package/lib/node/utils/resolveContainerPluginOptions.js +2 -2
- package/lib/shared/index.d.ts +2 -0
- package/lib/shared/index.js +2 -0
- 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 +31 -8
- package/lib/shared/page.d.ts +6 -4
- package/lib/shared/sidebar.d.ts +26 -0
- package/lib/shared/sidebar.js +1 -0
- package/package.json +22 -26
- package/templates/build.html +19 -10
- package/lib/client/components/AutoLink.vue +0 -113
- 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/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/styles/badge.scss +0 -36
- package/lib/client/styles/code.scss +0 -263
- 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
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useStorage } from '@vueuse/core';
|
|
2
2
|
import { computed, defineComponent, h, onBeforeUpdate, onMounted, ref, watch, } from 'vue';
|
|
3
|
+
import { useDarkMode } from '../../composables/useDarkMode.js';
|
|
4
|
+
import '../../styles/code-group.scss';
|
|
3
5
|
export const CodeGroup = defineComponent({
|
|
4
6
|
name: 'CodeGroup',
|
|
5
7
|
slots: Object,
|
|
@@ -13,6 +15,24 @@ export const CodeGroup = defineComponent({
|
|
|
13
15
|
tabRefs.value = [];
|
|
14
16
|
});
|
|
15
17
|
}
|
|
18
|
+
const isDark = useDarkMode();
|
|
19
|
+
const groupRef = ref();
|
|
20
|
+
// shiki highlighter color & background
|
|
21
|
+
onMounted(() => {
|
|
22
|
+
if (!groupRef.value)
|
|
23
|
+
return;
|
|
24
|
+
const codeBlock = groupRef.value.querySelector('div[class*="language-"]');
|
|
25
|
+
if (codeBlock && codeBlock.dataset.highlighter === 'shiki') {
|
|
26
|
+
const lightColor = codeBlock.style.getPropertyValue('--shiki-light');
|
|
27
|
+
const darkColor = codeBlock.style.getPropertyValue('--shiki-dark');
|
|
28
|
+
const lightBg = codeBlock.style.getPropertyValue('--shiki-light-bg');
|
|
29
|
+
const darkBg = codeBlock.style.getPropertyValue('--shiki-dark-bg');
|
|
30
|
+
watch(isDark, (val) => {
|
|
31
|
+
groupRef.value.style.setProperty('--c-code-group-tab-bg', val ? darkBg : lightBg);
|
|
32
|
+
groupRef.value.style.setProperty('--c-code-group-tab-title', val ? darkColor : lightColor);
|
|
33
|
+
}, { immediate: true });
|
|
34
|
+
}
|
|
35
|
+
});
|
|
16
36
|
// index of current active item
|
|
17
37
|
const activeIndex = ref(-1);
|
|
18
38
|
const codeGroupStorage = useStorage('vuepress-code-group', {});
|
|
@@ -94,8 +114,8 @@ export const CodeGroup = defineComponent({
|
|
|
94
114
|
vnode.props.active = i === activeIndex.value;
|
|
95
115
|
});
|
|
96
116
|
}
|
|
97
|
-
return h('div', { class: 'code-group' }, [
|
|
98
|
-
h('div', { class: 'code-
|
|
117
|
+
return h('div', { class: 'code-group', ref: groupRef }, [
|
|
118
|
+
h('div', { class: 'code-group-nav', role: 'tablist' }, items.map((vnode, i) => {
|
|
99
119
|
const isActive = i === activeIndex.value;
|
|
100
120
|
return h('button', {
|
|
101
121
|
ref: (element) => {
|
|
@@ -104,8 +124,8 @@ export const CodeGroup = defineComponent({
|
|
|
104
124
|
}
|
|
105
125
|
},
|
|
106
126
|
class: {
|
|
107
|
-
'code-
|
|
108
|
-
'
|
|
127
|
+
'code-group-nav-tab': true,
|
|
128
|
+
'active': isActive,
|
|
109
129
|
},
|
|
110
130
|
role: 'tab',
|
|
111
131
|
ariaSelected: isActive,
|
|
@@ -3,25 +3,14 @@ defineOptions({
|
|
|
3
3
|
name: 'CodeGroupItem',
|
|
4
4
|
})
|
|
5
5
|
|
|
6
|
-
defineProps
|
|
7
|
-
title:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
active: {
|
|
12
|
-
type: Boolean,
|
|
13
|
-
required: false,
|
|
14
|
-
default: false,
|
|
15
|
-
},
|
|
16
|
-
})
|
|
6
|
+
defineProps<{
|
|
7
|
+
title: string
|
|
8
|
+
active?: boolean
|
|
9
|
+
}>()
|
|
17
10
|
</script>
|
|
18
11
|
|
|
19
12
|
<template>
|
|
20
|
-
<div
|
|
21
|
-
class="code-group-item"
|
|
22
|
-
:class="{ 'code-group-item__active': active }"
|
|
23
|
-
role="tabpanel"
|
|
24
|
-
>
|
|
13
|
+
<div class="code-group-item" :class="{ active }" role="tabpanel">
|
|
25
14
|
<slot />
|
|
26
15
|
</div>
|
|
27
16
|
</template>
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
export * from './useContributors.js';
|
|
1
2
|
export * from './useDarkMode.js';
|
|
3
|
+
export * from './useEditLink.js';
|
|
4
|
+
export * from './useLastUpdated.js';
|
|
5
|
+
export * from './useNavigate.js';
|
|
6
|
+
export * from './useNavbarConfig.js';
|
|
7
|
+
export * from './useNavbarRepo.js';
|
|
8
|
+
export * from './useNavbarSelectLanguage.js';
|
|
9
|
+
export * from './useRelatedLinks.js';
|
|
2
10
|
export * from './useScrollPromise.js';
|
|
3
11
|
export * from './useSidebarItems.js';
|
|
4
12
|
export * from './useThemeData.js';
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
export * from './useContributors.js';
|
|
1
2
|
export * from './useDarkMode.js';
|
|
3
|
+
export * from './useEditLink.js';
|
|
4
|
+
export * from './useLastUpdated.js';
|
|
5
|
+
export * from './useNavigate.js';
|
|
6
|
+
export * from './useNavbarConfig.js';
|
|
7
|
+
export * from './useNavbarRepo.js';
|
|
8
|
+
export * from './useNavbarSelectLanguage.js';
|
|
9
|
+
export * from './useRelatedLinks.js';
|
|
2
10
|
export * from './useScrollPromise.js';
|
|
3
11
|
export * from './useSidebarItems.js';
|
|
4
12
|
export * from './useThemeData.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { usePageData, usePageFrontmatter } from 'vuepress/client';
|
|
4
|
+
export const useContributors = () => {
|
|
5
|
+
const themeLocale = useThemeLocaleData();
|
|
6
|
+
const page = usePageData();
|
|
7
|
+
const frontmatter = usePageFrontmatter();
|
|
8
|
+
return computed(() => {
|
|
9
|
+
const showContributors = frontmatter.value.contributors ?? themeLocale.value.contributors ?? true;
|
|
10
|
+
if (!showContributors)
|
|
11
|
+
return null;
|
|
12
|
+
return page.value.git?.contributors ?? null;
|
|
13
|
+
});
|
|
14
|
+
};
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
1
2
|
import { usePreferredDark, useStorage } from '@vueuse/core';
|
|
2
3
|
import { computed, inject, onMounted, onUnmounted, provide, watch } from 'vue';
|
|
3
|
-
import { useThemeLocaleData } from './useThemeData.js';
|
|
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
|
+
el.classList.toggle('dark', value);
|
|
10
|
+
el.dataset.theme = value ? 'dark' : 'light';
|
|
11
|
+
};
|
|
12
|
+
onMounted(() => {
|
|
13
|
+
watch(isDarkMode, update, { immediate: true });
|
|
14
|
+
});
|
|
15
|
+
onUnmounted(() => update());
|
|
16
|
+
};
|
|
5
17
|
/**
|
|
6
18
|
* Inject dark mode global computed
|
|
7
19
|
*/
|
|
@@ -42,16 +54,5 @@ export const setupDarkMode = () => {
|
|
|
42
54
|
},
|
|
43
55
|
});
|
|
44
56
|
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());
|
|
57
|
+
applyDarkmodeToHTML(isDarkMode);
|
|
57
58
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { usePageData, usePageFrontmatter } from 'vuepress/client';
|
|
4
|
+
import { resolveEditLink } from '../utils/index.js';
|
|
5
|
+
export const useEditLink = () => {
|
|
6
|
+
const themeLocale = useThemeLocaleData();
|
|
7
|
+
const page = usePageData();
|
|
8
|
+
const frontmatter = usePageFrontmatter();
|
|
9
|
+
return computed(() => {
|
|
10
|
+
const showEditLink = frontmatter.value.editLink ?? themeLocale.value.editLink ?? true;
|
|
11
|
+
if (!showEditLink) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const { repo, docsRepo = repo, docsBranch = 'main', docsDir = '', editLinkText, } = themeLocale.value;
|
|
15
|
+
if (!docsRepo)
|
|
16
|
+
return null;
|
|
17
|
+
const editLink = resolveEditLink({
|
|
18
|
+
docsRepo,
|
|
19
|
+
docsBranch,
|
|
20
|
+
docsDir,
|
|
21
|
+
filePathRelative: page.value.filePathRelative,
|
|
22
|
+
editLinkPattern: frontmatter.value.editLinkPattern ?? themeLocale.value.editLinkPattern,
|
|
23
|
+
});
|
|
24
|
+
if (!editLink)
|
|
25
|
+
return null;
|
|
26
|
+
return {
|
|
27
|
+
text: editLinkText ?? 'Edit this page',
|
|
28
|
+
link: editLink,
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { usePageData, usePageFrontmatter } from 'vuepress/client';
|
|
4
|
+
export const useLastUpdated = () => {
|
|
5
|
+
const themeLocale = useThemeLocaleData();
|
|
6
|
+
const page = usePageData();
|
|
7
|
+
const frontmatter = usePageFrontmatter();
|
|
8
|
+
return computed(() => {
|
|
9
|
+
const showLastUpdated = frontmatter.value.lastUpdated ?? themeLocale.value.lastUpdated ?? true;
|
|
10
|
+
if (!showLastUpdated)
|
|
11
|
+
return null;
|
|
12
|
+
if (!page.value.git?.updatedTime)
|
|
13
|
+
return null;
|
|
14
|
+
const updatedDate = new Date(page.value.git?.updatedTime);
|
|
15
|
+
return updatedDate.toLocaleString();
|
|
16
|
+
});
|
|
17
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { isString } from 'vuepress/shared';
|
|
4
|
+
import { getAutoLink, isLinkInternal, resolvePrefix } from '../utils/index.js';
|
|
5
|
+
const resolveNavbarItem = (item, prefix = '') => {
|
|
6
|
+
if (isString(item)) {
|
|
7
|
+
return getAutoLink(resolvePrefix(prefix, item));
|
|
8
|
+
}
|
|
9
|
+
if ('children' in item) {
|
|
10
|
+
return {
|
|
11
|
+
...item,
|
|
12
|
+
children: item.children.map((child) => resolveNavbarItem(child, resolvePrefix(prefix, item.prefix))),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
...item,
|
|
17
|
+
link: isLinkInternal(item.link)
|
|
18
|
+
? getAutoLink(resolvePrefix(prefix, item.link)).link
|
|
19
|
+
: item.link,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export const useNavbarConfig = () => {
|
|
23
|
+
const themeLocale = useThemeLocaleData();
|
|
24
|
+
return computed(() => (themeLocale.value.navbar || []).map((item) => resolveNavbarItem(item)));
|
|
25
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { isLinkHttp } from 'vuepress/shared';
|
|
4
|
+
import { resolveRepoType } from '../utils/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Get navbar config of repository link
|
|
7
|
+
*/
|
|
8
|
+
export const useNavbarRepo = () => {
|
|
9
|
+
const themeLocale = useThemeLocaleData();
|
|
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,58 @@
|
|
|
1
|
+
import { useThemeData, useThemeLocaleData } from '@theme/useThemeData';
|
|
2
|
+
import { useRoutePaths } from '@vuepress/helper/client';
|
|
3
|
+
import { computed } from 'vue';
|
|
4
|
+
import { useRoute, useRouteLocale, useSiteData, useSiteLocaleData, } 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 = useRouteLocale();
|
|
12
|
+
const site = useSiteData();
|
|
13
|
+
const siteLocale = useSiteLocaleData();
|
|
14
|
+
const theme = useThemeData();
|
|
15
|
+
const themeLocale = useThemeLocaleData();
|
|
16
|
+
return computed(() => {
|
|
17
|
+
const localePaths = Object.keys(site.value.locales);
|
|
18
|
+
// do not display language selection dropdown if there is only one language
|
|
19
|
+
if (localePaths.length < 2) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
const currentPath = route.path;
|
|
23
|
+
const currentFullPath = route.fullPath;
|
|
24
|
+
const languageDropdown = {
|
|
25
|
+
text: `${themeLocale.value.selectLanguageText}`,
|
|
26
|
+
ariaLabel: `${themeLocale.value.selectLanguageAriaLabel ??
|
|
27
|
+
themeLocale.value.selectLanguageText}`,
|
|
28
|
+
children: localePaths.map((targetLocalePath) => {
|
|
29
|
+
// target locale config of this language link
|
|
30
|
+
const targetSiteLocale = site.value.locales?.[targetLocalePath] ?? {};
|
|
31
|
+
const targetThemeLocale = theme.value.locales?.[targetLocalePath] ?? {};
|
|
32
|
+
const targetLang = `${targetSiteLocale.lang}`;
|
|
33
|
+
const text = targetThemeLocale.selectLanguageName ?? targetLang;
|
|
34
|
+
// if the target language is current language
|
|
35
|
+
// stay at current link
|
|
36
|
+
if (targetLang === siteLocale.value.lang) {
|
|
37
|
+
return {
|
|
38
|
+
text,
|
|
39
|
+
activeMatch: '.',
|
|
40
|
+
link: route.fullPath,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// if the target language is not current language
|
|
44
|
+
// try to link to the corresponding page of current page
|
|
45
|
+
// or fallback to homepage
|
|
46
|
+
const targetLocalePage = currentPath.replace(routeLocale.value, targetLocalePath);
|
|
47
|
+
return {
|
|
48
|
+
text,
|
|
49
|
+
// try to keep current hash and params across languages
|
|
50
|
+
link: routePaths.value.some((item) => item === targetLocalePage)
|
|
51
|
+
? currentFullPath.replace(currentPath, targetLocalePage)
|
|
52
|
+
: (targetThemeLocale.home ?? targetLocalePath),
|
|
53
|
+
};
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
56
|
+
return [languageDropdown];
|
|
57
|
+
});
|
|
58
|
+
};
|
|
@@ -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.path !== 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,91 @@
|
|
|
1
|
+
import { useSidebarItems } from '@theme/useSidebarItems';
|
|
2
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
3
|
+
import { computed } from 'vue';
|
|
4
|
+
import { resolveRoute, usePageFrontmatter, useRoute } from 'vuepress/client';
|
|
5
|
+
import { isPlainObject, isString } from 'vuepress/shared';
|
|
6
|
+
import { getAutoLink } from '../utils/index.js';
|
|
7
|
+
const resolveFromFrontmatterConfig = (config, currentPath) => {
|
|
8
|
+
if (config === false) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (isString(config)) {
|
|
12
|
+
return getAutoLink(config, currentPath);
|
|
13
|
+
}
|
|
14
|
+
if (isPlainObject(config)) {
|
|
15
|
+
return {
|
|
16
|
+
...config,
|
|
17
|
+
link: getAutoLink(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 = usePageFrontmatter();
|
|
66
|
+
const themeLocale = useThemeLocaleData();
|
|
67
|
+
const sidebarItems = useSidebarItems();
|
|
68
|
+
const route = useRoute();
|
|
69
|
+
const prevLink = computed(() => {
|
|
70
|
+
const prevConfig = resolveFromFrontmatterConfig(frontmatter.value.prev, route.path);
|
|
71
|
+
return prevConfig === false
|
|
72
|
+
? null
|
|
73
|
+
: (prevConfig ??
|
|
74
|
+
(themeLocale.value.prev === false
|
|
75
|
+
? null
|
|
76
|
+
: resolveFromSidebarItems(sidebarItems.value, route.path, -1)));
|
|
77
|
+
});
|
|
78
|
+
const nextLink = computed(() => {
|
|
79
|
+
const nextConfig = resolveFromFrontmatterConfig(frontmatter.value.next, route.path);
|
|
80
|
+
return nextConfig === false
|
|
81
|
+
? null
|
|
82
|
+
: (nextConfig ??
|
|
83
|
+
(themeLocale.value.next === false
|
|
84
|
+
? null
|
|
85
|
+
: resolveFromSidebarItems(sidebarItems.value, route.path, 1)));
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
prevLink,
|
|
89
|
+
nextLink,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { PageData
|
|
4
|
-
import type {
|
|
5
|
-
|
|
1
|
+
import type { MenuItem } from '@vuepress/helper/client';
|
|
2
|
+
import type { ComputedRef, InjectionKey, Ref } from 'vue';
|
|
3
|
+
import type { PageData } from 'vuepress/client';
|
|
4
|
+
import type { SidebarArrayOptions, SidebarObjectOptions, SidebarOptions } from '../../shared/index.js';
|
|
5
|
+
import type { SidebarHeaderItem, SidebarItem } from '../typings.js';
|
|
6
|
+
export type HeadersRef = Ref<MenuItem[]>;
|
|
7
|
+
export declare const headersRef: HeadersRef;
|
|
8
|
+
export declare const setupHeaders: () => void;
|
|
9
|
+
export declare const useHeaders: () => HeadersRef;
|
|
10
|
+
export type SidebarItemsRef = ComputedRef<SidebarItem[]>;
|
|
6
11
|
export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
|
|
7
12
|
/**
|
|
8
13
|
* Inject sidebar items global computed
|
|
@@ -17,21 +22,21 @@ export declare const setupSidebarItems: () => void;
|
|
|
17
22
|
*
|
|
18
23
|
* It should only be resolved and provided once
|
|
19
24
|
*/
|
|
20
|
-
export declare const resolveSidebarItems: (
|
|
25
|
+
export declare const resolveSidebarItems: (sidebarConfig: false | SidebarOptions, page: PageData, path: string, routeLocale: string, headers: MenuItem[]) => SidebarItem[];
|
|
21
26
|
/**
|
|
22
27
|
* Util to transform page header to sidebar item
|
|
23
28
|
*/
|
|
24
|
-
export declare const
|
|
25
|
-
export declare const
|
|
29
|
+
export declare const resolveSidebarHeaderItem: (header: MenuItem) => SidebarHeaderItem;
|
|
30
|
+
export declare const resolveSidebarHeaderItems: (headers?: MenuItem[]) => SidebarHeaderItem[];
|
|
26
31
|
/**
|
|
27
|
-
* Resolve sidebar items if the config is `
|
|
32
|
+
* Resolve current page and its header to sidebar items if the config is `heading`
|
|
28
33
|
*/
|
|
29
|
-
export declare const
|
|
34
|
+
export declare const resolveSidebarHeadingItem: (page: PageData, headers: MenuItem[]) => SidebarItem[];
|
|
30
35
|
/**
|
|
31
36
|
* Resolve sidebar items if the config is an array
|
|
32
37
|
*/
|
|
33
|
-
export declare const resolveArraySidebarItems: (
|
|
38
|
+
export declare const resolveArraySidebarItems: (sidebarConfig: SidebarArrayOptions, headers: MenuItem[], path: string, prefix?: string) => SidebarItem[];
|
|
34
39
|
/**
|
|
35
40
|
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
36
41
|
*/
|
|
37
|
-
export declare const resolveMultiSidebarItems: (page: PageData,
|
|
42
|
+
export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarObjectOptions, page: PageData, headers: MenuItem[], path: string) => SidebarItem[];
|