@rspress/core 0.0.9 → 0.0.11

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.
Files changed (42) hide show
  1. package/dist/index.d.ts +1 -10
  2. package/dist/index.js +237 -264
  3. package/dist/index.js.map +1 -1
  4. package/dist/loader.d.ts +1 -1
  5. package/dist/loader.js +0 -3
  6. package/dist/loader.js.map +1 -1
  7. package/dist/theme/bundle.css +96 -159
  8. package/dist/theme/bundle.d.ts +1 -1
  9. package/dist/theme/bundle.js +879 -802
  10. package/dist/theme/bundle.js.map +1 -1
  11. package/package.json +15 -15
  12. package/src/theme-default/components/Aside/index.css +23 -0
  13. package/src/theme-default/components/Aside/index.tsx +7 -13
  14. package/src/theme-default/components/EditLink/index.module.scss +3 -3
  15. package/src/theme-default/components/EditLink/index.tsx +0 -5
  16. package/src/theme-default/components/HomeHero/index.module.scss +6 -0
  17. package/src/theme-default/components/HomeHero/index.tsx +4 -4
  18. package/src/theme-default/components/Nav/NavMenuGroup.tsx +43 -23
  19. package/src/theme-default/components/Nav/NavMenuSingleItem.tsx +12 -4
  20. package/src/theme-default/components/Nav/index.module.scss +0 -1
  21. package/src/theme-default/components/Nav/index.tsx +4 -3
  22. package/src/theme-default/components/NavScreenMenuGroup/NavScreenMenuGroup.tsx +18 -7
  23. package/src/theme-default/components/Search/logic/providers/LocalProvider.ts +1 -2
  24. package/src/theme-default/components/Sidebar/SidebarGroup.tsx +180 -0
  25. package/src/theme-default/components/Sidebar/SidebarItem.tsx +61 -0
  26. package/src/theme-default/components/Sidebar/index.module.scss +22 -5
  27. package/src/theme-default/components/Sidebar/index.tsx +39 -248
  28. package/src/theme-default/components/Tabs/index.module.scss +11 -18
  29. package/src/theme-default/components/Tabs/index.tsx +1 -1
  30. package/src/theme-default/layout/DocLayout/index.module.scss +17 -18
  31. package/src/theme-default/layout/Layout/index.tsx +19 -7
  32. package/src/theme-default/logic/sideEffects.ts +3 -1
  33. package/src/theme-default/logic/useEditLink.ts +6 -3
  34. package/src/theme-default/logic/useLocaleSiteData.ts +1 -1
  35. package/src/theme-default/logic/useSidebarData.ts +1 -1
  36. package/src/theme-default/styles/{doc/code.css → code.css} +4 -1
  37. package/src/theme-default/styles/index.ts +1 -3
  38. package/src/theme-default/styles/vars.css +2 -2
  39. package/src/theme-default/assets/edit.svg +0 -1
  40. package/src/theme-default/styles/doc/container.css +0 -103
  41. package/src/theme-default/styles/doc/index.css +0 -6
  42. /package/dist/theme/{index.ts → index.js} +0 -0
@@ -0,0 +1,61 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { Link } from '../Link';
3
+ import { Tag } from '../Tag';
4
+ import styles from './index.module.scss';
5
+ import { SidebarGroup } from './SidebarGroup';
6
+ import { SidebarItemProps, highlightTitleStyle } from '.';
7
+ import { normalizeHref } from '@/runtime';
8
+
9
+ export function SidebarItem(props: SidebarItemProps) {
10
+ const { item, depth = 0, activeMatcher, id, setSidebarData } = props;
11
+ const active = item.link && activeMatcher(item.link);
12
+
13
+ const ref = useRef<HTMLDivElement>(null);
14
+ useEffect(() => {
15
+ if (active) {
16
+ ref.current?.scrollIntoView({
17
+ block: 'center',
18
+ });
19
+ }
20
+ }, []);
21
+
22
+ const { text } = item;
23
+
24
+ if ('items' in item) {
25
+ return (
26
+ <SidebarGroup
27
+ id={id}
28
+ key={`${item.text}-${id}`}
29
+ item={item}
30
+ depth={depth}
31
+ activeMatcher={activeMatcher}
32
+ collapsed={item.collapsed}
33
+ setSidebarData={setSidebarData}
34
+ preloadLink={props.preloadLink}
35
+ />
36
+ );
37
+ } else {
38
+ return (
39
+ <Link href={normalizeHref(item.link)} className={styles.menuLink}>
40
+ <div
41
+ ref={ref}
42
+ onMouseEnter={() => props.preloadLink(item.link)}
43
+ className={`${
44
+ active ? styles.menuItemActive : styles.menuItem
45
+ } mt-0.5 py-2 px-3 font-medium flex`}
46
+ style={{
47
+ // The first level menu item will have the same font size as the sidebar group
48
+ fontSize: depth === 0 ? '14px' : '13px',
49
+ marginLeft: depth === 0 ? 0 : '18px',
50
+ borderRadius: '0 1rem 1rem 0',
51
+ ...(depth === 0 ? highlightTitleStyle : {}),
52
+ ...(active ? { color: 'var(--rp-c-brand)' } : {}),
53
+ }}
54
+ >
55
+ <Tag tag={item.tag} />
56
+ {text}
57
+ </div>
58
+ </Link>
59
+ );
60
+ }
61
+ }
@@ -4,7 +4,7 @@
4
4
  bottom: 0;
5
5
  left: 0;
6
6
  z-index: var(--rp-z-index-sidebar);
7
- padding: 12px 12px 96px 16px;
7
+ padding: 12px 12px 96px 0;
8
8
  width: calc(100vw - 64px);
9
9
  max-width: 320px;
10
10
  background-color: var(--rp-c-bg);
@@ -46,9 +46,8 @@
46
46
 
47
47
  @media (min-width: 1440px) {
48
48
  .sidebar {
49
- padding-left: 16px;
49
+ padding-left: 0;
50
50
  width: var(--rp-sidebar-width);
51
- margin-left: calc((100vw - 1440px) / 2);
52
51
  }
53
52
  }
54
53
 
@@ -82,18 +81,36 @@
82
81
  .menuItemActive {
83
82
  font-size: 13px;
84
83
  line-height: 19px;
84
+ border-radius: 0 1rem 1rem 0;
85
85
  }
86
86
 
87
87
  .menuItem,
88
88
  .menuItemStatic {
89
89
  color: var(--rp-c-text-2);
90
- transition: all 0.2s;
90
+ transition: color 0.2s;
91
+ font-weight: 500;
91
92
  }
92
93
 
93
94
  .menuItemActive {
94
95
  background-color: var(--rp-c-brand-tint);
95
96
  color: var(--rp-c-brand);
96
97
  font-weight: bolder;
98
+ position: relative;
99
+ }
100
+
101
+ .menuItemActive::before {
102
+ content: '';
103
+ position: absolute;
104
+ top: 0;
105
+ left: 0;
106
+ width: 1px;
107
+ height: 100%;
108
+ background-color: var(--rp-c-brand);
109
+ transition: all 0.2s ease;
110
+ }
111
+
112
+ .menuGroupActive {
113
+ background-color: var(--rp-c-bg-mute);
97
114
  }
98
115
 
99
116
  :global(.rspress-sidebar-group) {
@@ -102,7 +119,7 @@
102
119
  content: '';
103
120
  position: absolute;
104
121
  top: 0;
105
- left: 12px;
122
+ left: 18px;
106
123
  width: 1px;
107
124
  height: 100%;
108
125
  background-color: var(--rp-c-gray-light-4);
@@ -1,255 +1,45 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
- import { NormalizedSidebarGroup, SidebarItem } from '@rspress/shared';
3
- import { matchRoutes, useNavigate } from 'react-router-dom';
1
+ import React, { useEffect, useState } from 'react';
2
+ import {
3
+ NormalizedSidebarGroup,
4
+ SidebarItem as ISidebarItem,
5
+ } from '@rspress/shared';
6
+ import { matchRoutes } from 'react-router-dom';
4
7
  import { routes } from 'virtual-routes';
5
- import { Link } from '../Link';
6
8
  import { isActive } from '../../logic';
7
- import ArrowRight from '../../assets/arrow-right.svg';
8
- import { Tag } from '../Tag';
9
9
  import styles from './index.module.scss';
10
- import { removeBase, normalizeHref, withBase, usePageData } from '@/runtime';
10
+ import { SidebarItem } from './SidebarItem';
11
+ import { removeBase, usePageData } from '@/runtime';
11
12
 
12
- interface Props {
13
- isSidebarOpen?: boolean;
14
- pathname: string;
15
- langRoutePrefix: string;
16
- sidebarData: (NormalizedSidebarGroup | SidebarItem)[];
17
- }
18
-
19
- const highlightTitleStyle = {
20
- color: 'var(--rp-c-text-1)',
21
- fontSize: '14px',
22
- };
23
-
24
- interface SidebarItemProps {
13
+ export interface SidebarItemProps {
25
14
  id: string;
26
- item: SidebarItem | NormalizedSidebarGroup;
15
+ item: ISidebarItem | NormalizedSidebarGroup;
27
16
  depth: number;
28
17
  activeMatcher: (link: string) => boolean;
29
18
  collapsed?: boolean;
30
19
  setSidebarData: React.Dispatch<
31
- React.SetStateAction<(NormalizedSidebarGroup | SidebarItem)[]>
20
+ React.SetStateAction<(NormalizedSidebarGroup | ISidebarItem)[]>
32
21
  >;
33
22
  preloadLink: (link: string) => void;
34
23
  }
35
24
 
36
- export function SidebarItemComp(props: SidebarItemProps) {
37
- const { item, depth = 0, activeMatcher, id, setSidebarData } = props;
38
- const active = item.link && activeMatcher(item.link);
39
-
40
- const ref = useRef<HTMLDivElement>(null);
41
- useEffect(() => {
42
- if (active) {
43
- ref.current?.scrollIntoView({
44
- block: 'center',
45
- });
46
- }
47
- }, []);
48
-
49
- const { text } = item;
50
-
51
- if ('items' in item) {
52
- return (
53
- <SidebarGroupComp
54
- id={id}
55
- key={`${item.text}-${id}`}
56
- item={item}
57
- depth={depth}
58
- activeMatcher={activeMatcher}
59
- collapsed={item.collapsed}
60
- setSidebarData={setSidebarData}
61
- preloadLink={props.preloadLink}
62
- />
63
- );
64
- } else {
65
- return (
66
- <Link href={normalizeHref(item.link)} className={styles.menuLink}>
67
- <div
68
- ref={ref}
69
- onMouseEnter={() => props.preloadLink(item.link)}
70
- className={`${
71
- active ? styles.menuItemActive : styles.menuItem
72
- } mt-1 py-1.5 px-2 rounded-xl font-medium flex`}
73
- style={{
74
- // The first level menu item will have the same font size as the sidebar group
75
- fontSize: depth === 0 ? '14px' : '13px',
76
- marginLeft: depth === 0 ? 0 : '20px',
77
- ...(depth === 0 ? highlightTitleStyle : {}),
78
- }}
79
- >
80
- <Tag tag={item.tag} />
81
- {text}
82
- </div>
83
- </Link>
84
- );
85
- }
25
+ interface Props {
26
+ isSidebarOpen?: boolean;
27
+ pathname: string;
28
+ langRoutePrefix: string;
29
+ sidebarData: (NormalizedSidebarGroup | ISidebarItem)[];
86
30
  }
87
31
 
88
- export function SidebarGroupComp(props: SidebarItemProps) {
89
- const { item, depth = 0, activeMatcher, id, setSidebarData } = props;
90
- const navigate = useNavigate();
91
- const containerRef = useRef<HTMLDivElement>(null);
92
- const transitionRef = useRef<any>(null);
93
- const innerRef = useRef<HTMLDivElement>(null);
94
- const initialRender = useRef(true);
95
- const initialState = useRef((item as NormalizedSidebarGroup).collapsed);
96
- const active = item.link && activeMatcher(item.link);
97
- const { collapsed, collapsible = true } = item as NormalizedSidebarGroup;
98
- const collapsibleIcon = (
99
- <div
100
- style={{
101
- cursor: 'pointer',
102
- transition: 'transform 0.2s ease-out',
103
- transform: collapsed ? 'rotate(0deg)' : 'rotate(90deg)',
104
- }}
105
- >
106
- <ArrowRight />
107
- </div>
108
- );
109
-
110
- useEffect(() => {
111
- if (initialRender.current) {
112
- return;
113
- }
114
-
115
- if (!containerRef.current || !innerRef.current) {
116
- return;
117
- }
118
-
119
- if (transitionRef.current) {
120
- clearTimeout(transitionRef.current);
121
- }
122
-
123
- const container = containerRef.current;
124
- const inner = innerRef.current;
125
- // We should add the margin-top(4px) of first item in list, which is a part of the height of the container
126
- const contentHeight = inner.clientHeight + 4;
127
- if (collapsed) {
128
- container.style.maxHeight = `${contentHeight}px`;
129
- container.style.transitionDuration = '0.5s';
130
- inner.style.opacity = '0';
131
-
132
- transitionRef.current = setTimeout(() => {
133
- if (containerRef.current) {
134
- containerRef.current.style.maxHeight = '0px';
135
- }
136
- }, 0);
137
- } else {
138
- container.style.maxHeight = `${contentHeight}px`;
139
- container.style.transitionDuration = '0.3s';
140
- inner.style.opacity = '1';
141
-
142
- transitionRef.current = setTimeout(() => {
143
- if (containerRef.current) {
144
- containerRef.current.style.removeProperty('max-height');
145
- }
146
- }, 300);
147
- }
148
- }, [collapsed]);
149
-
150
- useEffect(() => {
151
- initialRender.current = false;
152
- }, []);
32
+ export const highlightTitleStyle = {
33
+ color: 'var(--rp-c-text-1)',
34
+ fontSize: '14px',
35
+ paddingLeft: '24px',
36
+ fontWeight: 'bold',
37
+ };
153
38
 
154
- const toggleCollapse: React.MouseEventHandler<HTMLDivElement> = (e): void => {
155
- e.stopPropagation();
156
- // update collapsed state
157
- setSidebarData(sidebarData => {
158
- const newSidebarData = [...sidebarData];
159
- const indexes = id.split('-').map(Number);
160
- const initialIndex = indexes.shift()!;
161
- const root = newSidebarData[initialIndex];
162
- let current = root;
163
- for (const index of indexes) {
164
- current = (current as NormalizedSidebarGroup).items[index];
165
- }
166
- if ('items' in current) {
167
- current.collapsed = !current.collapsed;
168
- }
169
- return newSidebarData;
170
- });
171
- };
172
-
173
- return (
174
- <section
175
- key={id}
176
- className="mt-1 block"
177
- style={{
178
- marginLeft: depth === 0 ? 0 : '20px',
179
- }}
180
- >
181
- <div
182
- style={{
183
- cursor: collapsible || item.link ? 'pointer' : 'normal',
184
- }}
185
- className={`flex justify-between items-center rounded-xl ${
186
- // eslint-disable-next-line no-nested-ternary
187
- active
188
- ? styles.menuItemActive
189
- : collapsible || item.link
190
- ? styles.menuItem
191
- : styles.menuItemStatic
192
- }`}
193
- onMouseEnter={() => item.link && props.preloadLink(item.link)}
194
- onClick={e => {
195
- if (item.link) {
196
- navigate(withBase(normalizeHref(item.link)));
197
- collapsed && toggleCollapse(e);
198
- } else {
199
- collapsible && toggleCollapse(e);
200
- }
201
- }}
202
- >
203
- <h2
204
- className="py-1 px-2 text-sm font-medium flex"
205
- style={{
206
- ...(depth === 0 ? highlightTitleStyle : {}),
207
- }}
208
- >
209
- <Tag tag={item.tag} />
210
- {item.text}
211
- </h2>
212
- {collapsible && (
213
- <div
214
- className={`${styles.collapseContainer} p-2 rounded-xl`}
215
- onClick={toggleCollapse}
216
- >
217
- {collapsibleIcon}
218
- </div>
219
- )}
220
- </div>
221
- <div
222
- ref={containerRef}
223
- className="transition-all duration-300 ease-in-out"
224
- style={{
225
- overflow: 'hidden',
226
- maxHeight: initialState.current ? 0 : undefined,
227
- }}
228
- >
229
- <div
230
- ref={innerRef}
231
- className="rspress-sidebar-group transition-opacity duration-500 ease-in-out"
232
- style={{
233
- opacity: initialState.current ? 0 : 1,
234
- }}
235
- >
236
- {(item as NormalizedSidebarGroup)?.items?.map((item, index) => (
237
- // eslint-disable-next-line react/no-array-index-key
238
- <div key={index}>
239
- <SidebarItemComp
240
- {...props}
241
- item={item}
242
- depth={depth + 1}
243
- id={`${id}-${index}`}
244
- preloadLink={props.preloadLink}
245
- />
246
- </div>
247
- ))}
248
- </div>
249
- </div>
250
- </section>
251
- );
252
- }
39
+ // Note: the cache object won't be reassign in other module
40
+ // eslint-disable-next-line import/no-mutable-exports
41
+ export let matchCache: WeakMap<NormalizedSidebarGroup | ISidebarItem, boolean> =
42
+ new WeakMap();
253
43
 
254
44
  export function SideBar(props: Props) {
255
45
  const {
@@ -265,18 +55,18 @@ export function SideBar(props: Props) {
265
55
  const hideNavbar =
266
56
  frontmatter?.hideNavbar ?? themeConfig?.hideNavbar ?? false;
267
57
  const [sidebarData, setSidebarData] = useState<
268
- (SidebarItem | NormalizedSidebarGroup)[]
58
+ (ISidebarItem | NormalizedSidebarGroup)[]
269
59
  >(rawSidebarData.filter(Boolean).flat());
270
60
  const pathname = decodeURIComponent(rawPathname);
271
61
  useEffect(() => {
62
+ if (props.sidebarData === sidebarData) {
63
+ return;
64
+ }
272
65
  // 1. Update sidebarData when pathname changes
273
66
  // 2. For current active item, expand its parent group
274
67
  // Cache, Avoid redundant calculation
275
- const matchCache = new WeakMap<
276
- NormalizedSidebarGroup | SidebarItem,
277
- boolean
278
- >();
279
- const match = (item: NormalizedSidebarGroup | SidebarItem) => {
68
+ matchCache = new WeakMap<NormalizedSidebarGroup | ISidebarItem, boolean>();
69
+ const match = (item: NormalizedSidebarGroup | ISidebarItem) => {
280
70
  if (matchCache.has(item)) {
281
71
  return matchCache.get(item);
282
72
  }
@@ -294,7 +84,7 @@ export function SideBar(props: Props) {
294
84
  matchCache.set(item, false);
295
85
  return false;
296
86
  };
297
- const traverse = (item: NormalizedSidebarGroup | SidebarItem) => {
87
+ const traverse = (item: NormalizedSidebarGroup | ISidebarItem) => {
298
88
  if ('items' in item) {
299
89
  item.items.forEach(traverse);
300
90
  if (match(item)) {
@@ -302,8 +92,9 @@ export function SideBar(props: Props) {
302
92
  }
303
93
  }
304
94
  };
305
- sidebarData.forEach(traverse);
306
- setSidebarData(rawSidebarData.filter(Boolean).flat());
95
+ const newSidebarData = props.sidebarData.filter(Boolean).flat();
96
+ newSidebarData.forEach(traverse);
97
+ setSidebarData(newSidebarData);
307
98
  }, [props.sidebarData, pathname]);
308
99
 
309
100
  const removeLangPrefix = (path: string) => {
@@ -339,10 +130,10 @@ export function SideBar(props: Props) {
339
130
  overflow: 'scroll',
340
131
  }}
341
132
  >
342
- <nav className="pb-6">
133
+ <nav className="pb-2">
343
134
  {sidebarData.map(
344
- (item: NormalizedSidebarGroup | SidebarItem, index: number) => (
345
- <SidebarItemComp
135
+ (item: NormalizedSidebarGroup | ISidebarItem, index: number) => (
136
+ <SidebarItem
346
137
  id={String(index)}
347
138
  item={item}
348
139
  depth={0}
@@ -1,10 +1,14 @@
1
1
  .container {
2
- border: 1px solid var(--rp-c-gray-light-3);
3
- border-radius: 8px;
4
- }
2
+ background-color: var(--rp-code-block-bg);
3
+ contain: content;
4
+ border-radius: 16px;
5
5
 
6
- :global(.dark) .container {
7
- border-color: var(--rp-c-dark-light-1);
6
+ :global(div[class*='language-']) {
7
+ margin: 6px 0;
8
+ code {
9
+ background-color: var(--rp-c-bg);
10
+ }
11
+ }
8
12
  }
9
13
 
10
14
  .tab-list {
@@ -12,12 +16,7 @@
12
16
  padding-top: 4px;
13
17
  display: flex;
14
18
  min-width: 100%;
15
- border-bottom-width: 1px;
16
- border-color: var(--rp-c-gray-light-3);
17
- }
18
-
19
- :global(.dark) .tab-list {
20
- border-color: var(--rp-c-dark-light-1);
19
+ background-color: var(--rp-code-title-bg);
21
20
  }
22
21
 
23
22
  .tab {
@@ -25,7 +24,7 @@
25
24
  border-bottom: 1px solid transparent;
26
25
  box-sizing: border-box;
27
26
  margin-right: 10px;
28
- padding: 6px 8px;
27
+ padding: 6px 12px;
29
28
  margin-bottom: -1px;
30
29
  user-select: none;
31
30
  transition: all 0.2s ease-in-out;
@@ -38,12 +37,6 @@
38
37
  .not-selected:hover {
39
38
  color: var(--rp-c-text-1);
40
39
  border-color: var(--rp-c-gray);
41
- border-top-left-radius: 10px;
42
- border-top-right-radius: 10px;
43
- background-color: var(--rp-c-gray-light-5);
44
- :global(.dark) & {
45
- background-color: var(--rp-c-dark-light-3);
46
- }
47
40
  }
48
41
 
49
42
  .selected {
@@ -10,7 +10,7 @@ import styles from './index.module.scss';
10
10
 
11
11
  type TabItem = {
12
12
  value?: string;
13
- label?: string;
13
+ label?: string | ReactNode;
14
14
  disabled?: boolean;
15
15
  };
16
16
 
@@ -32,7 +32,7 @@
32
32
  .content {
33
33
  margin-left: var(--rp-sidebar-width);
34
34
  width: calc(100% - var(--rp-sidebar-width));
35
- padding: 48px 48px 72px 48px;
35
+ padding: 48px 48px 72px 0;
36
36
 
37
37
  :global(.rspress-doc) {
38
38
  width: 100%;
@@ -45,41 +45,40 @@
45
45
  }
46
46
 
47
47
  @media (min-width: 1280px) {
48
- .docLayout {
49
- width: calc(1280px - 100vw + 100%);
50
- margin-left: calc((100vw - 1280px) / 2);
51
- }
52
-
53
48
  .aside-container {
54
49
  display: block;
55
50
  width: var(--rp-aside-width);
56
51
  }
57
52
 
58
53
  .content {
59
- margin-left: var(--rp-sidebar-width);
60
- width: calc(100% - var(--rp-sidebar-width));
61
54
  padding: 48px 0 72px 0;
62
-
63
55
  :global(.rspress-doc) {
64
- width: calc(1280px - var(--rp-sidebar-width) - var(--rp-aside-width));
56
+ padding: 0 48px;
57
+ box-sizing: content-box;
58
+ width: calc(100vw - var(--rp-aside-width) - var(--rp-sidebar-width));
65
59
  }
66
60
  }
67
61
  }
68
62
 
69
63
  @media (min-width: 1440px) {
70
64
  .docLayout {
71
- width: calc(1440px - 100vw + 100%);
72
- margin-left: calc((100vw - 1440px) / 2);
65
+ width: 100%;
66
+ margin-left: 0;
73
67
  }
74
68
 
75
69
  .content {
76
- padding: 48px 0 72px 64px;
77
-
78
70
  :global(.rspress-doc) {
79
- padding-right: 64px;
80
- width: calc(
81
- 1440px - var(--rp-sidebar-width) - var(--rp-aside-width) - 64px
82
- );
71
+ box-sizing: content-box;
72
+ width: calc(100vw - var(--rp-sidebar-width) - var(--rp-aside-width));
73
+ padding: 0
74
+ max(
75
+ 48px,
76
+ calc(
77
+ (100vw - var(--rp-sidebar-width) - var(--rp-aside-width) - 960px) /
78
+ 2
79
+ )
80
+ );
81
+ max-width: 960px;
83
82
  }
84
83
  }
85
84
  }
@@ -48,9 +48,10 @@ export const Layout: React.FC<LayoutProps> = props => {
48
48
  } = page;
49
49
  const localesData = useLocaleSiteData();
50
50
  const defaultLang = siteData.lang || '';
51
+ // Priority: frontmatter.navbar > themeConfig.hideNavbar
52
+ // Always show sidebar by default
51
53
  const hideNavbar =
52
- frontmatter?.hideNavbar ?? themeConfig?.hideNavbar ?? false;
53
-
54
+ !(frontmatter?.navbar ?? true) || (themeConfig?.hideNavbar ?? false);
54
55
  // Priority: front matter title > h1 title
55
56
  let title = (frontmatter?.title as string) ?? articleTitle;
56
57
  const mainTitle = siteData.title || localesData.title;
@@ -141,11 +142,22 @@ export const Layout: React.FC<LayoutProps> = props => {
141
142
  {bottom}
142
143
  {
143
144
  // Global UI
144
- globalComponents.map((Component, index) => (
145
- // The component order is stable
146
- // eslint-disable-next-line react/no-array-index-key
147
- <Component key={index} />
148
- ))
145
+ globalComponents.map((componentInfo, index) => {
146
+ if (Array.isArray(componentInfo)) {
147
+ const [component, props] = componentInfo;
148
+ return React.createElement(component, {
149
+ // The component order is stable
150
+ // eslint-disable-next-line react/no-array-index-key
151
+ key: index,
152
+ ...props,
153
+ });
154
+ } else {
155
+ return React.createElement(componentInfo, {
156
+ // eslint-disable-next-line react/no-array-index-key
157
+ key: index,
158
+ });
159
+ }
160
+ })
149
161
  }
150
162
  </div>
151
163
  );
@@ -104,7 +104,9 @@ export function bindingAsideScroll() {
104
104
  const activate = (links: HTMLAnchorElement[], index: number) => {
105
105
  if (links[index]) {
106
106
  const id = links[index].getAttribute('href');
107
- const currentLink = aside?.querySelector(`a[href="#${id?.slice(1)}"]`);
107
+ const currentLink = aside?.querySelector(
108
+ `a[href="#${id?.slice(1)}"] > span`,
109
+ );
108
110
  if (currentLink) {
109
111
  if (prevActiveLink) {
110
112
  prevActiveLink.classList.remove('aside-active');
@@ -1,3 +1,4 @@
1
+ import { useLocaleSiteData } from './useLocaleSiteData';
1
2
  import { usePageData } from '@/runtime';
2
3
 
3
4
  interface EditLink {
@@ -6,9 +7,11 @@ interface EditLink {
6
7
  }
7
8
 
8
9
  export function useEditLink() {
9
- const pageData = usePageData();
10
+ const { siteData, page } = usePageData();
11
+ const locales = useLocaleSiteData();
10
12
 
11
- const editLink: EditLink = pageData.siteData.themeConfig?.editLink ?? {};
13
+ const editLink: EditLink =
14
+ locales.editLink ?? siteData.themeConfig?.editLink ?? {};
12
15
 
13
16
  if (!editLink.docRepoBaseUrl || !editLink.text) {
14
17
  return null;
@@ -20,7 +23,7 @@ export function useEditLink() {
20
23
  docRepoBaseUrl += '/';
21
24
  }
22
25
 
23
- const relativePagePath = pageData.page._relativePath.replace(/\\/g, '/');
26
+ const relativePagePath = page._relativePath.replace(/\\/g, '/');
24
27
  const link = `${docRepoBaseUrl}${relativePagePath}`;
25
28
 
26
29
  return {