Skip to content

Commit 3c3badb

Browse files
authored
fix: use hack way to reuse builtin nav (#231)
1 parent 60d53ec commit 3c3badb

File tree

14 files changed

+149
-397
lines changed

14 files changed

+149
-397
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@alauda/doom": patch
3+
---
4+
5+
fix: use hack way to reuse builtin nav

packages/doom/src/runtime/components/Directive.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ export const Directive = ({
1919
open,
2020
onToggle,
2121
}: DirectiveProps) => {
22-
const rootClassName = clsx('rspress-directive', type, className)
22+
const rootClassName = clsx('rp-callout', `rp-callout--${type}`, className)
2323
const titleNode = title || upperCase(type)
24-
const contentNode = (
25-
<div className="rspress-directive-content">{children}</div>
26-
)
24+
const contentNode = <div className="rp-callout__content">{children}</div>
2725

2826
const handleToggle: ReactEventHandler<HTMLDetailsElement> = useCallback(
2927
(ev) => {
@@ -35,15 +33,15 @@ export const Directive = ({
3533
if (type === 'details') {
3634
return (
3735
<details className={rootClassName} open={open} onToggle={handleToggle}>
38-
<summary className="rspress-directive-title">{titleNode}</summary>
36+
<summary className="rp-callout__title">{titleNode}</summary>
3937
{contentNode}
4038
</details>
4139
)
4240
}
4341

4442
return (
4543
<div className={rootClassName}>
46-
<div className="rspress-directive-title">{titleNode}</div>
44+
<div className="rp-callout__title">{titleNode}</div>
4745
{contentNode}
4846
</div>
4947
)

packages/doom/src/runtime/components/ExternalSiteLink.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { clsx } from 'clsx'
1111
import virtual from 'doom-@global-virtual'
1212
import { type AnchorHTMLAttributes, type ReactNode, useMemo } from 'react'
1313

14-
import classes from '../../../styles/link.module.scss'
1514
import { isUnversioned } from '../../shared/helpers.js'
1615
import { useIsPrint } from '../hooks/index.js'
1716

@@ -76,7 +75,7 @@ const ExternalSiteLink_ = ({
7675
}
7776
target="_blank"
7877
rel="noopener noreferrer"
79-
className={clsx(classes.link, 'rp-cursor-pointer', className)}
78+
className={clsx('rp-link', className)}
8079
{...props}
8180
/>
8281
)

packages/doom/src/shared/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const removeBothEndsSlashes = (str?: string) =>
1212
str?.replace(/^\/|\/$/g, '') || ''
1313

1414
export const getPdfName = (lang: string, userBase?: string, title?: string) =>
15-
`${removeBothEndsSlashes(userBase) || title || 'exported'}-${lang}.pdf`
15+
`/${removeBothEndsSlashes(userBase) || title || 'exported'}-${lang}.pdf`
1616

1717
export const isExplicitlyUnversioned = (
1818
version?: string,

packages/doom/src/theme/Layout.tsx

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { useLang, useSite, withBase } from '@rspress/core/runtime'
1+
import { useLang, useSite } from '@rspress/core/runtime'
22
import {
3+
Link,
34
Layout as OriginalLayout,
45
getCustomMDXComponent,
56
} from '@rspress/core/theme-original'
67
import virtual from 'doom-@global-virtual'
7-
import { useMemo } from 'react'
8+
import { useCallback, useMemo, useState } from 'react'
89
import { useLocation } from 'react-router'
910

10-
import classes from '../../styles/link.module.scss'
1111
import type {
1212
DoomSidebar,
1313
DoomSidebarGroup,
@@ -16,6 +16,7 @@ import type {
1616
import { useTranslation } from '../runtime/index.ts'
1717
import type { ExportItem } from '../types.ts'
1818

19+
import { ForceRenderContext } from './VersionsNav/context.tsx'
1920
import { VersionsNav } from './VersionsNav/index.tsx'
2021

2122
const X = getCustomMDXComponent()
@@ -130,28 +131,34 @@ export const Layout = () => {
130131

131132
const pdfLink = useMemo(
132133
() =>
133-
found &&
134-
withBase(`${found.exportItem.name ?? found.sidebar.text}-${lang}.pdf`),
134+
found && `/${found.exportItem.name ?? found.sidebar.text}-${lang}.pdf`,
135135
[found, lang],
136136
)
137137

138+
const [render, setRender] = useState(false)
139+
const forceRender = useCallback(() => {
140+
setRender((v) => !v)
141+
}, [])
142+
138143
return (
139-
<OriginalLayout
140-
afterNavMenu={<VersionsNav />}
141-
beforeOutline={
142-
pdfLink && (
143-
<X.p style={{ marginBottom: 16 }}>
144-
<a
145-
className={classes.link}
146-
href={pdfLink}
147-
target="_blank"
148-
rel="noopener noreferrer"
149-
>
150-
{t('view_docs_as_pdf')}
151-
</a>
152-
</X.p>
153-
)
154-
}
155-
/>
144+
<ForceRenderContext
145+
value={useMemo(
146+
() => ({ value: render, setValue: forceRender }),
147+
[forceRender, render],
148+
)}
149+
>
150+
<VersionsNav />
151+
<OriginalLayout
152+
beforeOutline={
153+
pdfLink && (
154+
<X.p className="rp-doc" style={{ marginBottom: 16 }}>
155+
<Link href={pdfLink} target="_blank" rel="noopener noreferrer">
156+
{t('view_docs_as_pdf')}
157+
</Link>
158+
</X.p>
159+
)
160+
}
161+
/>
162+
</ForceRenderContext>
156163
)
157164
}

packages/doom/src/theme/Link.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {
2+
Link as OriginalLink,
3+
type LinkProps,
4+
} from '@rspress/core/theme-original'
5+
6+
export const Link = (props: LinkProps) => {
7+
if (
8+
typeof location !== 'undefined' &&
9+
props.href?.startsWith(`${location.protocol}//${location.host}`)
10+
) {
11+
return <a {...props} />
12+
}
13+
return (
14+
<OriginalLink
15+
{...props}
16+
download={
17+
// type-coverage:ignore-next-line -- out of control
18+
props.download == null
19+
? props.href?.endsWith('.pdf')
20+
: // type-coverage:ignore-next-line -- out of control
21+
(props.download as unknown)
22+
}
23+
/>
24+
)
25+
}

packages/doom/src/theme/VersionsNav/Down.tsx

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/doom/src/theme/VersionsNav/NavMenuGroup.tsx

Lines changed: 0 additions & 192 deletions
This file was deleted.

0 commit comments

Comments
 (0)