Skip to content

[pull] main from coreui:main #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/docs/src/components/Toc.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, useState } from 'react'
import React, { CSSProperties, forwardRef, useState } from 'react'
import { CCollapse, CNav } from '@coreui/react/src/index'

export type TocItem = {
Expand All @@ -9,6 +9,7 @@ export type TocItem = {

interface TocProps {
items: TocItem[]
style: CSSProperties
}

const toc = (items: TocItem[]) => {
Expand Down
28 changes: 25 additions & 3 deletions packages/docs/src/templates/DocsLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { FC, ReactNode, useEffect, useMemo, useRef, useState } from 'react'
import React, { CSSProperties, FC, ReactNode, useEffect, useMemo, useRef, useState } from 'react'
import { Link } from 'gatsby'
import { CContainer } from '@coreui/react'
import { Ads, Banner, ComponentSubNav, Footer, Header, Sidebar, Toc } from '../components'
// @ts-expect-error json file
Expand Down Expand Up @@ -58,6 +59,28 @@ const humanize = (text: string): string => {
.join(' ')
}

const getDescription = (___location: Location, description: string) => {
if (___location.pathname.includes('api') || ___location.pathname.includes('styling')) {
const regex = /React\s[A-Z][A-Za-z]*/
const parts = description.split(regex)
const matches = description.match(regex)

if (matches && parts.length > 1) {
return (
<>
{parts[0]}
<Link to="../">{matches[0]}</Link>
{parts[1]}
</>
)
}

return description
}

return description
}

const DocsLayout: FC<DocsLayoutProps> = ({ children, data, ___location, pageContext, path }) => {
const docsNavRef = useRef<HTMLDivElement>(null)
const headerRef = useRef<HTMLDivElement>(null)
Expand All @@ -71,7 +94,6 @@ const DocsLayout: FC<DocsLayoutProps> = ({ children, data, ___location, pageContext
name = '',
other_frameworks: otherFrameworksStr = '',
pro_component: proComponent = false,
route = '',
} = frontmatter
const frameworks = useMemo(
() => otherFrameworksStr.split(', ').filter(Boolean),
Expand Down Expand Up @@ -130,7 +152,7 @@ const DocsLayout: FC<DocsLayoutProps> = ({ children, data, ___location, pageContext
</h1>
)}
<Banner pro={proComponent} />
<p className="docs-lead">{description}</p>
<p className="docs-lead">{getDescription(___location, description)}</p>
<Ads code="CEAICKJY" ___location={___location.pathname} placement="coreuiio" />
{frameworks.length > 0 && (
<>
Expand Down