|
| 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 | +} |
0 commit comments