Skip to content

Commit 1604515

Browse files
authored
feat(theme/EditLink): add edit link to outline sidebar (#3164)
1 parent 56db516 commit 1604515

File tree

6 files changed

+39
-4
lines changed

6 files changed

+39
-4
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { useEditLink } from '../EditLink/useEditLink';
2+
3+
export function EditLinkRow() {
4+
const editLinkObj = useEditLink();
5+
6+
if (!editLinkObj) {
7+
return null;
8+
}
9+
10+
const { text, link } = editLinkObj;
11+
12+
return (
13+
<a
14+
href={link}
15+
target="_blank"
16+
rel="noopener noreferrer"
17+
className="rp-outline__action-row"
18+
>
19+
<svg
20+
viewBox="0 0 16 16"
21+
fill="currentColor"
22+
xmlns="http://www.w3.org/2000/svg"
23+
>
24+
<path
25+
fillRule="evenodd"
26+
clipRule="evenodd"
27+
d="M11.013 1.427a1.75 1.75 0 0 1 2.474 0l1.086 1.086a1.75 1.75 0 0 1 0 2.474l-8.61 8.61c-.21.21-.47.364-.756.442l-3.251.929a.75.75 0 0 1-.924-.924l.929-3.251a1.75 1.75 0 0 1 .443-.757l8.61-8.61Zm1.414 1.06a.25.25 0 0 0-.354 0L3.463 11.098a.25.25 0 0 0-.063.108l-.558 1.953 1.953-.558a.25.25 0 0 0 .108-.063l8.61-8.61a.25.25 0 0 0 0-.354l-1.086-1.086Z"
28+
/>
29+
</svg>
30+
<span>{text}</span>
31+
</a>
32+
);
33+
}

packages/core/src/theme/components/Outline/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useI18n, useSite } from '@rspress/core/runtime';
22
import { ReadPercent, Toc, useDynamicToc } from '@theme';
33
import './index.scss';
4+
import { EditLinkRow } from './EditLinkRow';
45
import { ScrollToTop } from './ScrollToTop';
56

67
export function Outline() {
@@ -29,6 +30,7 @@ export function Outline() {
2930
<div className="rp-outline__divider" />
3031
<div className="rp-outline__bottom">
3132
{enableScrollToTop && <ScrollToTop />}
33+
<EditLinkRow />
3234
</div>
3335
</div>
3436
);

website/docs/en/api/config/config-theme.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ interface EditLink {
402402

403403
- **Default**: `undefined`
404404

405-
Display a link to edit the page on Git management services such as GitHub, or GitLab.
405+
Display a link to edit the page on Git management services such as GitHub, or GitLab. The link appears in both the doc footer and the right-side outline panel.
406406

407407
For example:
408408

website/docs/en/ui/layout-components/edit-link.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ overviewHeaders: []
99

1010
## Usage
1111

12-
This component is usually rendered automatically as part of [DocFooter](/ui/layout-components/doc-footer) and doesn't need manual usage.
12+
This component is rendered automatically in both the [DocFooter](/ui/layout-components/doc-footer) and the right-side outline panel, and doesn't need manual usage.
1313

1414
```tsx preview
1515
import { EditLink as BasicEditLink } from '@rspress/core/theme-original';

website/docs/zh/api/config/config-theme.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ interface EditLink {
389389

390390
- **默认值**`undefined`
391391

392-
用于配置编辑链接,以在 GitHub 或 GitLab 等 Git 管理服务上编辑页面。
392+
用于配置编辑链接,以在 GitHub 或 GitLab 等 Git 管理服务上编辑页面。该链接会同时显示在文档底部和右侧大纲面板中。
393393

394394
比如:
395395

website/docs/zh/ui/layout-components/edit-link.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ overviewHeaders: []
99

1010
## 用法
1111

12-
该组件通常作为 [DocFooter](/ui/layout-components/doc-footer) 的一部分自动渲染,无需手动使用。
12+
该组件会自动渲染在 [DocFooter](/ui/layout-components/doc-footer) 和右侧大纲面板中,无需手动使用。
1313

1414
```tsx preview
1515
import { EditLink as BasicEditLink } from '@rspress/core/theme-original';

0 commit comments

Comments
 (0)