Skip to content

Commit 6fb2b31

Browse files
authored
feat: add edit page adn question sidecat (#273)
1 parent 330072d commit 6fb2b31

File tree

6 files changed

+155
-4
lines changed

6 files changed

+155
-4
lines changed

i18n/en/code.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,5 +1048,9 @@
10481048
"team.termStart": {
10491049
"message": "Term Start",
10501050
"description": "Term start label"
1051+
},
1052+
"theme.common.reportAnIssue": {
1053+
"message": "Report an issue",
1054+
"description": "The link label to report an issue for the current page"
10511055
}
10521056
}

i18n/zh-Hans/code.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,5 +1164,9 @@
11641164
"contributing.codeOfConductTitle": {
11651165
"message": "行为准则",
11661166
"description": "Code of conduct title"
1167+
},
1168+
"theme.common.reportAnIssue": {
1169+
"message": "问题反馈",
1170+
"description": "The link label to report an issue for the current page"
11671171
}
11681172
}

project.config.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ export interface ProjectConfig {
1111
website?: string
1212
}
1313

14-
// GitHub repository information
14+
// GitHub repository information (project code repo)
1515
github: {
1616
username: string
1717
repoName: string
1818
}
1919

20+
// Docs/website repository information
21+
docsGithub: {
22+
username: string
23+
repoName: string
24+
}
25+
2026
// Website deployment information
2127
deployment: {
2228
url: string
@@ -56,12 +62,18 @@ const projectConfig: ProjectConfig = {
5662
website: 'https://java2ai.com', // optional
5763
},
5864

59-
// GitHub repository information
65+
// GitHub repository information (project code repo)
6066
github: {
6167
username: 'alibaba',
6268
repoName: 'spring-ai-alibaba',
6369
},
6470

71+
// Docs/website repository information
72+
docsGithub: {
73+
username: 'spring-ai-alibaba',
74+
repoName: 'website',
75+
},
76+
6577
// Website deployment configuration
6678
deployment: {
6779
url: 'https://spring-ai-alibaba.github.io',
@@ -96,14 +108,18 @@ export const getGitHubUrls = (config: ProjectConfig) => {
96108
const { username, repoName } = config.github
97109
const baseUrl = `https://github.com/${username}/${repoName}`
98110

111+
const { username: docsUsername, repoName: docsRepoName } = config.docsGithub
112+
const docsBaseUrl = `https://github.com/${docsUsername}/${docsRepoName}`
113+
99114
return {
100115
repo: baseUrl,
101116
discussions: `${baseUrl}/discussions`,
102117
issues: `${baseUrl}/issues`,
103118
license: `${baseUrl}/blob/main/LICENSE`,
104119
contributing: `${baseUrl}/blob/main/CONTRIBUTING.md`,
105-
editDocs: `${baseUrl}/tree/main/docs/`,
106-
editBlog: `${baseUrl}/tree/main/blog/`,
120+
editDocs: `${docsBaseUrl}/tree/main/`,
121+
editBlog: `${docsBaseUrl}/tree/main/blog/`,
122+
docsRepo: docsBaseUrl,
107123
}
108124
}
109125

src/theme/TOC/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React, { type ReactNode } from 'react'
2+
import TOCOriginal from '@theme-original/TOC'
3+
import type TOCType from '@theme/TOC'
4+
import type { WrapperProps } from '@docusaurus/types'
5+
6+
type Props = WrapperProps<typeof TOCType>
7+
8+
export default function TOCWrapper(props: Props): ReactNode {
9+
return <TOCOriginal {...props} />
10+
}

src/theme/TOCItems/index.tsx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import React, { type ReactNode } from 'react'
2+
import TOCItemsOriginal from '@theme-original/TOCItems'
3+
import type TOCItemsType from '@theme/TOCItems'
4+
import type { WrapperProps } from '@docusaurus/types'
5+
import { useDoc } from '@docusaurus/plugin-content-docs/client'
6+
import Translate from '@docusaurus/Translate'
7+
import styles from './styles.module.css'
8+
9+
type Props = WrapperProps<typeof TOCItemsType>
10+
11+
function DocPageLinks(): ReactNode {
12+
const { metadata } = useDoc()
13+
const { editUrl } = metadata
14+
const issuesUrl = 'https://github.com/alibaba/spring-ai-alibaba/issues/new'
15+
16+
return (
17+
<div className={styles.docPageLinks}>
18+
{editUrl && (
19+
<a
20+
href={editUrl}
21+
target="_blank"
22+
rel="noopener noreferrer"
23+
className={styles.link}
24+
>
25+
<svg className={styles.icon} viewBox="0 0 24 24" aria-hidden="true">
26+
<path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z" />
27+
</svg>
28+
<Translate
29+
id="theme.common.editThisPage"
30+
description="The link label to edit the current page"
31+
>
32+
编辑此页
33+
</Translate>
34+
</a>
35+
)}
36+
<a
37+
href={issuesUrl}
38+
target="_blank"
39+
rel="noopener noreferrer"
40+
className={styles.link}
41+
>
42+
<svg className={styles.icon} viewBox="0 0 24 24" aria-hidden="true">
43+
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z" />
44+
</svg>
45+
<Translate
46+
id="theme.common.reportAnIssue"
47+
description="The link label to report an issue for the current page"
48+
>
49+
问题反馈
50+
</Translate>
51+
</a>
52+
</div>
53+
)
54+
}
55+
56+
class DocPageLinksErrorBoundary extends React.Component<
57+
{ children: ReactNode },
58+
{ hasError: boolean }
59+
> {
60+
constructor(props: { children: ReactNode }) {
61+
super(props)
62+
this.state = { hasError: false }
63+
}
64+
65+
static getDerivedStateFromError() {
66+
return { hasError: true }
67+
}
68+
69+
render() {
70+
if (this.state.hasError) {
71+
return null
72+
}
73+
return this.props.children
74+
}
75+
}
76+
77+
export default function TOCItemsWrapper(props: Props): ReactNode {
78+
return (
79+
<>
80+
<TOCItemsOriginal {...props} />
81+
<DocPageLinksErrorBoundary>
82+
<DocPageLinks />
83+
</DocPageLinksErrorBoundary>
84+
</>
85+
)
86+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.docPageLinks {
2+
display: flex;
3+
flex-direction: column;
4+
gap: 8px;
5+
margin-top: 20px;
6+
padding-top: 16px;
7+
border-top: 1px solid var(--ifm-color-emphasis-300);
8+
font-size: 0.8rem;
9+
}
10+
11+
.link {
12+
display: flex;
13+
align-items: center;
14+
gap: 6px;
15+
color: var(--ifm-color-emphasis-700);
16+
text-decoration: none;
17+
transition: color var(--ifm-transition-fast);
18+
line-height: 1.4;
19+
}
20+
21+
.link:hover {
22+
color: var(--ifm-color-primary);
23+
text-decoration: none;
24+
}
25+
26+
.icon {
27+
width: 14px;
28+
height: 14px;
29+
flex-shrink: 0;
30+
fill: currentColor;
31+
}

0 commit comments

Comments
 (0)