@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.
@@ -1,8 +1,8 @@
1
1
  import type { ComputedRef } from 'vue';
2
- import type { AutoLinkConfig } from 'vuepress/client';
2
+ import type { AutoLinkOptions } from '../../shared/index.js';
3
3
  interface RelatedLinks {
4
- prevLink: ComputedRef<AutoLinkConfig | null>;
5
- nextLink: ComputedRef<AutoLinkConfig | null>;
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
- * Resolve `prev` or `next` config from frontmatter
7
- */
8
- const resolveFromFrontmatterConfig = (conf, current) => {
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(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
- };
11
+ if (isString(config)) {
12
+ return getAutoLink(config, currentPath);
20
13
  }
21
- if (isPlainObject(conf)) {
14
+ if (isPlainObject(config)) {
22
15
  return {
23
- ...conf,
24
- link: resolveRoute(conf.link, current).path,
16
+ ...config,
17
+ link: getAutoLink(config.link, currentPath).link,
25
18
  };
26
19
  }
27
- return false;
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 index = sidebarItems.findIndex((item) => item.link === currentPath);
34
- if (index !== -1) {
35
- const targetItem = sidebarItems[index + offset];
36
- if (!targetItem?.link) {
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
- return targetItem;
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
- if (prevConfig !== false) {
58
- return prevConfig;
59
- }
60
- return resolveFromSidebarItems(sidebarItems.value, route.path, -1);
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
- if (nextConfig !== false) {
65
- return nextConfig;
66
- }
67
- return resolveFromSidebarItems(sidebarItems.value, route.path, 1);
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,
@@ -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
  : {
@@ -283,9 +283,9 @@ export interface DefaultThemeLocaleData extends LocaleData {
283
283
  /**
284
284
  * text for prev link
285
285
  */
286
- prev?: string;
286
+ prev?: string | false;
287
287
  /**
288
288
  * text for next link
289
289
  */
290
- next?: string;
290
+ next?: string | false;
291
291
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/theme-default",
3
- "version": "2.0.0-rc.34",
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": "93df303baa6291f52e3523f136073e79d53274ea"
75
+ "gitHead": "4d18f77ca965e0735fa2c09c73ddbc6e5b16fabc"
76
76
  }