@vuepress/theme-default 2.0.0-rc.32 → 2.0.0-rc.33

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,165 +1,27 @@
1
1
  <script setup lang="ts">
2
2
  import NavbarDropdown from '@theme/NavbarDropdown.vue'
3
- import { useRoutePaths } from '@vuepress/helper/client'
4
3
  import { computed, ref } from 'vue'
5
- import type { ComputedRef } from 'vue'
6
- import {
7
- AutoLink,
8
- useRoute,
9
- useRouteLocale,
10
- useSiteData,
11
- useSiteLocaleData,
12
- } from 'vuepress/client'
13
- import { isLinkHttp, isString } from 'vuepress/shared'
14
- import type {
15
- NavbarGroup,
16
- NavbarItem,
17
- ResolvedNavbarItem,
18
- } from '../../shared/index.js'
4
+ import { AutoLink } from 'vuepress/client'
19
5
  import {
20
6
  DeviceType,
21
- useThemeData,
7
+ useNavbarConfig,
8
+ useNavbarRepo,
9
+ useNavbarSelectLanguage,
22
10
  useThemeLocaleData,
23
11
  useUpdateDeviceStatus,
24
12
  } from '../composables/index.js'
25
- import { getAutoLink, resolveRepoType } from '../utils/index.js'
26
-
27
- /**
28
- * Get navbar config of select language dropdown
29
- */
30
- const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
31
- const route = useRoute()
32
- const routePaths = useRoutePaths()
33
- const routeLocale = useRouteLocale()
34
- const site = useSiteData()
35
- const siteLocale = useSiteLocaleData()
36
- const theme = useThemeData()
37
- const themeLocale = useThemeLocaleData()
38
-
39
- return computed<ResolvedNavbarItem[]>(() => {
40
- const localePaths = Object.keys(site.value.locales)
41
- // do not display language selection dropdown if there is only one language
42
- if (localePaths.length < 2) {
43
- return []
44
- }
45
- const currentPath = route.path
46
- const currentFullPath = route.fullPath
47
-
48
- const languageDropdown: ResolvedNavbarItem = {
49
- text: `${themeLocale.value.selectLanguageText}`,
50
- ariaLabel: `${
51
- themeLocale.value.selectLanguageAriaLabel ??
52
- themeLocale.value.selectLanguageText
53
- }`,
54
- children: localePaths.map((targetLocalePath) => {
55
- // target locale config of this language link
56
- const targetSiteLocale = site.value.locales?.[targetLocalePath] ?? {}
57
- const targetThemeLocale = theme.value.locales?.[targetLocalePath] ?? {}
58
- const targetLang = `${targetSiteLocale.lang}`
59
-
60
- const text = targetThemeLocale.selectLanguageName ?? targetLang
61
-
62
- // if the target language is current language
63
- // stay at current link
64
- if (targetLang === siteLocale.value.lang) {
65
- return {
66
- text,
67
- activeMatch: /./,
68
- link: route.hash ?? '#',
69
- }
70
- }
71
-
72
- // if the target language is not current language
73
- // try to link to the corresponding page of current page
74
- // or fallback to homepage
75
- const targetLocalePage = currentPath.replace(
76
- routeLocale.value,
77
- targetLocalePath,
78
- )
79
-
80
- return {
81
- text,
82
- // try to keep current hash and params across languages
83
- link: routePaths.value.some((item) => item === targetLocalePage)
84
- ? currentFullPath.replace(currentPath, targetLocalePage)
85
- : targetThemeLocale.home ?? targetLocalePath,
86
- }
87
- }),
88
- }
89
-
90
- return [languageDropdown]
91
- })
92
- }
93
-
94
- /**
95
- * Get navbar config of repository link
96
- */
97
- const useNavbarRepo = (): ComputedRef<ResolvedNavbarItem[]> => {
98
- const themeLocale = useThemeLocaleData()
99
-
100
- const repo = computed(() => themeLocale.value.repo)
101
- const repoType = computed(() =>
102
- repo.value ? resolveRepoType(repo.value) : null,
103
- )
104
-
105
- const repoLink = computed(() => {
106
- if (repo.value && !isLinkHttp(repo.value)) {
107
- return `https://github.com/${repo.value}`
108
- }
109
-
110
- return repo.value
111
- })
112
-
113
- const repoLabel = computed(() => {
114
- if (!repoLink.value) return null
115
- if (themeLocale.value.repoLabel) return themeLocale.value.repoLabel
116
- if (repoType.value === null) return 'Source'
117
- return repoType.value
118
- })
119
-
120
- return computed(() => {
121
- if (!repoLink.value || !repoLabel.value) {
122
- return []
123
- }
124
13
 
125
- return [
126
- {
127
- text: repoLabel.value,
128
- link: repoLink.value,
129
- },
130
- ]
131
- })
132
- }
14
+ const navbarConfig = useNavbarConfig()
15
+ const navbarSelectLanguage = useNavbarSelectLanguage()
16
+ const navbarRepo = useNavbarRepo()
133
17
 
134
- const resolveNavbarItem = (
135
- item: NavbarItem | NavbarGroup | string,
136
- ): ResolvedNavbarItem => {
137
- if (isString(item)) {
138
- return getAutoLink(item)
139
- }
140
- if ((item as NavbarGroup).children) {
141
- return {
142
- ...item,
143
- children: (item as NavbarGroup).children.map((item) =>
144
- resolveNavbarItem(item),
145
- ),
146
- }
147
- }
148
- return item as ResolvedNavbarItem
149
- }
18
+ const isMobile = ref(false)
150
19
 
151
- const useNavbarConfig = (): ComputedRef<ResolvedNavbarItem[]> => {
20
+ const navbarLabel = computed(() => {
152
21
  const themeLocale = useThemeLocaleData()
22
+ return themeLocale.value.navbarLabel ?? 'site navigation'
23
+ })
153
24
 
154
- return computed(() =>
155
- (themeLocale.value.navbar || []).map((item) => resolveNavbarItem(item)),
156
- )
157
- }
158
-
159
- const isMobile = ref(false)
160
- const navbarConfig = useNavbarConfig()
161
- const navbarSelectLanguage = useNavbarSelectLanguage()
162
- const navbarRepo = useNavbarRepo()
163
25
  const navbarLinks = computed(() => [
164
26
  ...navbarConfig.value,
165
27
  ...navbarSelectLanguage.value,
@@ -170,18 +32,9 @@ useUpdateDeviceStatus(
170
32
  DeviceType.MOBILE,
171
33
  (mobileDesktopBreakpoint: number): void => {
172
34
  // avoid overlapping of long title and long navbar links
173
- if (window.innerWidth < mobileDesktopBreakpoint) {
174
- isMobile.value = true
175
- } else {
176
- isMobile.value = false
177
- }
35
+ isMobile.value = window.innerWidth < mobileDesktopBreakpoint
178
36
  },
179
37
  )
180
-
181
- const navbarLabel = computed(() => {
182
- const themeLocale = useThemeLocaleData()
183
- return themeLocale.value.navbarLabel ?? 'site navigation'
184
- })
185
38
  </script>
186
39
 
187
40
  <template>
@@ -189,8 +42,8 @@ const navbarLabel = computed(() => {
189
42
  <div v-for="item in navbarLinks" :key="item.text" class="navbar-item">
190
43
  <NavbarDropdown
191
44
  v-if="'children' in item"
45
+ :class="{ mobile: isMobile }"
192
46
  :item="item"
193
- :class="isMobile ? 'mobile' : ''"
194
47
  />
195
48
  <AutoLink v-else :config="item" />
196
49
  </div>
@@ -1,5 +1,8 @@
1
1
  export * from './useDarkMode.js';
2
2
  export * from './useNavigate.js';
3
+ export * from './useNavbarConfig.js';
4
+ export * from './useNavbarRepo.js';
5
+ export * from './useNavbarSelectLanguage.js';
3
6
  export * from './useScrollPromise.js';
4
7
  export * from './useSidebarItems.js';
5
8
  export * from './useThemeData.js';
@@ -1,5 +1,8 @@
1
1
  export * from './useDarkMode.js';
2
2
  export * from './useNavigate.js';
3
+ export * from './useNavbarConfig.js';
4
+ export * from './useNavbarRepo.js';
5
+ export * from './useNavbarSelectLanguage.js';
3
6
  export * from './useScrollPromise.js';
4
7
  export * from './useSidebarItems.js';
5
8
  export * from './useThemeData.js';
@@ -0,0 +1,3 @@
1
+ import type { ComputedRef } from 'vue';
2
+ import type { ResolvedNavbarItem } from '../../shared/index.js';
3
+ export declare const useNavbarConfig: () => ComputedRef<ResolvedNavbarItem[]>;
@@ -0,0 +1,25 @@
1
+ import { computed } from 'vue';
2
+ import { isString } from 'vuepress/shared';
3
+ import { getAutoLink, isLinkInternal, resolvePrefix } from '../utils/index.js';
4
+ import { useThemeLocaleData } from './useThemeData.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,6 @@
1
+ import type { ComputedRef } from 'vue';
2
+ import type { ResolvedNavbarItem } from '../../shared/index.js';
3
+ /**
4
+ * Get navbar config of repository link
5
+ */
6
+ export declare const useNavbarRepo: () => ComputedRef<ResolvedNavbarItem[]>;
@@ -0,0 +1,38 @@
1
+ import { computed } from 'vue';
2
+ import { isLinkHttp } from 'vuepress/shared';
3
+ import { resolveRepoType } from '../utils/index.js';
4
+ import { useThemeLocaleData } from './useThemeData.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,6 @@
1
+ import type { ComputedRef } from 'vue';
2
+ import type { ResolvedNavbarItem } from '../../shared/index.js';
3
+ /**
4
+ * Get navbar config of select language dropdown
5
+ */
6
+ export declare const useNavbarSelectLanguage: () => ComputedRef<ResolvedNavbarItem[]>;
@@ -0,0 +1,58 @@
1
+ import { useRoutePaths } from '@vuepress/helper/client';
2
+ import { computed } from 'vue';
3
+ import { useRoute, useRouteLocale, useSiteData, useSiteLocaleData, } from 'vuepress/client';
4
+ import { useThemeData, useThemeLocaleData } from './useThemeData.js';
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,6 @@
1
1
  import type { ComputedRef, InjectionKey } from 'vue';
2
2
  import type { PageData, PageHeader } from 'vuepress/client';
3
- import type { DefaultThemeData, DefaultThemeNormalPageFrontmatter, ResolvedSidebarItem, SidebarConfigArray, SidebarConfigObject } from '../../shared/index.js';
3
+ import type { ResolvedSidebarItem, SidebarConfig, SidebarConfigArray, SidebarConfigObject } from '../../shared/index.js';
4
4
  export type SidebarItemsRef = ComputedRef<ResolvedSidebarItem[]>;
5
5
  export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
6
6
  /**
@@ -16,21 +16,21 @@ export declare const setupSidebarItems: () => void;
16
16
  *
17
17
  * It should only be resolved and provided once
18
18
  */
19
- export declare const resolveSidebarItems: (frontmatter: DefaultThemeNormalPageFrontmatter, themeLocale: DefaultThemeData, page: PageData, path: string) => ResolvedSidebarItem[];
19
+ export declare const resolveSidebarItems: (sidebarConfig: SidebarConfig | 'auto' | false, sidebarDepth: number, page: PageData, path: string, routeLocale: string) => ResolvedSidebarItem[];
20
20
  /**
21
21
  * Util to transform page header to sidebar item
22
22
  */
23
- export declare const headerToSidebarItem: (header: PageHeader, sidebarDepth: number) => ResolvedSidebarItem;
24
- export declare const headersToSidebarItemChildren: (headers: PageHeader[], sidebarDepth: number) => ResolvedSidebarItem[];
23
+ export declare const headerToSidebarItem: (sidebarDepth: number, header: PageHeader) => ResolvedSidebarItem;
24
+ export declare const headersToSidebarItemChildren: (sidebarDepth: number, headers: PageHeader[]) => ResolvedSidebarItem[];
25
25
  /**
26
26
  * Resolve sidebar items if the config is `auto`
27
27
  */
28
- export declare const resolveAutoSidebarItems: (page: PageData, sidebarDepth: number) => ResolvedSidebarItem[];
28
+ export declare const resolveAutoSidebarItems: (sidebarDepth: number, page: PageData) => ResolvedSidebarItem[];
29
29
  /**
30
30
  * Resolve sidebar items if the config is an array
31
31
  */
32
- export declare const resolveArraySidebarItems: (page: PageData, path: string, sidebarConfig: SidebarConfigArray, sidebarDepth: number) => ResolvedSidebarItem[];
32
+ export declare const resolveArraySidebarItems: (sidebarConfig: SidebarConfigArray, sidebarDepth: number, page: PageData, path: string, prefix?: string) => ResolvedSidebarItem[];
33
33
  /**
34
34
  * Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
35
35
  */
36
- export declare const resolveMultiSidebarItems: (page: PageData, path: string, sidebarConfig: SidebarConfigObject, sidebarDepth: number) => ResolvedSidebarItem[];
36
+ export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarConfigObject, sidebarDepth: number, page: PageData, path: string) => ResolvedSidebarItem[];
@@ -1,7 +1,8 @@
1
+ import { keys, startsWith } from '@vuepress/helper/client';
1
2
  import { computed, inject, provide } from 'vue';
2
- import { usePageData, usePageFrontmatter, useRoute } from 'vuepress/client';
3
- import { isPlainObject, isString, resolveLocalePath } from 'vuepress/shared';
4
- import { getAutoLink } from '../utils/index.js';
3
+ import { usePageData, usePageFrontmatter, useRoute, useRouteLocale, } from 'vuepress/client';
4
+ import { isPlainObject, isString } from 'vuepress/shared';
5
+ import { getAutoLink, isLinkInternal, resolvePrefix } from '../utils/index.js';
5
6
  import { useThemeLocaleData } from './useThemeData.js';
6
7
  export const sidebarItemsSymbol = Symbol('sidebarItems');
7
8
  /**
@@ -22,7 +23,12 @@ export const setupSidebarItems = () => {
22
23
  const frontmatter = usePageFrontmatter();
23
24
  const page = usePageData();
24
25
  const route = useRoute();
25
- const sidebarItems = computed(() => resolveSidebarItems(frontmatter.value, themeLocale.value, page.value, route.path));
26
+ const routeLocale = useRouteLocale();
27
+ const sidebarConfig = computed(() => frontmatter.value.home
28
+ ? false
29
+ : frontmatter.value.sidebar ?? themeLocale.value.sidebar ?? 'auto');
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 = (frontmatter, themeLocale, page, path) => {
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 (frontmatter.home || sidebarConfig === false) {
41
+ if (sidebarConfig === false) {
39
42
  return [];
40
43
  }
41
44
  if (sidebarConfig === 'auto') {
42
- return resolveAutoSidebarItems(page, sidebarDepth);
45
+ return resolveAutoSidebarItems(sidebarDepth, page);
43
46
  }
44
47
  if (Array.isArray(sidebarConfig)) {
45
- return resolveArraySidebarItems(page, path, sidebarConfig, sidebarDepth);
48
+ return resolveArraySidebarItems(sidebarConfig, sidebarDepth, page, path, routeLocale);
46
49
  }
47
50
  if (isPlainObject(sidebarConfig)) {
48
- return resolveMultiSidebarItems(page, path, sidebarConfig, sidebarDepth);
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 headerToSidebarItem = (header, sidebarDepth) => ({
58
+ export const headerToSidebarItem = (sidebarDepth, header) => ({
56
59
  text: header.title,
57
60
  link: header.link,
58
- children: headersToSidebarItemChildren(header.children, sidebarDepth),
61
+ children: headersToSidebarItemChildren(sidebarDepth, header.children),
59
62
  });
60
- export const headersToSidebarItemChildren = (headers, sidebarDepth) => sidebarDepth > 0
61
- ? headers.map((header) => headerToSidebarItem(header, sidebarDepth - 1))
63
+ export const headersToSidebarItemChildren = (sidebarDepth, headers) => sidebarDepth > 0
64
+ ? headers.map((header) => headerToSidebarItem(sidebarDepth - 1, header))
62
65
  : [];
63
66
  /**
64
67
  * Resolve sidebar items if the config is `auto`
65
68
  */
66
- export const resolveAutoSidebarItems = (page, sidebarDepth) => {
67
- return [
68
- {
69
- text: page.title,
70
- children: headersToSidebarItemChildren(page.headers, sidebarDepth),
71
- },
72
- ];
73
- };
69
+ export const resolveAutoSidebarItems = (sidebarDepth, page) => [
70
+ {
71
+ text: page.title,
72
+ children: headersToSidebarItemChildren(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, sidebarConfig, sidebarDepth) => {
78
- const handleChildItem = (item) => {
79
- let childItem;
80
- if (isString(item)) {
81
- childItem = getAutoLink(item);
82
- }
83
- else {
84
- childItem = item;
85
- }
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;
86
90
  if (childItem.children) {
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: headersToSidebarItemChildren(headers, sidebarDepth),
103
+ children: headersToSidebarItemChildren(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 = (page, path, sidebarConfig, sidebarDepth) => {
110
- const sidebarPath = resolveLocalePath(sidebarConfig, path);
111
- const matchedSidebarConfig = sidebarConfig[sidebarPath] ?? [];
112
- if (matchedSidebarConfig === 'heading') {
113
- return resolveAutoSidebarItems(page, sidebarDepth);
114
- }
115
- return resolveArraySidebarItems(page, path, matchedSidebarConfig, sidebarDepth);
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
+ ? resolveAutoSidebarItems(sidebarDepth, page)
122
+ : resolveArraySidebarItems(matched, sidebarDepth, page, path, base)
123
+ : [];
124
+ }
125
+ console.warn(`${decodeURI(path)} is missing sidebar config.`);
126
+ return [];
116
127
  };
@@ -1,4 +1,5 @@
1
1
  import type { ClientConfig } from 'vuepress/client';
2
+ import '@vuepress/helper/normalize.css';
2
3
  import './styles/index.scss';
3
4
  declare const _default: ClientConfig;
4
5
  export default _default;
@@ -5,6 +5,7 @@ import { Badge, CodeGroup, CodeGroupItem } from './components/global/index.js';
5
5
  import { setupDarkMode, setupSidebarItems, useScrollPromise, } from './composables/index.js';
6
6
  import Layout from './layouts/Layout.vue';
7
7
  import NotFound from './layouts/NotFound.vue';
8
+ import '@vuepress/helper/normalize.css';
8
9
  import './styles/index.scss';
9
10
  export default defineClientConfig({
10
11
  enhance({ app, router }) {
@@ -3,50 +3,23 @@
3
3
  // the original font-size is 14px, 1.7 will make line-height be 23.8px
4
4
  $line-height: 1.7;
5
5
 
6
- // ===============================
7
- // Forked and modified from prismjs/themes/prism-tomorrow.css
8
-
9
- code[class*='language-'],
10
6
  pre[class*='language-'] {
11
- color: #ccc;
12
- background: none;
13
7
  font-family: var(--font-family-code);
14
8
  font-size: 1em;
15
- text-align: left;
16
- white-space: pre;
17
- word-spacing: normal;
18
- word-break: normal;
19
- word-wrap: normal;
20
9
  line-height: 1.5;
21
10
 
22
- -moz-tab-size: 4;
23
- -o-tab-size: 4;
24
- tab-size: 4;
25
-
26
- -webkit-hyphens: none;
27
- -moz-hyphens: none;
28
- -ms-hyphens: none;
29
- hyphens: none;
30
- }
31
-
32
- /* Code blocks */
33
- pre[class*='language-'] {
34
11
  margin: 0.5em 0;
35
12
  overflow: auto;
36
13
  }
37
14
 
38
- :not(pre) > code[class*='language-'],
15
+ // ===============================
16
+ // Forked and modified from prismjs/themes/prism-tomorrow.css
17
+
39
18
  pre[class*='language-'] {
19
+ color: #ccc;
40
20
  background: #2d2d2d;
41
21
  }
42
22
 
43
- /* Inline code */
44
- :not(pre) > code[class*='language-'] {
45
- padding: 0.1em;
46
- border-radius: 0.3em;
47
- white-space: normal;
48
- }
49
-
50
23
  .token.comment,
51
24
  .token.block-comment,
52
25
  .token.prolog,
@@ -174,21 +147,6 @@ div[class*='language-'] {
174
147
  z-index: 1;
175
148
  }
176
149
 
177
- .highlight-lines {
178
- user-select: none;
179
- padding-top: 1.3rem;
180
- position: absolute;
181
- top: 0;
182
- left: 0;
183
- width: 100%;
184
- font-size: 0.875em;
185
- line-height: $line-height;
186
-
187
- .highlight-line {
188
- background-color: var(--code-hl-bg-color);
189
- }
190
- }
191
-
192
150
  &:not(.line-numbers-mode) {
193
151
  .line-numbers {
194
152
  display: none;
@@ -196,21 +154,6 @@ div[class*='language-'] {
196
154
  }
197
155
 
198
156
  &.line-numbers-mode {
199
- .highlight-lines .highlight-line {
200
- position: relative;
201
-
202
- &::before {
203
- content: ' ';
204
- position: absolute;
205
- z-index: 2;
206
- left: 0;
207
- top: 0;
208
- display: block;
209
- width: var(--code-ln-wrapper-width);
210
- height: 100%;
211
- }
212
- }
213
-
214
157
  pre {
215
158
  margin-left: var(--code-ln-wrapper-width);
216
159
  vertical-align: middle;
@@ -235,7 +178,6 @@ div[class*='language-'] {
235
178
  position: relative;
236
179
  z-index: 3;
237
180
  user-select: none;
238
- height: #{$line-height}em;
239
181
 
240
182
  &::before {
241
183
  counter-increment: line-number;
@@ -257,10 +199,28 @@ div[class*='language-'] {
257
199
  }
258
200
  }
259
201
 
202
+ // ------------ plugin-shiki code highlighting ------------
203
+ div[data-highlighter='shiki'] {
204
+ background-color: var(--shiki-light-bg, var(--code-bg-color));
205
+ transition: background-color var(--t-color);
206
+
207
+ .dark & {
208
+ background-color: var(--shiki-dark-bg, var(--code-bg-color));
209
+ }
210
+ }
211
+
212
+ .shiki span {
213
+ color: var(--shiki-light, inherit);
214
+
215
+ .dark & {
216
+ color: var(--shiki-dark, inherit);
217
+ }
218
+ }
219
+
260
220
  // ------------ code notation highlighting ------------
261
221
  // matches `<span class="line xxxx" ></span>`
262
222
 
263
- div[class*='language-'] pre {
223
+ div[class*='language-'] {
264
224
  // highlight lines and notation highlight
265
225
  //
266
226
  // `!code highlight` and `!code hl` are the same:
@@ -275,7 +235,7 @@ div[class*='language-'] pre {
275
235
  // - `// [\!code error]`
276
236
  // - `// [\!code warning:3]`
277
237
  // - `// [\!code error:3]`
278
- code .highlighted {
238
+ .line.highlighted {
279
239
  background-color: var(--code-hl-bg-color);
280
240
  transition: background-color 0.5s;
281
241
  margin: 0 -24px;
@@ -296,7 +256,7 @@ div[class*='language-'] pre {
296
256
  //
297
257
  // - class="diff add": `// [\!code ++]` or `// [\!code ++:3]`
298
258
  // - class="diff remove": `// [\!code --]` or `// [\!code --:3]`
299
- code .diff {
259
+ .line.diff {
300
260
  transition: background-color 0.5s;
301
261
  margin: 0 -24px;
302
262
  padding: 0 24px;
@@ -327,13 +287,11 @@ div[class*='language-'] pre {
327
287
  }
328
288
  }
329
289
  }
330
- }
331
290
 
332
- // notation focused lines
333
- //
334
- // - `// [\!code focus]`
335
- // - `// [\!code focus:3]`
336
- div[class*='language-'] {
291
+ // notation focused lines
292
+ //
293
+ // - `// [\!code focus]`
294
+ // - `// [\!code focus:3]`
337
295
  .has-focused-lines .line:not(.has-focus) {
338
296
  filter: blur(0.095rem);
339
297
  opacity: 0.7;
@@ -19,12 +19,6 @@
19
19
  &:hover {
20
20
  border-color: transparent;
21
21
  }
22
-
23
- .arrow {
24
- vertical-align: middle;
25
- margin-top: -1px;
26
- margin-left: 0.4rem;
27
- }
28
22
  }
29
23
 
30
24
  .navbar-dropdown-title-mobile {
@@ -1,7 +1,5 @@
1
1
  html,
2
2
  body {
3
- padding: 0;
4
- margin: 0;
5
3
  background-color: var(--c-bg);
6
4
  transition: background-color var(--t-color);
7
5
  }
@@ -10,179 +8,50 @@ html.dark {
10
8
  color-scheme: dark;
11
9
  }
12
10
 
13
- html {
14
- font-size: 16px;
15
- }
16
-
17
11
  body {
18
- font-family: var(--font-family);
19
- -webkit-font-smoothing: antialiased;
20
- -moz-osx-font-smoothing: grayscale;
21
- font-size: 1rem;
22
12
  color: var(--c-text);
13
+ font-size: 1rem;
14
+ font-family: var(--font-family);
23
15
  }
24
16
 
25
- a {
26
- font-weight: 500;
27
- color: var(--c-text-accent);
28
- text-decoration: none;
29
- overflow-wrap: break-word;
17
+ h2 {
18
+ border-color: var(--c-border);
30
19
  }
31
20
 
32
- p a code {
33
- font-weight: 400;
21
+ a {
34
22
  color: var(--c-text-accent);
35
23
  }
36
24
 
37
- kbd {
38
- font-family: var(--font-family-code);
39
- color: var(--c-text);
40
- background: var(--c-bg-lighter);
41
- border: solid 0.15rem var(--c-border-dark);
42
- border-bottom: solid 0.25rem var(--c-border-dark);
43
- border-radius: 0.15rem;
44
- padding: 0 0.15em;
45
- }
46
-
47
25
  code {
48
26
  font-family: var(--font-family-code);
49
27
  color: var(--c-text-lighter);
50
- padding: 0.25rem 0.5rem;
51
- margin: 0;
52
- font-size: 0.875em;
53
28
  background-color: var(--c-bg-light);
54
- border-radius: 3px;
55
- overflow-wrap: break-word;
56
29
  transition: background-color var(--t-color);
57
- }
58
-
59
- blockquote {
60
- font-size: 1rem;
61
- color: var(--c-text-quote);
62
- border-left: 0.2rem solid var(--c-border-dark);
63
- margin: 1rem 0;
64
- padding: 0.25rem 0 0.25rem 1rem;
65
- overflow-wrap: break-word;
66
-
67
- & > p {
68
- margin: 0;
69
- }
70
- }
71
-
72
- ul,
73
- ol {
74
- padding-left: 1.2em;
75
- }
76
-
77
- strong {
78
- font-weight: 600;
79
- }
80
-
81
- h1,
82
- h2,
83
- h3,
84
- h4,
85
- h5,
86
- h6 {
87
- font-weight: 600;
88
- line-height: 1.25;
89
- overflow-wrap: break-word;
90
-
91
- &:focus-visible {
92
- outline: none;
93
- }
94
-
95
- .header-anchor {
96
- color: inherit;
97
- text-decoration: none;
98
- position: relative;
99
-
100
- &:hover::before {
101
- font-size: 0.8em;
102
- content: '¶';
103
- position: absolute;
104
- left: -0.75em;
105
- color: var(--c-brand);
106
- }
107
30
 
108
- &:focus-visible {
109
- outline: none;
110
-
111
- &::before {
112
- content: '¶';
113
- position: absolute;
114
- left: -0.75em;
115
- color: var(--c-brand);
116
- outline: auto;
117
- }
118
- }
31
+ p a & {
32
+ color: var(--c-text-accent);
119
33
  }
120
34
  }
121
35
 
122
- h1 {
123
- font-size: 2.2rem;
124
- }
125
-
126
- h2 {
127
- font-size: 1.65rem;
128
- padding-bottom: 0.3rem;
129
- border-bottom: 1px solid var(--c-border);
130
- transition: border-color var(--t-color);
131
- }
132
-
133
- h3 {
134
- font-size: 1.35rem;
135
- }
136
-
137
- h4 {
138
- font-size: 1.15rem;
139
- }
140
-
141
- h5 {
142
- font-size: 1.05rem;
143
- }
144
-
145
- h6 {
146
- font-size: 1rem;
147
- }
148
-
149
- a {
150
- @media print {
151
- &[href^="http://"],
152
- &[href^="https://"]
153
- {
154
- &::after {
155
- content: ' (' attr(href) ') ';
156
- }
157
- }
158
- }
36
+ kbd {
37
+ border-color: var(--c-border-dark);
159
38
  }
160
39
 
161
- p,
162
- ul,
163
- ol {
164
- line-height: 1.7;
165
- overflow-wrap: break-word;
40
+ blockquote {
41
+ color: var(--c-text-quote);
42
+ border-color: var(--c-border-dark);
166
43
  }
167
44
 
168
45
  hr {
169
- border: 0;
170
- border-top: 1px solid var(--c-border);
46
+ border-color: var(--c-border);
171
47
  }
172
48
 
173
49
  table {
174
- border-collapse: collapse;
175
- margin: 1rem 0;
176
- display: block;
177
- overflow-x: auto;
178
50
  transition: border-color var(--t-color);
179
51
  }
180
52
 
181
53
  tr {
182
- border-top: 1px solid var(--c-border-dark);
183
- transition: border-color var(--t-color);
184
-
185
- &:nth-child(2n) {
54
+ &:nth-child(odd) {
186
55
  background-color: var(--c-bg-light);
187
56
  transition: background-color var(--t-color);
188
57
 
@@ -194,7 +63,6 @@ tr {
194
63
 
195
64
  th,
196
65
  td {
197
- padding: 0.6em 1em;
198
- border: 1px solid var(--c-border-dark);
66
+ border-color: var(--c-border-dark);
199
67
  transition: border-color var(--t-color);
200
68
  }
@@ -87,12 +87,6 @@
87
87
 
88
88
  &.collapsible {
89
89
  cursor: pointer;
90
-
91
- .arrow {
92
- position: relative;
93
- top: -0.12em;
94
- left: 0.5em;
95
- }
96
90
  }
97
91
 
98
92
  &:not(.sidebar-heading) {
@@ -1,4 +1,6 @@
1
1
  export * from './getNavLink.js';
2
2
  export * from './isActiveSidebarItem.js';
3
+ export * from './isLinkInternal.js';
3
4
  export * from './resolveEditLink.js';
5
+ export * from './resolvePrefix.js';
4
6
  export * from './resolveRepoType.js';
@@ -1,4 +1,6 @@
1
1
  export * from './getNavLink.js';
2
2
  export * from './isActiveSidebarItem.js';
3
+ export * from './isLinkInternal.js';
3
4
  export * from './resolveEditLink.js';
5
+ export * from './resolvePrefix.js';
4
6
  export * from './resolveRepoType.js';
@@ -0,0 +1 @@
1
+ export declare const isLinkInternal: (link: string) => boolean;
@@ -0,0 +1,2 @@
1
+ import { isLinkExternal, isLinkWithProtocol } from 'vuepress/shared';
2
+ export const isLinkInternal = (link) => !isLinkExternal(link) && !isLinkWithProtocol(link);
@@ -0,0 +1 @@
1
+ export declare const resolvePrefix: (prefix?: string, path?: string) => string;
@@ -0,0 +1,4 @@
1
+ import { ensureEndingSlash, isLinkAbsolute, isLinkWithProtocol, } from '@vuepress/helper/client';
2
+ export const resolvePrefix = (prefix = '', path = '') => isLinkAbsolute(path) || isLinkWithProtocol(path)
3
+ ? path
4
+ : `${ensureEndingSlash(prefix)}${path}`;
@@ -10,6 +10,12 @@ export interface NavItem {
10
10
  * Base nav group, has nav items children
11
11
  */
12
12
  export interface NavGroup<T> extends NavItem {
13
+ /**
14
+ * Link prefix of current group
15
+ *
16
+ * 当前分组的页面前缀
17
+ */
18
+ prefix?: string;
13
19
  children: T[];
14
20
  }
15
21
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/theme-default",
3
- "version": "2.0.0-rc.32",
3
+ "version": "2.0.0-rc.33",
4
4
  "description": "Default theme of VuePress",
5
5
  "keywords": [
6
6
  "vuepress-theme",
@@ -42,21 +42,21 @@
42
42
  "copy": "cpx \"src/**/*.{d.ts,vue,scss}\" lib"
43
43
  },
44
44
  "dependencies": {
45
- "@vuepress/helper": "~2.0.0-rc.31",
46
- "@vuepress/plugin-active-header-links": "~2.0.0-rc.31",
47
- "@vuepress/plugin-back-to-top": "~2.0.0-rc.31",
48
- "@vuepress/plugin-copy-code": "~2.0.0-rc.31",
49
- "@vuepress/plugin-git": "~2.0.0-rc.31",
50
- "@vuepress/plugin-links-check": "~2.0.0-rc.31",
51
- "@vuepress/plugin-markdown-container": "~2.0.0-rc.31",
52
- "@vuepress/plugin-medium-zoom": "~2.0.0-rc.31",
53
- "@vuepress/plugin-nprogress": "~2.0.0-rc.31",
54
- "@vuepress/plugin-palette": "~2.0.0-rc.31",
55
- "@vuepress/plugin-prismjs": "~2.0.0-rc.32",
56
- "@vuepress/plugin-seo": "~2.0.0-rc.31",
57
- "@vuepress/plugin-sitemap": "~2.0.0-rc.31",
58
- "@vuepress/plugin-theme-data": "~2.0.0-rc.31",
59
- "@vueuse/core": "^10.9.0",
45
+ "@vuepress/helper": "2.0.0-rc.33",
46
+ "@vuepress/plugin-active-header-links": "2.0.0-rc.33",
47
+ "@vuepress/plugin-back-to-top": "2.0.0-rc.33",
48
+ "@vuepress/plugin-copy-code": "2.0.0-rc.33",
49
+ "@vuepress/plugin-git": "2.0.0-rc.33",
50
+ "@vuepress/plugin-links-check": "2.0.0-rc.33",
51
+ "@vuepress/plugin-markdown-container": "2.0.0-rc.33",
52
+ "@vuepress/plugin-medium-zoom": "2.0.0-rc.33",
53
+ "@vuepress/plugin-nprogress": "2.0.0-rc.33",
54
+ "@vuepress/plugin-palette": "2.0.0-rc.33",
55
+ "@vuepress/plugin-prismjs": "2.0.0-rc.33",
56
+ "@vuepress/plugin-seo": "2.0.0-rc.33",
57
+ "@vuepress/plugin-sitemap": "2.0.0-rc.33",
58
+ "@vuepress/plugin-theme-data": "2.0.0-rc.33",
59
+ "@vueuse/core": "^10.10.0",
60
60
  "sass": "^1.77.2",
61
61
  "vue": "^3.4.27"
62
62
  },
@@ -72,5 +72,5 @@
72
72
  "publishConfig": {
73
73
  "access": "public"
74
74
  },
75
- "gitHead": "ae404292432a5ecdc0aa2d1553a7c24273a8c4c3"
75
+ "gitHead": "6e9565ef71b7eb41f8bf8736dc9f6544f1925c58"
76
76
  }