Skip to content

Commit d43302c

Browse files
committed
docs: improve performance of theme
1 parent 359f552 commit d43302c

File tree

17 files changed

+274
-329
lines changed

17 files changed

+274
-329
lines changed

packages/docs/content/api/CTableCaption.api.mdx

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/docs/gatsby-browser.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1+
import React from 'react'
2+
import DefaultLayout from './src/templates/DefaultLayout'
13
import './src/styles/styles.scss'
4+
5+
export const wrapPageElement = ({ element, props }) => {
6+
return <DefaultLayout {...props}>{element}</DefaultLayout>
7+
}

packages/docs/gatsby-node.js

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,50 @@ const { createFilePath } = require('gatsby-source-filesystem')
33

44
exports.onCreateNode = ({ node, actions, getNode }) => {
55
const { createNodeField } = actions
6-
7-
// you only want to operate on `Mdx` nodes. If you had content from a
8-
// remote CMS you could also check to see if the parent node was a
9-
// `File` node here
106
if (node.internal.type === 'Mdx') {
11-
const value = createFilePath({ node, getNode })
7+
const slug = createFilePath({ node, getNode })
128

139
createNodeField({
14-
// Name of the field you are adding
1510
name: 'slug',
16-
// Individual MDX node
1711
node,
18-
// Generated value based on filepath with "blog" prefix. you
19-
// don't need a separating "/" before the value because
20-
// createFilePath returns a path with the leading "/".
21-
value: `${value}`,
12+
value: `${slug}`,
2213
})
2314
}
2415
}
2516

2617
exports.createPages = async ({ graphql, actions, reporter }) => {
27-
// Destructure the createPage function from the actions object
2818
const { createPage, createRedirect } = actions
2919
const result = await graphql(`
3020
query {
3121
allMdx {
32-
edges {
33-
node {
34-
id
35-
fields {
36-
slug
37-
}
38-
tableOfContents(maxDepth: 10)
39-
internal {
40-
contentFilePath
41-
}
22+
nodes {
23+
id
24+
fields {
25+
slug
26+
}
27+
internal {
28+
contentFilePath
4229
}
30+
tableOfContents(maxDepth: 3)
4331
}
4432
}
4533
}
4634
`)
35+
4736
if (result.errors) {
48-
reporter.panicOnBuild('🚨 ERROR: Loading "createPages" query')
37+
reporter.panicOnBuild('Error loading MDX result', result.errors)
4938
}
50-
// Create blog post pages.
51-
const posts = result.data.allMdx.edges
52-
const docsTemplate = path.resolve(`./src/templates/Docs.tsx`)
53-
// you'll call `createPage` for each result
54-
posts.forEach(({ node }, index) => {
55-
!node.internal.contentFilePath.includes('api') &&
56-
createPage({
57-
// This is the slug you created before
58-
// (or `node.frontmatter.slug`)
59-
path: node.fields.slug,
60-
// This component will wrap our MDX content
61-
component: `${docsTemplate}?__contentFilePath=${node.internal.contentFilePath}`,
62-
// You can use the values in this context in
63-
// our page layout component
64-
context: { id: node.id },
65-
})
39+
40+
const posts = result.data.allMdx.nodes
41+
42+
posts.forEach((node) => {
43+
createPage({
44+
path: node.fields.slug,
45+
component: `${path.resolve(`./src/templates/MdxLayout.tsx`)}?__contentFilePath=${
46+
node.internal.contentFilePath
47+
}`,
48+
context: { id: node.id },
49+
})
6650
})
6751
createRedirect({
6852
fromPath: `/`,

packages/docs/gatsby-ssr.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/**
2-
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
3-
*
4-
* See: https://www.gatsbyjs.com/docs/ssr-apis/
5-
*/
1+
import React from 'react'
2+
import DefaultLayout from './src/templates/DefaultLayout'
3+
import './src/styles/styles.scss'
64

7-
// You can delete this file if you're not using it
5+
export const wrapPageElement = ({ element, props }) => {
6+
return <DefaultLayout {...props}>{element}</DefaultLayout>
7+
}

packages/docs/src/components/Ads.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import React, { FC, useEffect, useRef } from 'react'
22

33
interface AdsProps {
44
code: string
5+
location: string
56
placement: string
67
}
78

8-
export const Ads: FC<AdsProps> = ({ code, placement }) => {
9+
export const Ads: FC<AdsProps> = ({ code, location, placement }) => {
910
const ref = useRef<HTMLDivElement>(null)
1011

1112
useEffect(() => {
@@ -16,7 +17,7 @@ export const Ads: FC<AdsProps> = ({ code, placement }) => {
1617
s.src = `//cdn.carbonads.com/carbon.js?serve=${code}&placement=${placement}`
1718
ref.current.appendChild(s)
1819
}
19-
}, [])
20+
}, [location])
2021

2122
return <div ref={ref} />
2223
}

packages/docs/src/components/CodeBlock.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { FC } from 'react'
2-
import PropTypes from 'prop-types'
32
import Highlight, { defaultProps } from 'prism-react-renderer'
43

54
interface CodeBlockProps {
@@ -32,10 +31,6 @@ const CodeBlock: FC<CodeBlockProps> = ({ children }) => {
3231
)
3332
}
3433

35-
CodeBlock.propTypes = {
36-
children: PropTypes.any,
37-
}
38-
3934
CodeBlock.displayName = 'CodeBlock'
4035

4136
export default CodeBlock

packages/docs/src/components/Footer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { FC } from 'react'
22

33
import { CContainer, CFooter } from '@coreui/react/src/index'
4+
5+
// @ts-expect-error json file
46
import pkg from './../../package.json'
57

68
const Footer: FC = () => {

packages/docs/src/components/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, { FC } from 'react'
22

33
import CIcon from '@coreui/icons-react'
44
import { cibGithub, cibOpenCollective, cibTwitter, cilCloudDownload, cilMenu } from '@coreui/icons'
5-
import { CButton, CHeader, CHeaderNav, CHeaderToggler, CNavItem } from '@coreui/react/src'
65

6+
import { CButton, CHeader, CHeaderNav, CHeaderToggler, CNavItem } from '@coreui/react/src'
77
import { AppContext } from './../AppContext'
88

99
const Header: FC = () => {

packages/docs/src/components/Seo.tsx

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
import React from 'react'
2-
import PropTypes from 'prop-types'
32
import { Helmet } from 'react-helmet'
43
import { useLocation } from '@reach/router'
54
import { useStaticQuery, graphql } from 'gatsby'
65

7-
const SEO = ({
8-
title,
9-
description,
10-
name,
11-
image,
12-
article,
13-
}: {
14-
title: string
15-
description: string
16-
name: string
17-
image: string
18-
article: string
19-
}) => {
6+
interface SEOProps {
7+
title?: string
8+
description?: string
9+
name?: string
10+
image?: string
11+
article?: string
12+
}
13+
14+
const SEO = ({ title, description, name, image, article }: SEOProps) => {
2015
const { pathname } = useLocation()
2116
const { site } = useStaticQuery(query)
2217

@@ -87,22 +82,6 @@ const SEO = ({
8782

8883
export default SEO
8984

90-
SEO.propTypes = {
91-
title: PropTypes.string,
92-
description: PropTypes.string,
93-
name: PropTypes.string,
94-
image: PropTypes.string,
95-
article: PropTypes.bool,
96-
}
97-
98-
SEO.defaultProps = {
99-
title: null,
100-
description: null,
101-
name: null,
102-
image: null,
103-
article: false,
104-
}
105-
10685
const query = graphql`
10786
query SEO {
10887
site {

packages/docs/src/components/Sidebar.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { FC } from 'react'
2-
import PropTypes from 'prop-types'
32

43
import {
54
CDropdown,
@@ -62,10 +61,6 @@ const Sidebar: FC<SidebarProps> = ({ ...props }) => {
6261
)
6362
}
6463

65-
Sidebar.propTypes = {
66-
currentRoute: PropTypes.string.isRequired,
67-
}
68-
6964
Sidebar.displayName = 'Sidebar'
7065

7166
export default Sidebar

packages/docs/src/components/SidebarNav.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { ReactNode } from 'react'
2-
import PropTypes from 'prop-types'
32
import { Link } from 'gatsby'
43

54
import { CBadge, CNavGroup, CNavItem, CSidebarNav } from '@coreui/react/src/index'
@@ -46,6 +45,7 @@ export const SidebarNav = ({ items, currentRoute }: SidebarNavProps) => {
4645
</CNavItem>
4746
)
4847
}
48+
4949
const navGroup = (item: NavItem, index: number) => {
5050
const { name, icon, to, ...rest } = item
5151
return (
@@ -73,8 +73,3 @@ export const SidebarNav = ({ items, currentRoute }: SidebarNavProps) => {
7373
</CSidebarNav>
7474
)
7575
}
76-
77-
SidebarNav.propTypes = {
78-
items: PropTypes.arrayOf(PropTypes.any).isRequired,
79-
currentRoute: PropTypes.string.isRequired,
80-
}

packages/docs/src/pages/404.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import * as React from 'react'
22
import { graphql, useStaticQuery } from 'gatsby'
3+
import { CButton } from '@coreui/react/src/index'
34

4-
import DefaultLayout from './../templates/Layout'
55
import Seo from './../components/Seo'
6-
import { CButton } from '@coreui/react/src/index'
76

87
const NotFoundPage = () => {
98
const { site } = useStaticQuery(query)
109
const { siteUrl } = site.siteMetadata
1110
return (
12-
<DefaultLayout>
11+
<>
1312
<Seo title="404: Not found" />
1413
<h1>404: Not Found</h1>
1514
<p>You just hit a route that doesn&#39;t exist... the sadness.</p>
1615
<CButton href={siteUrl}>Go to documentation</CButton>
17-
</DefaultLayout>
16+
</>
1817
)
1918
}
2019

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React, { FC, useState } from 'react'
2+
import { Footer, Header, Sidebar, Seo } from '../components'
3+
import { CContainer } from '@coreui/react/src/'
4+
import DocsLayout from './DocsLayout'
5+
6+
import { AppContext } from '../AppContext'
7+
8+
interface DefaultLayoutProps {
9+
children: any
10+
data: any
11+
pageContext: any
12+
path: any
13+
}
14+
15+
const DefaultLayout: FC<DefaultLayoutProps> = ({ children, data, pageContext, path }) => {
16+
const [sidebarVisible, setSidebarVisible] = useState()
17+
18+
const title = pageContext.frontmatter ? pageContext.frontmatter.title : ''
19+
const description = pageContext.frontmatter ? pageContext.frontmatter.description : ''
20+
const name = pageContext.frontmatter ? pageContext.frontmatter.name : ''
21+
const route = pageContext.frontmatter ? pageContext.frontmatter.route : ''
22+
23+
return (
24+
<AppContext.Provider
25+
value={{
26+
sidebarVisible,
27+
setSidebarVisible,
28+
}}
29+
>
30+
<Seo title={title} description={description} name={name} />
31+
<Sidebar currentRoute={route} />
32+
<div className="wrapper d-flex flex-column min-vh-100">
33+
<Header />
34+
<div className="body flex-grow-1 px-3">
35+
{path === '/404/' ? (
36+
<CContainer lg>{children}</CContainer>
37+
) : (
38+
<DocsLayout data={data} pageContext={pageContext}>
39+
{children}
40+
</DocsLayout>
41+
)}
42+
</div>
43+
<Footer />
44+
</div>
45+
</AppContext.Provider>
46+
)
47+
}
48+
49+
DefaultLayout.displayName = 'DefaultLayout'
50+
51+
export default DefaultLayout

0 commit comments

Comments
 (0)