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

Appearance settings

Commit 746377d

Browse filesBrowse files
committed
docs: improve internal linking
1 parent 69dc9b9 commit 746377d
Copy full SHA for 746377d

File tree

1 file changed

+24
-2
lines changed
Filter options

1 file changed

+24
-2
lines changed

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

Copy file name to clipboardExpand all lines: packages/docs/src/templates/DocsLayout.tsx
+24-2Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { 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+
const getDescription = (location: Location, description: string) => {
63+
if (location.pathname.includes('api') || location.pathname.includes('styling')) {
64+
const regex = /React\s[A-Z][A-Za-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+
6184
const 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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.