@vuepress/theme-default 2.0.0-rc.34 → 2.0.0-rc.35
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/composables/useRelatedLinks.d.ts +3 -3
- package/lib/client/composables/useRelatedLinks.js +50 -32
- package/lib/client/config.js +3 -1
- package/lib/client/utils/getAutoLink.d.ts +1 -1
- package/lib/client/utils/getAutoLink.js +2 -2
- package/lib/shared/options.d.ts +2 -2
- package/package.json +2 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ComputedRef } from 'vue';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AutoLinkOptions } from '../../shared/index.js';
|
|
3
3
|
interface RelatedLinks {
|
|
4
|
-
prevLink: ComputedRef<
|
|
5
|
-
nextLink: ComputedRef<
|
|
4
|
+
prevLink: ComputedRef<AutoLinkOptions | null>;
|
|
5
|
+
nextLink: ComputedRef<AutoLinkOptions | null>;
|
|
6
6
|
}
|
|
7
7
|
export declare const useRelatedLinks: () => RelatedLinks;
|
|
8
8
|
export {};
|
|
@@ -1,42 +1,41 @@
|
|
|
1
1
|
import { useSidebarItems } from '@theme/useSidebarItems';
|
|
2
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
2
3
|
import { computed } from 'vue';
|
|
3
4
|
import { resolveRoute, usePageFrontmatter, useRoute } from 'vuepress/client';
|
|
4
5
|
import { isPlainObject, isString } from 'vuepress/shared';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (conf === false) {
|
|
10
|
-
return null;
|
|
6
|
+
import { getAutoLink } from '../utils/index.js';
|
|
7
|
+
const resolveFromFrontmatterConfig = (config, currentPath) => {
|
|
8
|
+
if (config === false) {
|
|
9
|
+
return false;
|
|
11
10
|
}
|
|
12
|
-
if (isString(
|
|
13
|
-
|
|
14
|
-
return notFound
|
|
15
|
-
? { text: path, link: path }
|
|
16
|
-
: {
|
|
17
|
-
text: meta.title || path,
|
|
18
|
-
link: path,
|
|
19
|
-
};
|
|
11
|
+
if (isString(config)) {
|
|
12
|
+
return getAutoLink(config, currentPath);
|
|
20
13
|
}
|
|
21
|
-
if (isPlainObject(
|
|
14
|
+
if (isPlainObject(config)) {
|
|
22
15
|
return {
|
|
23
|
-
...
|
|
24
|
-
link:
|
|
16
|
+
...config,
|
|
17
|
+
link: getAutoLink(config.link, currentPath).link,
|
|
25
18
|
};
|
|
26
19
|
}
|
|
27
|
-
return
|
|
20
|
+
return null;
|
|
28
21
|
};
|
|
29
22
|
/**
|
|
30
23
|
* Resolve `prev` or `next` config from sidebar items
|
|
31
24
|
*/
|
|
32
25
|
const resolveFromSidebarItems = (sidebarItems, currentPath, offset) => {
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
const targetItem = sidebarItems[
|
|
36
|
-
if (!targetItem
|
|
26
|
+
const linkIndex = sidebarItems.findIndex((item) => item.link === currentPath);
|
|
27
|
+
if (linkIndex !== -1) {
|
|
28
|
+
const targetItem = sidebarItems[linkIndex + offset];
|
|
29
|
+
if (!targetItem)
|
|
37
30
|
return null;
|
|
38
|
-
|
|
39
|
-
|
|
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;
|
|
40
39
|
}
|
|
41
40
|
for (const item of sidebarItems) {
|
|
42
41
|
if ('children' in item) {
|
|
@@ -46,25 +45,44 @@ const resolveFromSidebarItems = (sidebarItems, currentPath, offset) => {
|
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
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
|
+
}
|
|
49
62
|
return null;
|
|
50
63
|
};
|
|
51
64
|
export const useRelatedLinks = () => {
|
|
52
65
|
const frontmatter = usePageFrontmatter();
|
|
66
|
+
const themeLocale = useThemeLocaleData();
|
|
53
67
|
const sidebarItems = useSidebarItems();
|
|
54
68
|
const route = useRoute();
|
|
55
69
|
const prevLink = computed(() => {
|
|
56
70
|
const prevConfig = resolveFromFrontmatterConfig(frontmatter.value.prev, route.path);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
return prevConfig === false
|
|
72
|
+
? null
|
|
73
|
+
: prevConfig ??
|
|
74
|
+
(themeLocale.value.prev === false
|
|
75
|
+
? null
|
|
76
|
+
: resolveFromSidebarItems(sidebarItems.value, route.path, -1));
|
|
61
77
|
});
|
|
62
78
|
const nextLink = computed(() => {
|
|
63
79
|
const nextConfig = resolveFromFrontmatterConfig(frontmatter.value.next, route.path);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
80
|
+
return nextConfig === false
|
|
81
|
+
? null
|
|
82
|
+
: nextConfig ??
|
|
83
|
+
(themeLocale.value.next === false
|
|
84
|
+
? null
|
|
85
|
+
: resolveFromSidebarItems(sidebarItems.value, route.path, 1));
|
|
68
86
|
});
|
|
69
87
|
return {
|
|
70
88
|
prevLink,
|
package/lib/client/config.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { setupDarkMode } from '@theme/useDarkMode';
|
|
2
|
+
import { useScrollPromise } from '@theme/useScrollPromise';
|
|
3
|
+
import { setupSidebarItems } from '@theme/useSidebarItems';
|
|
1
4
|
import { hasGlobalComponent } from '@vuepress/helper/client';
|
|
2
5
|
import { h } from 'vue';
|
|
3
6
|
import { defineClientConfig } from 'vuepress/client';
|
|
4
7
|
import { Badge, CodeGroup, CodeGroupItem } from './components/global/index.js';
|
|
5
|
-
import { setupDarkMode, setupSidebarItems, useScrollPromise, } from './composables/index.js';
|
|
6
8
|
import Layout from './layouts/Layout.vue';
|
|
7
9
|
import NotFound from './layouts/NotFound.vue';
|
|
8
10
|
import '@vuepress/helper/normalize.css';
|
|
@@ -6,4 +6,4 @@ import type { AutoLinkOptions } from '../../shared';
|
|
|
6
6
|
* - Input: '/README.md'
|
|
7
7
|
* - Output: { text: 'Home', link: '/' }
|
|
8
8
|
*/
|
|
9
|
-
export declare const getAutoLink: (config: string) => AutoLinkOptions;
|
|
9
|
+
export declare const getAutoLink: (config: string, currentPath?: string) => AutoLinkOptions;
|
|
@@ -6,8 +6,8 @@ import { resolveRoute } from 'vuepress/client';
|
|
|
6
6
|
* - Input: '/README.md'
|
|
7
7
|
* - Output: { text: 'Home', link: '/' }
|
|
8
8
|
*/
|
|
9
|
-
export const getAutoLink = (config) => {
|
|
10
|
-
const { notFound, meta, path } = resolveRoute(config);
|
|
9
|
+
export const getAutoLink = (config, currentPath) => {
|
|
10
|
+
const { notFound, meta, path } = resolveRoute(config, currentPath);
|
|
11
11
|
return notFound
|
|
12
12
|
? { text: path, link: path }
|
|
13
13
|
: {
|
package/lib/shared/options.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/theme-default",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.35",
|
|
4
4
|
"description": "Default theme of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress-theme",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"publishConfig": {
|
|
73
73
|
"access": "public"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "4d18f77ca965e0735fa2c09c73ddbc6e5b16fabc"
|
|
76
76
|
}
|