Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb1ae042

Browse files
committed
docs: improve internal linking
1 parent69dc9b9 commitb1ae042

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

‎packages/docs/src/templates/DocsLayout.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
importReact,{FC,ReactNode,useEffect,useMemo,useRef,useState}from'react'
1+
importReact,{CSSProperties,FC,ReactNode,useEffect,useMemo,useRef,useState}from'react'
2+
import{Link}from'gatsby'
23
import{CContainer}from'@coreui/react'
34
import{Ads,Banner,ComponentSubNav,Footer,Header,Sidebar,Toc}from'../components'
45
//@ts-expect-error json file
@@ -58,6 +59,28 @@ const humanize = (text: string): string => {
5859
.join(' ')
5960
}
6061

62+
constgetDescription=(location:Location,description:string)=>{
63+
if(location.pathname.includes('api')||location.pathname.includes('styling')){
64+
constregex=/React\s[A-Z][A-Za-z]*/
65+
constparts=description.split(regex)
66+
constmatches=description.match(regex)
67+
68+
if(matches&&parts.length>1){
69+
return(
70+
<>
71+
{parts[0]}
72+
<Linkto="../">{matches[0]}</Link>
73+
{parts[1]}
74+
</>
75+
)
76+
}
77+
78+
returndescription
79+
}
80+
81+
returndescription
82+
}
83+
6184
constDocsLayout:FC<DocsLayoutProps>=({ children, data, location, pageContext, path})=>{
6285
constdocsNavRef=useRef<HTMLDivElement>(null)
6386
constheaderRef=useRef<HTMLDivElement>(null)
@@ -71,7 +94,6 @@ const DocsLayout: FC<DocsLayoutProps> = ({ children, data, location, pageContext
7194
name='',
7295
other_frameworks:otherFrameworksStr='',
7396
pro_component:proComponent=false,
74-
route='',
7597
}=frontmatter
7698
constframeworks=useMemo(
7799
()=>otherFrameworksStr.split(', ').filter(Boolean),
@@ -130,7 +152,7 @@ const DocsLayout: FC<DocsLayoutProps> = ({ children, data, location, pageContext
130152
</h1>
131153
)}
132154
<Bannerpro={proComponent}/>
133-
<pclassName="docs-lead">{description}</p>
155+
<pclassName="docs-lead">{getDescription(location,description)}</p>
134156
<Adscode="CEAICKJY"location={location.pathname}placement="coreuiio"/>
135157
{frameworks.length>0&&(
136158
<>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp