11import React , { FC , ReactNode , useEffect , useMemo , useRef , useState } from 'react'
2+ import { Link } from 'gatsby'
23import { CContainer } from '@coreui/react'
34import { 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+ const getDescription = ( location : Location , description : string ) => {
63+ if ( location . pathname . includes ( 'api' ) || location . pathname . includes ( 'styling' ) ) {
64+ const regex = / R e a c t \s [ A - Z ] [ A - Z a - z ] * /
65+ const parts = description . split ( regex )
66+ const matches = description . match ( regex )
67+
68+ if ( matches && parts . length > 1 ) {
69+ return (
70+ < >
71+ { parts [ 0 ] }
72+ < Link to = "../" > { matches [ 0 ] } </ Link >
73+ { parts [ 1 ] }
74+ </ >
75+ )
76+ }
77+
78+ return description
79+ }
80+
81+ return description
82+ }
83+
6184const DocsLayout : FC < DocsLayoutProps > = ( { children, data, location, pageContext, path } ) => {
6285 const docsNavRef = useRef < HTMLDivElement > ( null )
6386 const headerRef = 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 const frameworks = useMemo (
7799 ( ) => otherFrameworksStr . split ( ', ' ) . filter ( Boolean ) ,
@@ -130,7 +152,7 @@ const DocsLayout: FC<DocsLayoutProps> = ({ children, data, location, pageContext
130152 </ h1 >
131153 ) }
132154 < Banner pro = { proComponent } />
133- < p className = "docs-lead" > { description } </ p >
155+ < p className = "docs-lead" > { getDescription ( location , description ) } </ p >
134156 < Ads code = "CEAICKJY" location = { location . pathname } placement = "coreuiio" />
135157 { frameworks . length > 0 && (
136158 < >
0 commit comments