@rspress/core 1.0.0-beta.3 → 1.0.0-beta.5
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/dist/runtime/App.js +24 -4
- package/dist/runtime/index.d.ts +2 -2
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/tsconfig.json +2 -1
- package/dist/runtime/utils.d.ts +1 -0
- package/dist/runtime/utils.js +7 -1
- package/dist/theme/bundle.css +132 -125
- package/dist/theme/bundle.d.ts +5 -2
- package/dist/theme/bundle.js +898 -910
- package/dist/theme/bundle.js.map +1 -1
- package/package.json +6 -6
- package/src/runtime/App.tsx +21 -1
- package/src/runtime/index.ts +2 -1
- package/src/runtime/tsconfig.json +2 -1
- package/src/runtime/utils.ts +9 -0
- package/src/theme-default/components/Aside/index.css +0 -1
- package/src/theme-default/components/Aside/index.tsx +7 -8
- package/src/theme-default/components/DocFooter/index.tsx +4 -1
- package/src/theme-default/components/HomeHero/index.module.scss +6 -0
- package/src/theme-default/components/HomeHero/index.tsx +8 -2
- package/src/theme-default/components/LocalSideBar/index.tsx +5 -15
- package/src/theme-default/components/Nav/NavBarTitle.tsx +42 -0
- package/src/theme-default/components/Nav/index.module.scss +18 -4
- package/src/theme-default/components/Nav/index.tsx +14 -54
- package/src/theme-default/components/NavHambmger/index.tsx +1 -3
- package/src/theme-default/components/NavScreen/index.tsx +31 -18
- package/src/theme-default/components/Sidebar/SidebarGroup.tsx +1 -1
- package/src/theme-default/components/Sidebar/index.module.scss +20 -11
- package/src/theme-default/components/Sidebar/index.tsx +25 -38
- package/src/theme-default/layout/DocLayout/index.module.scss +7 -3
- package/src/theme-default/layout/DocLayout/index.tsx +6 -19
- package/src/theme-default/layout/HomeLayout/index.tsx +1 -1
- package/src/theme-default/layout/Layout/index.tsx +3 -25
- package/src/theme-default/logic/index.ts +1 -0
- package/src/theme-default/logic/sideEffects.ts +8 -7
- package/src/theme-default/logic/useHiddenNav.ts +55 -0
- package/src/theme-default/styles/code.css +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -89,11 +89,11 @@
|
|
|
89
89
|
"unist-util-visit-children": "^2.0.1",
|
|
90
90
|
"yaml-front-matter": "^4.1.1",
|
|
91
91
|
"rspack-plugin-virtual-module": "0.1.12",
|
|
92
|
-
"@rspress/shared": "1.0.0-beta.
|
|
93
|
-
"@rspress/plugin-medium-zoom": "1.0.0-beta.
|
|
94
|
-
"@rspress/plugin-last-updated": "1.0.0-beta.
|
|
95
|
-
"@rspress/plugin-auto-nav-sidebar": "1.0.0-beta.
|
|
96
|
-
"@rspress/plugin-container-syntax": "1.0.0-beta.
|
|
92
|
+
"@rspress/shared": "1.0.0-beta.5",
|
|
93
|
+
"@rspress/plugin-medium-zoom": "1.0.0-beta.5",
|
|
94
|
+
"@rspress/plugin-last-updated": "1.0.0-beta.5",
|
|
95
|
+
"@rspress/plugin-auto-nav-sidebar": "1.0.0-beta.5",
|
|
96
|
+
"@rspress/plugin-container-syntax": "1.0.0-beta.5"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@modern-js/plugin-tailwindcss": "2.35.1",
|
package/src/runtime/App.tsx
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import siteData from 'virtual-site-data';
|
|
2
2
|
import { matchRoutes, useLocation } from 'react-router-dom';
|
|
3
3
|
import { HelmetProvider } from 'react-helmet-async';
|
|
4
|
-
import { useContext, useLayoutEffect } from 'react';
|
|
4
|
+
import React, { useContext, useLayoutEffect } from 'react';
|
|
5
5
|
import { Header, PageData, cleanUrl, isProduction } from '@rspress/shared';
|
|
6
|
+
import globalComponents from 'virtual-global-components';
|
|
6
7
|
import { isEqualPath, normalizeRoutePath } from './utils';
|
|
7
8
|
import { DataContext } from './hooks';
|
|
8
9
|
import 'virtual-global-styles';
|
|
@@ -103,6 +104,25 @@ export function App({ helmetContext }: { helmetContext?: object }) {
|
|
|
103
104
|
return (
|
|
104
105
|
<HelmetProvider context={helmetContext}>
|
|
105
106
|
<Theme.Layout />
|
|
107
|
+
{
|
|
108
|
+
// Global UI
|
|
109
|
+
globalComponents.map((componentInfo, index) => {
|
|
110
|
+
if (Array.isArray(componentInfo)) {
|
|
111
|
+
const [component, props] = componentInfo;
|
|
112
|
+
return React.createElement(component, {
|
|
113
|
+
// The component order is stable
|
|
114
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
115
|
+
key: index,
|
|
116
|
+
...props,
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
return React.createElement(componentInfo, {
|
|
120
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
121
|
+
key: index,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
}
|
|
106
126
|
</HelmetProvider>
|
|
107
127
|
);
|
|
108
128
|
}
|
package/src/runtime/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './hooks';
|
|
|
2
2
|
export * from './Content';
|
|
3
3
|
export {
|
|
4
4
|
normalizeHrefInRuntime,
|
|
5
|
+
normalizeImagePath,
|
|
5
6
|
withBase,
|
|
6
7
|
removeBase,
|
|
7
8
|
addLeadingSlash,
|
|
@@ -11,6 +12,6 @@ export {
|
|
|
11
12
|
normalizeRoutePath,
|
|
12
13
|
isEqualPath,
|
|
13
14
|
} from './utils';
|
|
14
|
-
export { useLocation, useNavigate } from 'react-router-dom';
|
|
15
|
+
export { useLocation, useNavigate, matchRoutes } from 'react-router-dom';
|
|
15
16
|
export { Helmet } from 'react-helmet-async';
|
|
16
17
|
export { NoSSR } from './NoSSR';
|
package/src/runtime/utils.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
normalizeHref,
|
|
8
8
|
withBase as rawWithBase,
|
|
9
9
|
removeBase as rawRemoveBase,
|
|
10
|
+
isExternalUrl,
|
|
10
11
|
} from '@rspress/shared';
|
|
11
12
|
|
|
12
13
|
export function normalizeRoutePath(routePath: string) {
|
|
@@ -34,4 +35,12 @@ export function normalizeHrefInRuntime(a: string) {
|
|
|
34
35
|
return normalizeHref(a, cleanUrls);
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
export function normalizeImagePath(imagePath: string) {
|
|
39
|
+
if (isExternalUrl(imagePath)) {
|
|
40
|
+
return imagePath;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return withBase(imagePath);
|
|
44
|
+
}
|
|
45
|
+
|
|
37
46
|
export { addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction };
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
2
|
import { Header } from '@rspress/shared';
|
|
3
|
-
import { bindingAsideScroll, scrollToTarget } from '../../logic';
|
|
3
|
+
import { bindingAsideScroll, scrollToTarget, useHiddenNav } from '../../logic';
|
|
4
|
+
import { DEFAULT_NAV_HEIGHT } from '@/theme-default/logic/sideEffects';
|
|
4
5
|
import './index.css';
|
|
5
6
|
|
|
6
7
|
export function Aside(props: { headers: Header[]; outlineTitle: string }) {
|
|
7
8
|
const { headers } = props;
|
|
8
9
|
const hasOutline = headers.length > 0;
|
|
9
10
|
// For outline text highlight
|
|
10
|
-
const markerRef = useRef<HTMLDivElement>(null);
|
|
11
11
|
const baseHeaderLevel = headers[0]?.depth || 2;
|
|
12
|
+
const hiddenNav = useHiddenNav();
|
|
12
13
|
|
|
13
14
|
useEffect(() => {
|
|
14
15
|
let unbinding: (() => void) | undefined;
|
|
15
|
-
|
|
16
|
-
markerRef.current.style.opacity = '0';
|
|
17
|
-
}
|
|
16
|
+
|
|
18
17
|
setTimeout(() => {
|
|
19
18
|
unbinding = bindingAsideScroll();
|
|
20
19
|
}, 100);
|
|
@@ -24,7 +23,7 @@ export function Aside(props: { headers: Header[]; outlineTitle: string }) {
|
|
|
24
23
|
} else {
|
|
25
24
|
const target = document.getElementById(hash.slice(1));
|
|
26
25
|
if (target) {
|
|
27
|
-
scrollToTarget(target, false);
|
|
26
|
+
scrollToTarget(target, false, hiddenNav ? 0 : DEFAULT_NAV_HEIGHT);
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
return () => {
|
|
@@ -49,7 +48,7 @@ export function Aside(props: { headers: Header[]; outlineTitle: string }) {
|
|
|
49
48
|
window.location.hash = header.id;
|
|
50
49
|
const target = document.getElementById(header.id);
|
|
51
50
|
if (target) {
|
|
52
|
-
scrollToTarget(target, false);
|
|
51
|
+
scrollToTarget(target, false, hiddenNav ? 0 : DEFAULT_NAV_HEIGHT);
|
|
53
52
|
}
|
|
54
53
|
}}
|
|
55
54
|
>
|
|
@@ -2,7 +2,10 @@ import { useLocaleSiteData, usePrevNextPage } from '../../logic';
|
|
|
2
2
|
import EditLink from '../EditLink';
|
|
3
3
|
import { Link } from '../Link';
|
|
4
4
|
import styles from './index.module.scss';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
normalizeHrefInRuntime as normalizeHref,
|
|
7
|
+
usePageData,
|
|
8
|
+
} from '@/runtime';
|
|
6
9
|
|
|
7
10
|
export function DocFooter() {
|
|
8
11
|
const { prevPage, nextPage } = usePrevNextPage();
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { FrontMatterMeta } from '@rspress/shared';
|
|
2
2
|
import { Button } from '../Button';
|
|
3
3
|
import styles from './index.module.scss';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
normalizeHrefInRuntime as normalizeHref,
|
|
6
|
+
normalizeImagePath,
|
|
7
|
+
} from '@/runtime';
|
|
5
8
|
|
|
6
9
|
const DEFAULT_HERO = {
|
|
7
10
|
name: 'modern',
|
|
@@ -59,7 +62,10 @@ export function HomeHero({ frontmatter }: { frontmatter: FrontMatterMeta }) {
|
|
|
59
62
|
|
|
60
63
|
{hasImage ? (
|
|
61
64
|
<div className="rspress-home-hero-image md:flex-center m-auto order-1 md:order-2 sm:flex md:none lg:flex">
|
|
62
|
-
<img
|
|
65
|
+
<img
|
|
66
|
+
src={normalizeImagePath(hero.image?.src)}
|
|
67
|
+
alt={hero.image?.alt}
|
|
68
|
+
/>
|
|
63
69
|
</div>
|
|
64
70
|
) : null}
|
|
65
71
|
</div>
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { Fragment, useEffect, useState } from 'react';
|
|
2
|
-
import { NormalizedSidebarGroup, SidebarItem } from '@rspress/shared';
|
|
3
2
|
import { SideBar } from '../Sidebar';
|
|
4
3
|
import MenuIcon from '../../assets/menu.svg';
|
|
5
4
|
import './index.scss';
|
|
5
|
+
import { useLocation } from '@/runtime';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
pathname: string;
|
|
9
|
-
langRoutePrefix: string;
|
|
10
|
-
sidebarData: (NormalizedSidebarGroup | SidebarItem)[];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function SideMenu(props: Props) {
|
|
14
|
-
const { langRoutePrefix, pathname, sidebarData } = props;
|
|
7
|
+
export function SideMenu() {
|
|
15
8
|
const [isSidebarOpen, setIsOpen] = useState<boolean>(false);
|
|
9
|
+
const { pathname } = useLocation();
|
|
10
|
+
|
|
16
11
|
function openSidebar() {
|
|
17
12
|
setIsOpen(true);
|
|
18
13
|
}
|
|
@@ -35,12 +30,7 @@ export function SideMenu(props: Props) {
|
|
|
35
30
|
<span className="text-sm">Menu</span>
|
|
36
31
|
</button>
|
|
37
32
|
</div>
|
|
38
|
-
<SideBar
|
|
39
|
-
langRoutePrefix={langRoutePrefix}
|
|
40
|
-
pathname={pathname}
|
|
41
|
-
sidebarData={sidebarData}
|
|
42
|
-
isSidebarOpen={isSidebarOpen}
|
|
43
|
-
/>
|
|
33
|
+
<SideBar isSidebarOpen={isSidebarOpen} />
|
|
44
34
|
{isSidebarOpen ? (
|
|
45
35
|
<div onClick={closeSidebar} className="rspress-sidebar-back-drop" />
|
|
46
36
|
) : null}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useContext, useEffect, useState } from 'react';
|
|
2
|
+
import styles from './index.module.scss';
|
|
3
|
+
import {
|
|
4
|
+
ThemeContext,
|
|
5
|
+
normalizeImagePath,
|
|
6
|
+
usePageData,
|
|
7
|
+
withBase,
|
|
8
|
+
} from '@/runtime';
|
|
9
|
+
import { getLogoUrl, useLocaleSiteData } from '@/theme-default/logic';
|
|
10
|
+
|
|
11
|
+
export const NavBarTitle = () => {
|
|
12
|
+
const { siteData } = usePageData();
|
|
13
|
+
const localeData = useLocaleSiteData();
|
|
14
|
+
const { logo: rawLogo } = siteData;
|
|
15
|
+
const title = localeData.title ?? siteData.title;
|
|
16
|
+
const { theme } = useContext(ThemeContext);
|
|
17
|
+
const [logo, setLogo] = useState(getLogoUrl(rawLogo, theme));
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
setLogo(getLogoUrl(rawLogo, theme));
|
|
21
|
+
}, [theme]);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div className={`${styles.navBarTitle}`}>
|
|
25
|
+
<a
|
|
26
|
+
href={withBase(localeData.langRoutePrefix || '/')}
|
|
27
|
+
className="flex items-center w-full h-full text-base font-semibold transition-opacity duration-300 hover:opacity-60"
|
|
28
|
+
>
|
|
29
|
+
{logo ? (
|
|
30
|
+
<img
|
|
31
|
+
src={normalizeImagePath(logo)}
|
|
32
|
+
alt="logo"
|
|
33
|
+
id="logo"
|
|
34
|
+
className="w-24 mr-4 rspress-logo"
|
|
35
|
+
/>
|
|
36
|
+
) : (
|
|
37
|
+
<span>{title}</span>
|
|
38
|
+
)}
|
|
39
|
+
</a>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
@@ -1,7 +1,25 @@
|
|
|
1
|
+
.hidden {
|
|
2
|
+
transform: translate3d(0, calc(-100%), 0);
|
|
3
|
+
background: transparent;
|
|
4
|
+
opacity: 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
1
7
|
.container {
|
|
2
8
|
margin: auto;
|
|
3
9
|
}
|
|
4
10
|
|
|
11
|
+
.navContainer {
|
|
12
|
+
top: 0;
|
|
13
|
+
left: 0;
|
|
14
|
+
transition: all 0.3s ease;
|
|
15
|
+
transition-property: transform, opacity;
|
|
16
|
+
background: var(--rp-c-bg);
|
|
17
|
+
height: var(--rp-nav-height);
|
|
18
|
+
z-index: var(--rp-z-index-nav);
|
|
19
|
+
// Hidden the box shadow
|
|
20
|
+
// box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.1);
|
|
21
|
+
}
|
|
22
|
+
|
|
5
23
|
.leftNav {
|
|
6
24
|
display: none;
|
|
7
25
|
}
|
|
@@ -18,10 +36,6 @@
|
|
|
18
36
|
border-radius: 12px;
|
|
19
37
|
}
|
|
20
38
|
|
|
21
|
-
.navContainer {
|
|
22
|
-
height: var(--rp-nav-height);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
39
|
.navContainer :deep(*) {
|
|
26
40
|
pointer-events: all;
|
|
27
41
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { NavItem, replaceLang } from '@rspress/shared';
|
|
2
2
|
import { useLocation } from 'react-router-dom';
|
|
3
3
|
import { Search } from '@theme';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { isMobileDevice, useHiddenNav, useLocaleSiteData } from '../../logic';
|
|
6
6
|
import { NavHamburger } from '../NavHambmger';
|
|
7
7
|
import { SocialLinks } from '../SocialLinks';
|
|
8
8
|
import { SwitchAppearance } from '../SwitchAppearance';
|
|
9
9
|
import { NavMenuGroup, NavMenuGroupItem } from './NavMenuGroup';
|
|
10
10
|
import { NavMenuSingleItem } from './NavMenuSingleItem';
|
|
11
11
|
import styles from './index.module.scss';
|
|
12
|
-
import {
|
|
12
|
+
import { NavBarTitle } from './NavBarTitle';
|
|
13
|
+
import { usePageData, useVersion } from '@/runtime';
|
|
13
14
|
|
|
14
15
|
export interface NavProps {
|
|
15
16
|
beforeNav?: React.ReactNode;
|
|
@@ -19,34 +20,6 @@ export interface NavProps {
|
|
|
19
20
|
|
|
20
21
|
const DEFAULT_NAV_POSTION = 'right';
|
|
21
22
|
|
|
22
|
-
interface NavBarTitleProps {
|
|
23
|
-
title: string;
|
|
24
|
-
langRoutePrefix: string;
|
|
25
|
-
logo?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const NavBarTitle = ({ title, langRoutePrefix, logo }: NavBarTitleProps) => {
|
|
29
|
-
return (
|
|
30
|
-
<div className={`${styles.navBarTitle}`}>
|
|
31
|
-
<a
|
|
32
|
-
href={withBase(langRoutePrefix)}
|
|
33
|
-
className="flex items-center w-full h-full text-base font-semibold transition-opacity duration-300 hover:opacity-60"
|
|
34
|
-
>
|
|
35
|
-
{logo ? (
|
|
36
|
-
<img
|
|
37
|
-
src={logo}
|
|
38
|
-
alt="logo"
|
|
39
|
-
id="logo"
|
|
40
|
-
className="w-24 mr-4 rspress-logo"
|
|
41
|
-
/>
|
|
42
|
-
) : (
|
|
43
|
-
<span>{title}</span>
|
|
44
|
-
)}
|
|
45
|
-
</a>
|
|
46
|
-
</div>
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
23
|
const NavTranslations = ({
|
|
51
24
|
translationMenuData,
|
|
52
25
|
}: {
|
|
@@ -66,12 +39,12 @@ const NavTranslations = ({
|
|
|
66
39
|
export function Nav(props: NavProps) {
|
|
67
40
|
const { beforeNavTitle, afterNavTitle, beforeNav } = props;
|
|
68
41
|
const { siteData, page } = usePageData();
|
|
69
|
-
const {
|
|
42
|
+
const { base } = siteData;
|
|
70
43
|
const { pathname } = useLocation();
|
|
71
|
-
const { theme } = useContext(ThemeContext);
|
|
72
44
|
const localeData = useLocaleSiteData();
|
|
73
45
|
const currentVersion = useVersion();
|
|
74
46
|
const [isMobile, setIsMobile] = useState(false);
|
|
47
|
+
const hiddenNav = useHiddenNav();
|
|
75
48
|
const localeLanguages = Object.values(siteData.themeConfig.locales || {});
|
|
76
49
|
const hasMultiLanguage = localeLanguages.length > 1;
|
|
77
50
|
const socialLinks = siteData.themeConfig.socialLinks || [];
|
|
@@ -80,7 +53,6 @@ export function Nav(props: NavProps) {
|
|
|
80
53
|
const defaultVersion = siteData.multiVersion.default || '';
|
|
81
54
|
const { lang } = page;
|
|
82
55
|
const langs = localeLanguages.map(item => item.lang || '') || [];
|
|
83
|
-
const [logo, setLogo] = useState(getLogoUrl(rawLogo, theme));
|
|
84
56
|
|
|
85
57
|
const translationMenuData = hasMultiLanguage
|
|
86
58
|
? {
|
|
@@ -104,10 +76,6 @@ export function Nav(props: NavProps) {
|
|
|
104
76
|
}
|
|
105
77
|
: null;
|
|
106
78
|
|
|
107
|
-
useEffect(() => {
|
|
108
|
-
setLogo(getLogoUrl(rawLogo, theme));
|
|
109
|
-
}, [theme]);
|
|
110
|
-
|
|
111
79
|
useEffect(() => {
|
|
112
80
|
setIsMobile(isMobileDevice());
|
|
113
81
|
}, []);
|
|
@@ -151,7 +119,6 @@ export function Nav(props: NavProps) {
|
|
|
151
119
|
|
|
152
120
|
const hasSearch = siteData?.themeConfig?.search !== false;
|
|
153
121
|
|
|
154
|
-
const title = localeData.title ?? siteData.title;
|
|
155
122
|
const hasAppearanceSwitch = siteData.themeConfig.darkMode !== false;
|
|
156
123
|
|
|
157
124
|
const leftNav = () => {
|
|
@@ -186,24 +153,18 @@ export function Nav(props: NavProps) {
|
|
|
186
153
|
);
|
|
187
154
|
};
|
|
188
155
|
return (
|
|
189
|
-
|
|
190
|
-
className="top-0 left-0 md:fixed w-full"
|
|
191
|
-
style={{
|
|
192
|
-
zIndex: 'var(--rp-z-index-nav)',
|
|
193
|
-
background: 'var(--rp-c-bg)',
|
|
194
|
-
}}
|
|
195
|
-
>
|
|
156
|
+
<>
|
|
196
157
|
{beforeNav}
|
|
197
|
-
<div
|
|
158
|
+
<div
|
|
159
|
+
className={`${styles.navContainer} sticky rspress-nav px-6 ${
|
|
160
|
+
hiddenNav ? styles.hidden : ''
|
|
161
|
+
}`}
|
|
162
|
+
>
|
|
198
163
|
<div
|
|
199
164
|
className={`${styles.container} flex justify-between items-center h-full`}
|
|
200
165
|
>
|
|
201
166
|
{beforeNavTitle}
|
|
202
|
-
<NavBarTitle
|
|
203
|
-
title={title}
|
|
204
|
-
langRoutePrefix={localeData.langRoutePrefix || '/'}
|
|
205
|
-
logo={logo}
|
|
206
|
-
/>
|
|
167
|
+
<NavBarTitle />
|
|
207
168
|
{afterNavTitle}
|
|
208
169
|
<div
|
|
209
170
|
className={`${styles.content} flex flex-1 justify-end items-center`}
|
|
@@ -217,12 +178,11 @@ export function Nav(props: NavProps) {
|
|
|
217
178
|
localeData={localeData}
|
|
218
179
|
siteData={siteData}
|
|
219
180
|
pathname={pathname}
|
|
220
|
-
setLogo={setLogo}
|
|
221
181
|
/>
|
|
222
182
|
</div>
|
|
223
183
|
</div>
|
|
224
184
|
</div>
|
|
225
185
|
</div>
|
|
226
|
-
|
|
186
|
+
</>
|
|
227
187
|
);
|
|
228
188
|
}
|
|
@@ -13,11 +13,10 @@ interface Props {
|
|
|
13
13
|
localeData: LocaleConfig;
|
|
14
14
|
siteData: SiteData<DefaultThemeConfig>;
|
|
15
15
|
pathname: string;
|
|
16
|
-
setLogo: (logo: string) => void;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
export function NavHamburger(props: Props) {
|
|
20
|
-
const { localeData, siteData, pathname
|
|
19
|
+
const { localeData, siteData, pathname } = props;
|
|
21
20
|
const { isScreenOpen, toggleScreen } = useNav();
|
|
22
21
|
return (
|
|
23
22
|
<Fragment>
|
|
@@ -26,7 +25,6 @@ export function NavHamburger(props: Props) {
|
|
|
26
25
|
localeData={localeData}
|
|
27
26
|
siteData={siteData}
|
|
28
27
|
pathname={pathname}
|
|
29
|
-
setLogo={setLogo}
|
|
30
28
|
/>
|
|
31
29
|
<button
|
|
32
30
|
onClick={toggleScreen}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
2
|
import { disableBodyScroll, clearAllBodyScrollLocks } from 'body-scroll-lock';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
LocaleConfig,
|
|
5
|
+
NavItem,
|
|
6
|
+
DefaultThemeConfig,
|
|
7
|
+
replaceLang,
|
|
8
|
+
} from '@rspress/shared';
|
|
4
9
|
import type { SiteData } from '@rspress/shared';
|
|
5
10
|
import {
|
|
6
11
|
NavScreenMenuGroup,
|
|
@@ -10,16 +15,14 @@ import { NavMenuSingleItem } from '../Nav/NavMenuSingleItem';
|
|
|
10
15
|
import { SwitchAppearance } from '../SwitchAppearance';
|
|
11
16
|
import Translator from '../../assets/translator.svg';
|
|
12
17
|
import { SocialLinks } from '../SocialLinks';
|
|
13
|
-
import { getLogoUrl } from '../../logic/utils';
|
|
14
18
|
import styles from './index.module.scss';
|
|
15
|
-
import { NoSSR,
|
|
19
|
+
import { NoSSR, useLang, useVersion } from '@/runtime';
|
|
16
20
|
|
|
17
21
|
interface Props {
|
|
18
22
|
isScreenOpen: boolean;
|
|
19
23
|
localeData: LocaleConfig;
|
|
20
24
|
siteData: SiteData<DefaultThemeConfig>;
|
|
21
25
|
pathname: string;
|
|
22
|
-
setLogo: (logo: string) => void;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
const NavScreenTranslations = ({
|
|
@@ -39,9 +42,10 @@ const NavScreenTranslations = ({
|
|
|
39
42
|
};
|
|
40
43
|
|
|
41
44
|
export function NavScreen(props: Props) {
|
|
42
|
-
const { isScreenOpen, localeData, siteData, pathname
|
|
45
|
+
const { isScreenOpen, localeData, siteData, pathname } = props;
|
|
46
|
+
const currentVersion = useVersion();
|
|
47
|
+
const currentLang = useLang();
|
|
43
48
|
const screen = useRef<HTMLDivElement | null>(null);
|
|
44
|
-
const { theme } = useContext(ThemeContext);
|
|
45
49
|
const localesData = siteData.themeConfig.locales || [];
|
|
46
50
|
const hasMultiLanguage = localesData.length > 1;
|
|
47
51
|
const menuItems = localeData.nav || [];
|
|
@@ -49,7 +53,8 @@ export function NavScreen(props: Props) {
|
|
|
49
53
|
const socialLinks = siteData?.themeConfig?.socialLinks || [];
|
|
50
54
|
const hasSocialLinks = socialLinks.length > 0;
|
|
51
55
|
const langs = localesData.map(item => item.lang || 'zh') || [];
|
|
52
|
-
const { base,
|
|
56
|
+
const { base, lang: defaultLang, multiVersion } = siteData;
|
|
57
|
+
const { default: defaultVersion } = multiVersion;
|
|
53
58
|
const translationMenuData = hasMultiLanguage
|
|
54
59
|
? {
|
|
55
60
|
text: (
|
|
@@ -62,7 +67,19 @@ export function NavScreen(props: Props) {
|
|
|
62
67
|
),
|
|
63
68
|
items: localesData.map(item => ({
|
|
64
69
|
text: item?.label,
|
|
65
|
-
link:
|
|
70
|
+
link: replaceLang(
|
|
71
|
+
pathname,
|
|
72
|
+
{
|
|
73
|
+
current: currentLang,
|
|
74
|
+
target: item.lang,
|
|
75
|
+
default: defaultLang,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
current: currentVersion,
|
|
79
|
+
default: defaultVersion,
|
|
80
|
+
},
|
|
81
|
+
base,
|
|
82
|
+
),
|
|
66
83
|
})),
|
|
67
84
|
activeValue: localesData.find(item => item.lang === localeData.lang)
|
|
68
85
|
?.label,
|
|
@@ -72,11 +89,7 @@ export function NavScreen(props: Props) {
|
|
|
72
89
|
return (
|
|
73
90
|
<div className={`mt-2 ${styles.navAppearance} flex justify-center`}>
|
|
74
91
|
<NoSSR>
|
|
75
|
-
<SwitchAppearance
|
|
76
|
-
onClick={() => {
|
|
77
|
-
setLogo(getLogoUrl(logo, theme === 'dark' ? 'light' : 'dark'));
|
|
78
|
-
}}
|
|
79
|
-
/>
|
|
92
|
+
<SwitchAppearance />
|
|
80
93
|
</NoSSR>
|
|
81
94
|
</div>
|
|
82
95
|
);
|
|
@@ -84,19 +97,19 @@ export function NavScreen(props: Props) {
|
|
|
84
97
|
const NavScreenMenu = ({ menuItems }: { menuItems: NavItem[] }) => {
|
|
85
98
|
return (
|
|
86
99
|
<div className={styles.navMenu}>
|
|
87
|
-
{menuItems.map(
|
|
100
|
+
{menuItems.map(item => {
|
|
88
101
|
return (
|
|
89
|
-
<div key={
|
|
102
|
+
<div key={item.text} className={`${styles.navMenuItem} w-full`}>
|
|
90
103
|
{'link' in item ? (
|
|
91
104
|
<NavMenuSingleItem
|
|
92
105
|
pathname={pathname}
|
|
93
|
-
key={
|
|
106
|
+
key={item.text}
|
|
94
107
|
base={base}
|
|
95
108
|
langs={langs}
|
|
96
109
|
{...item}
|
|
97
110
|
/>
|
|
98
111
|
) : (
|
|
99
|
-
<div key={
|
|
112
|
+
<div key={item.text} className="mx-3 last:mr-0">
|
|
100
113
|
<NavScreenMenuGroup
|
|
101
114
|
{...item}
|
|
102
115
|
items={'items' in item ? item.items : item}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
|
+
.navTitleMask {
|
|
2
|
+
padding-left: 1.5rem;
|
|
3
|
+
height: var(--rp-nav-height);
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
.sidebar {
|
|
2
9
|
position: fixed;
|
|
3
10
|
top: 0;
|
|
4
11
|
bottom: 0;
|
|
5
12
|
left: 0;
|
|
6
13
|
z-index: var(--rp-z-index-sidebar);
|
|
7
|
-
padding:
|
|
14
|
+
padding: 0 12px 96px 0;
|
|
8
15
|
width: calc(100vw - 64px);
|
|
9
16
|
max-width: 320px;
|
|
10
|
-
background-color: var(--rp-c-bg);
|
|
11
17
|
opacity: 0;
|
|
12
18
|
transform: translateX(-100%);
|
|
13
19
|
transition: opacity 0.5s, transform 0.25s ease;
|
|
20
|
+
background: var(--rp-c-bg);
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
.sidebarContent {
|
|
17
24
|
overflow-x: hidden;
|
|
18
25
|
}
|
|
19
26
|
|
|
20
|
-
:global(.dark) .sidebar {
|
|
21
|
-
box-shadow: var(--rp-shadow-1);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
27
|
.sidebar.open {
|
|
25
28
|
opacity: 1;
|
|
26
29
|
visibility: visible;
|
|
@@ -30,11 +33,13 @@
|
|
|
30
33
|
|
|
31
34
|
@media (min-width: 960px) {
|
|
32
35
|
.sidebar {
|
|
33
|
-
z-index
|
|
34
|
-
|
|
35
|
-
padding-bottom: 128px;
|
|
36
|
+
// Lower than z-index of nav
|
|
37
|
+
z-index: 5;
|
|
36
38
|
opacity: 1;
|
|
37
39
|
visibility: visible;
|
|
40
|
+
position: sticky;
|
|
41
|
+
margin-top: calc(var(--rp-nav-height) * -1);
|
|
42
|
+
height: 100vh;
|
|
38
43
|
width: var(--rp-sidebar-width);
|
|
39
44
|
transform: translateX(0);
|
|
40
45
|
box-shadow: var(--rp-c-shadow-3);
|
|
@@ -126,8 +131,12 @@
|
|
|
126
131
|
}
|
|
127
132
|
}
|
|
128
133
|
|
|
129
|
-
:global(.dark
|
|
130
|
-
|
|
134
|
+
:global(.dark) {
|
|
135
|
+
:global(.rspress-sidebar-group)::before {
|
|
131
136
|
background-color: var(--rp-c-bg-mute);
|
|
132
137
|
}
|
|
138
|
+
|
|
139
|
+
.sidebar {
|
|
140
|
+
box-shadow: var(--rp-shadow-1);
|
|
141
|
+
}
|
|
133
142
|
}
|