@vuepress/theme-default 2.0.0-rc.32 → 2.0.0-rc.34
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} +107 -5
- package/lib/client/components/VPLightIcon.vue +28 -0
- package/lib/client/components/VPNavbar.vue +127 -0
- package/lib/client/components/{NavbarBrand.vue → VPNavbarBrand.vue} +36 -4
- package/lib/client/components/VPNavbarDropdown.vue +319 -0
- package/lib/client/components/VPNavbarItems.vue +110 -0
- package/lib/client/components/VPPage.vue +66 -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 +169 -0
- package/lib/client/components/{SidebarItems.vue → VPSidebarItems.vue} +30 -6
- 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 +4 -3
- package/lib/client/components/global/CodeGroupItem.vue +5 -16
- package/lib/client/composables/index.d.ts +7 -0
- package/lib/client/composables/index.js +7 -0
- package/lib/client/composables/useContributors.d.ts +3 -0
- package/lib/client/composables/useContributors.js +14 -0
- package/lib/client/composables/useDarkMode.js +1 -1
- 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.js +4 -7
- package/lib/client/composables/useRelatedLinks.d.ts +8 -0
- package/lib/client/composables/useRelatedLinks.js +73 -0
- package/lib/client/composables/useSidebarItems.d.ts +10 -9
- package/lib/client/composables/useSidebarItems.js +58 -47
- package/lib/client/config.d.ts +1 -0
- package/lib/client/config.js +2 -1
- package/lib/client/index.d.ts +1 -0
- package/lib/client/index.js +1 -0
- package/lib/client/layouts/Layout.vue +111 -18
- package/lib/client/layouts/NotFound.vue +1 -1
- 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/code-group.scss +32 -29
- package/lib/client/styles/{code.scss → content/code.scss} +81 -99
- package/lib/client/styles/{custom-container.scss → content/custom-container.scss} +9 -5
- 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 +7 -3
- package/lib/client/styles/index.scss +2 -13
- package/lib/client/styles/layout.scss +3 -203
- package/lib/client/styles/normalize.scss +18 -149
- package/lib/client/styles/plugins.scss +20 -0
- package/lib/client/styles/vars-dark.scss +17 -16
- package/lib/client/styles/vars.scss +19 -23
- package/lib/client/typings.d.ts +13 -0
- package/lib/client/typings.js +1 -0
- package/lib/client/utils/{getNavLink.d.ts → getAutoLink.d.ts} +2 -2
- package/lib/client/utils/index.d.ts +3 -1
- package/lib/client/utils/index.js +3 -1
- package/lib/client/utils/isActiveSidebarItem.d.ts +2 -2
- 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/resolvePrefix.d.ts +1 -0
- package/lib/client/utils/resolvePrefix.js +4 -0
- package/lib/node/defaultTheme.js +9 -1
- package/lib/node/utils/assignDefaultLocaleOptions.js +1 -1
- package/lib/shared/index.d.ts +2 -0
- package/lib/shared/index.js +2 -0
- package/lib/shared/nav.d.ts +23 -26
- package/lib/shared/navbar.d.ts +21 -0
- package/lib/shared/navbar.js +1 -0
- package/lib/shared/options.d.ts +4 -3
- package/lib/shared/page.d.ts +2 -2
- package/lib/shared/sidebar.d.ts +26 -0
- package/lib/shared/sidebar.js +1 -0
- package/package.json +19 -19
- package/templates/build.html +2 -0
- 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 -80
- package/lib/client/components/NavbarDropdown.vue +0 -125
- package/lib/client/components/NavbarItems.vue +0 -198
- package/lib/client/components/Page.vue +0 -31
- package/lib/client/components/PageMeta.vue +0 -220
- package/lib/client/components/PageNav.vue +0 -228
- package/lib/client/components/Sidebar.vue +0 -18
- package/lib/client/components/SidebarItem.vue +0 -86
- 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/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 -11
- package/lib/client/styles/sidebar.scss +0 -134
- package/lib/client/styles/transitions.scss +0 -22
- /package/lib/client/utils/{getNavLink.js → getAutoLink.js} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useStorage } from '@vueuse/core';
|
|
2
2
|
import { computed, defineComponent, h, onBeforeUpdate, onMounted, ref, watch, } from 'vue';
|
|
3
|
+
import '../../styles/code-group.scss';
|
|
3
4
|
export const CodeGroup = defineComponent({
|
|
4
5
|
name: 'CodeGroup',
|
|
5
6
|
slots: Object,
|
|
@@ -95,7 +96,7 @@ export const CodeGroup = defineComponent({
|
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
return h('div', { class: 'code-group' }, [
|
|
98
|
-
h('div', { class: 'code-
|
|
99
|
+
h('div', { class: 'code-group-nav', role: 'tablist' }, items.map((vnode, i) => {
|
|
99
100
|
const isActive = i === activeIndex.value;
|
|
100
101
|
return h('button', {
|
|
101
102
|
ref: (element) => {
|
|
@@ -104,8 +105,8 @@ export const CodeGroup = defineComponent({
|
|
|
104
105
|
}
|
|
105
106
|
},
|
|
106
107
|
class: {
|
|
107
|
-
'code-
|
|
108
|
-
'
|
|
108
|
+
'code-group-nav-tab': true,
|
|
109
|
+
'active': isActive,
|
|
109
110
|
},
|
|
110
111
|
role: 'tab',
|
|
111
112
|
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,5 +1,12 @@
|
|
|
1
|
+
export * from './useContributors.js';
|
|
1
2
|
export * from './useDarkMode.js';
|
|
3
|
+
export * from './useEditLink.js';
|
|
4
|
+
export * from './useLastUpdated.js';
|
|
2
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';
|
|
3
10
|
export * from './useScrollPromise.js';
|
|
4
11
|
export * from './useSidebarItems.js';
|
|
5
12
|
export * from './useThemeData.js';
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
export * from './useContributors.js';
|
|
1
2
|
export * from './useDarkMode.js';
|
|
3
|
+
export * from './useEditLink.js';
|
|
4
|
+
export * from './useLastUpdated.js';
|
|
2
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';
|
|
3
10
|
export * from './useScrollPromise.js';
|
|
4
11
|
export * from './useSidebarItems.js';
|
|
5
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,6 +1,6 @@
|
|
|
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
5
|
/**
|
|
6
6
|
* Inject dark mode global computed
|
|
@@ -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
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isLinkAbsolute, isLinkWithProtocol } from '@vuepress/helper/client';
|
|
2
2
|
import { useRoute, useRouter } from 'vuepress/client';
|
|
3
|
-
const FAKE_HOST = 'http://.';
|
|
4
3
|
export const useNavigate = () => {
|
|
5
4
|
const router = useRouter();
|
|
6
5
|
const route = useRoute();
|
|
@@ -12,14 +11,12 @@ export const useNavigate = () => {
|
|
|
12
11
|
router.push(url);
|
|
13
12
|
}
|
|
14
13
|
else if (isLinkWithProtocol(url)) {
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
window.open(url);
|
|
14
|
+
// external url
|
|
15
|
+
window?.open(url);
|
|
18
16
|
}
|
|
19
17
|
else {
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
router.push(new URL(`${loc}/${encodeURI(url)}`, FAKE_HOST).pathname);
|
|
18
|
+
// relative url
|
|
19
|
+
router.push(encodeURI(url));
|
|
23
20
|
}
|
|
24
21
|
};
|
|
25
22
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ComputedRef } from 'vue';
|
|
2
|
+
import type { AutoLinkConfig } from 'vuepress/client';
|
|
3
|
+
interface RelatedLinks {
|
|
4
|
+
prevLink: ComputedRef<AutoLinkConfig | null>;
|
|
5
|
+
nextLink: ComputedRef<AutoLinkConfig | null>;
|
|
6
|
+
}
|
|
7
|
+
export declare const useRelatedLinks: () => RelatedLinks;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { useSidebarItems } from '@theme/useSidebarItems';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { resolveRoute, usePageFrontmatter, useRoute } from 'vuepress/client';
|
|
4
|
+
import { isPlainObject, isString } from 'vuepress/shared';
|
|
5
|
+
/**
|
|
6
|
+
* Resolve `prev` or `next` config from frontmatter
|
|
7
|
+
*/
|
|
8
|
+
const resolveFromFrontmatterConfig = (conf, current) => {
|
|
9
|
+
if (conf === false) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (isString(conf)) {
|
|
13
|
+
const { notFound, meta, path } = resolveRoute(conf, current);
|
|
14
|
+
return notFound
|
|
15
|
+
? { text: path, link: path }
|
|
16
|
+
: {
|
|
17
|
+
text: meta.title || path,
|
|
18
|
+
link: path,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (isPlainObject(conf)) {
|
|
22
|
+
return {
|
|
23
|
+
...conf,
|
|
24
|
+
link: resolveRoute(conf.link, current).path,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Resolve `prev` or `next` config from sidebar items
|
|
31
|
+
*/
|
|
32
|
+
const resolveFromSidebarItems = (sidebarItems, currentPath, offset) => {
|
|
33
|
+
const index = sidebarItems.findIndex((item) => item.link === currentPath);
|
|
34
|
+
if (index !== -1) {
|
|
35
|
+
const targetItem = sidebarItems[index + offset];
|
|
36
|
+
if (!targetItem?.link) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return targetItem;
|
|
40
|
+
}
|
|
41
|
+
for (const item of sidebarItems) {
|
|
42
|
+
if ('children' in item) {
|
|
43
|
+
const childResult = resolveFromSidebarItems(item.children, currentPath, offset);
|
|
44
|
+
if (childResult) {
|
|
45
|
+
return childResult;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
export const useRelatedLinks = () => {
|
|
52
|
+
const frontmatter = usePageFrontmatter();
|
|
53
|
+
const sidebarItems = useSidebarItems();
|
|
54
|
+
const route = useRoute();
|
|
55
|
+
const prevLink = computed(() => {
|
|
56
|
+
const prevConfig = resolveFromFrontmatterConfig(frontmatter.value.prev, route.path);
|
|
57
|
+
if (prevConfig !== false) {
|
|
58
|
+
return prevConfig;
|
|
59
|
+
}
|
|
60
|
+
return resolveFromSidebarItems(sidebarItems.value, route.path, -1);
|
|
61
|
+
});
|
|
62
|
+
const nextLink = computed(() => {
|
|
63
|
+
const nextConfig = resolveFromFrontmatterConfig(frontmatter.value.next, route.path);
|
|
64
|
+
if (nextConfig !== false) {
|
|
65
|
+
return nextConfig;
|
|
66
|
+
}
|
|
67
|
+
return resolveFromSidebarItems(sidebarItems.value, route.path, 1);
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
prevLink,
|
|
71
|
+
nextLink,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ComputedRef, InjectionKey } from 'vue';
|
|
2
2
|
import type { PageData, PageHeader } from 'vuepress/client';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type { SidebarArrayOptions, SidebarObjectOptions, SidebarOptions } from '../../shared/index.js';
|
|
4
|
+
import type { SidebarHeaderItem, SidebarItem } from '../typings.js';
|
|
5
|
+
export type SidebarItemsRef = ComputedRef<SidebarItem[]>;
|
|
5
6
|
export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
|
|
6
7
|
/**
|
|
7
8
|
* Inject sidebar items global computed
|
|
@@ -16,21 +17,21 @@ export declare const setupSidebarItems: () => void;
|
|
|
16
17
|
*
|
|
17
18
|
* It should only be resolved and provided once
|
|
18
19
|
*/
|
|
19
|
-
export declare const resolveSidebarItems: (
|
|
20
|
+
export declare const resolveSidebarItems: (sidebarConfig: false | SidebarOptions, sidebarDepth: number, page: PageData, path: string, routeLocale: string) => SidebarItem[];
|
|
20
21
|
/**
|
|
21
22
|
* Util to transform page header to sidebar item
|
|
22
23
|
*/
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const
|
|
24
|
+
export declare const resolveSidebarHeaderItem: (sidebarDepth: number, header: PageHeader) => SidebarHeaderItem;
|
|
25
|
+
export declare const resolveSidebarHeaderItems: (sidebarDepth: number, headers: PageHeader[]) => SidebarHeaderItem[];
|
|
25
26
|
/**
|
|
26
|
-
* Resolve sidebar items if the config is `
|
|
27
|
+
* Resolve current page and its header to sidebar items if the config is `heading`
|
|
27
28
|
*/
|
|
28
|
-
export declare const
|
|
29
|
+
export declare const resolveSidebarHeadingItem: (sidebarDepth: number, page: PageData) => SidebarItem[];
|
|
29
30
|
/**
|
|
30
31
|
* Resolve sidebar items if the config is an array
|
|
31
32
|
*/
|
|
32
|
-
export declare const resolveArraySidebarItems: (
|
|
33
|
+
export declare const resolveArraySidebarItems: (sidebarConfig: SidebarArrayOptions, sidebarDepth: number, page: PageData, path: string, prefix?: string) => SidebarItem[];
|
|
33
34
|
/**
|
|
34
35
|
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
35
36
|
*/
|
|
36
|
-
export declare const resolveMultiSidebarItems: (
|
|
37
|
+
export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarObjectOptions, sidebarDepth: number, page: PageData, path: string) => SidebarItem[];
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
2
|
+
import { keys, startsWith } from '@vuepress/helper/client';
|
|
1
3
|
import { computed, inject, provide } from 'vue';
|
|
2
|
-
import { usePageData, usePageFrontmatter, useRoute } from 'vuepress/client';
|
|
3
|
-
import { isPlainObject, isString
|
|
4
|
-
import { getAutoLink } from '../utils/index.js';
|
|
5
|
-
import { useThemeLocaleData } from './useThemeData.js';
|
|
4
|
+
import { usePageData, usePageFrontmatter, useRoute, useRouteLocale, } from 'vuepress/client';
|
|
5
|
+
import { isPlainObject, isString } from 'vuepress/shared';
|
|
6
|
+
import { getAutoLink, isLinkInternal, resolvePrefix } from '../utils/index.js';
|
|
6
7
|
export const sidebarItemsSymbol = Symbol('sidebarItems');
|
|
7
8
|
/**
|
|
8
9
|
* Inject sidebar items global computed
|
|
@@ -22,7 +23,12 @@ export const setupSidebarItems = () => {
|
|
|
22
23
|
const frontmatter = usePageFrontmatter();
|
|
23
24
|
const page = usePageData();
|
|
24
25
|
const route = useRoute();
|
|
25
|
-
const
|
|
26
|
+
const routeLocale = useRouteLocale();
|
|
27
|
+
const sidebarConfig = computed(() => frontmatter.value.home
|
|
28
|
+
? false
|
|
29
|
+
: frontmatter.value.sidebar ?? themeLocale.value.sidebar ?? 'heading');
|
|
30
|
+
const sidebarDepth = computed(() => frontmatter.value.sidebarDepth ?? themeLocale.value.sidebarDepth ?? 2);
|
|
31
|
+
const sidebarItems = computed(() => resolveSidebarItems(sidebarConfig.value, sidebarDepth.value, page.value, route.path, routeLocale.value));
|
|
26
32
|
provide(sidebarItemsSymbol, sidebarItems);
|
|
27
33
|
};
|
|
28
34
|
/**
|
|
@@ -30,63 +36,61 @@ export const setupSidebarItems = () => {
|
|
|
30
36
|
*
|
|
31
37
|
* It should only be resolved and provided once
|
|
32
38
|
*/
|
|
33
|
-
export const resolveSidebarItems = (
|
|
34
|
-
// get sidebar config from frontmatter > theme data
|
|
35
|
-
const sidebarConfig = frontmatter.sidebar ?? themeLocale.sidebar ?? 'auto';
|
|
36
|
-
const sidebarDepth = frontmatter.sidebarDepth ?? themeLocale.sidebarDepth ?? 2;
|
|
39
|
+
export const resolveSidebarItems = (sidebarConfig, sidebarDepth, page, path, routeLocale) => {
|
|
37
40
|
// resolve sidebar items according to the config
|
|
38
|
-
if (
|
|
41
|
+
if (sidebarConfig === false) {
|
|
39
42
|
return [];
|
|
40
43
|
}
|
|
41
|
-
if (sidebarConfig === '
|
|
42
|
-
return
|
|
44
|
+
if (sidebarConfig === 'heading') {
|
|
45
|
+
return resolveSidebarHeadingItem(sidebarDepth, page);
|
|
43
46
|
}
|
|
44
47
|
if (Array.isArray(sidebarConfig)) {
|
|
45
|
-
return resolveArraySidebarItems(page, path,
|
|
48
|
+
return resolveArraySidebarItems(sidebarConfig, sidebarDepth, page, path, routeLocale);
|
|
46
49
|
}
|
|
47
50
|
if (isPlainObject(sidebarConfig)) {
|
|
48
|
-
return resolveMultiSidebarItems(
|
|
51
|
+
return resolveMultiSidebarItems(sidebarConfig, sidebarDepth, page, path);
|
|
49
52
|
}
|
|
50
53
|
return [];
|
|
51
54
|
};
|
|
52
55
|
/**
|
|
53
56
|
* Util to transform page header to sidebar item
|
|
54
57
|
*/
|
|
55
|
-
export const
|
|
58
|
+
export const resolveSidebarHeaderItem = (sidebarDepth, header) => ({
|
|
56
59
|
text: header.title,
|
|
57
60
|
link: header.link,
|
|
58
|
-
children:
|
|
61
|
+
children: resolveSidebarHeaderItems(sidebarDepth, header.children),
|
|
59
62
|
});
|
|
60
|
-
export const
|
|
61
|
-
? headers.map((header) =>
|
|
63
|
+
export const resolveSidebarHeaderItems = (sidebarDepth, headers) => sidebarDepth > 0
|
|
64
|
+
? headers.map((header) => resolveSidebarHeaderItem(sidebarDepth - 1, header))
|
|
62
65
|
: [];
|
|
63
66
|
/**
|
|
64
|
-
* Resolve sidebar items if the config is `
|
|
67
|
+
* Resolve current page and its header to sidebar items if the config is `heading`
|
|
65
68
|
*/
|
|
66
|
-
export const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
];
|
|
73
|
-
};
|
|
69
|
+
export const resolveSidebarHeadingItem = (sidebarDepth, page) => [
|
|
70
|
+
{
|
|
71
|
+
text: page.title,
|
|
72
|
+
children: resolveSidebarHeaderItems(sidebarDepth, page.headers),
|
|
73
|
+
},
|
|
74
|
+
];
|
|
74
75
|
/**
|
|
75
76
|
* Resolve sidebar items if the config is an array
|
|
76
77
|
*/
|
|
77
|
-
export const resolveArraySidebarItems = (page, path,
|
|
78
|
-
const handleChildItem = (item) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
export const resolveArraySidebarItems = (sidebarConfig, sidebarDepth, page, path, prefix = '') => {
|
|
79
|
+
const handleChildItem = (item, pathPrefix) => {
|
|
80
|
+
const childItem = isString(item)
|
|
81
|
+
? getAutoLink(resolvePrefix(pathPrefix, item))
|
|
82
|
+
: isString(item.link)
|
|
83
|
+
? {
|
|
84
|
+
...item,
|
|
85
|
+
link: isLinkInternal(item.link)
|
|
86
|
+
? getAutoLink(resolvePrefix(pathPrefix, item.link)).link
|
|
87
|
+
: item.link,
|
|
88
|
+
}
|
|
89
|
+
: item;
|
|
90
|
+
if ('children' in childItem) {
|
|
87
91
|
return {
|
|
88
92
|
...childItem,
|
|
89
|
-
children: childItem.children.map((item) => handleChildItem(item)),
|
|
93
|
+
children: childItem.children.map((item) => handleChildItem(item, resolvePrefix(pathPrefix, childItem.prefix))),
|
|
90
94
|
};
|
|
91
95
|
}
|
|
92
96
|
// if the sidebar item is current page and children is not set
|
|
@@ -96,21 +100,28 @@ export const resolveArraySidebarItems = (page, path, sidebarConfig, sidebarDepth
|
|
|
96
100
|
const headers = page.headers[0]?.level === 1 ? page.headers[0].children : page.headers;
|
|
97
101
|
return {
|
|
98
102
|
...childItem,
|
|
99
|
-
children:
|
|
103
|
+
children: resolveSidebarHeaderItems(sidebarDepth, headers),
|
|
100
104
|
};
|
|
101
105
|
}
|
|
102
106
|
return childItem;
|
|
103
107
|
};
|
|
104
|
-
return sidebarConfig.map((item) => handleChildItem(item));
|
|
108
|
+
return sidebarConfig.map((item) => handleChildItem(item, prefix));
|
|
105
109
|
};
|
|
106
110
|
/**
|
|
107
111
|
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
108
112
|
*/
|
|
109
|
-
export const resolveMultiSidebarItems = (
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
export const resolveMultiSidebarItems = (sidebarConfig, sidebarDepth, page, path) => {
|
|
114
|
+
const sidebarRoutes = keys(sidebarConfig).sort((x, y) => y.length - x.length);
|
|
115
|
+
// Find matching config
|
|
116
|
+
for (const base of sidebarRoutes)
|
|
117
|
+
if (startsWith(decodeURI(path), base)) {
|
|
118
|
+
const matched = sidebarConfig[base];
|
|
119
|
+
return matched
|
|
120
|
+
? matched === 'heading'
|
|
121
|
+
? resolveSidebarHeadingItem(sidebarDepth, page)
|
|
122
|
+
: resolveArraySidebarItems(matched, sidebarDepth, page, path, base)
|
|
123
|
+
: [];
|
|
124
|
+
}
|
|
125
|
+
console.warn(`${decodeURI(path)} is missing sidebar config.`);
|
|
126
|
+
return [];
|
|
116
127
|
};
|