Skip to content

Commit a7f65b7

Browse files
committed
refactor: finished migration of mdxs and removed next-mdx-remote package
1 parent acdbbad commit a7f65b7

28 files changed

+151
-333
lines changed
File renamed without changes.

components/ContentCallout.tsx renamed to components/mdx/Callout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Box, HStack, useStyleConfig } from '@chakra-ui/react'
22
import React, { FC } from 'react'
33

4-
const ComponentCallout: FC = (props: any) => {
4+
const Callout: FC = (props: any) => {
55
const { size, variant, emoji, children, ...rest } = props
66

7-
const styles = useStyleConfig('ContentCallout', { size, variant })
7+
const styles = useStyleConfig('Callout', { size, variant })
88
return (
99
<Box __css={styles} {...rest}>
1010
<HStack spacing={4}>
@@ -17,4 +17,4 @@ const ComponentCallout: FC = (props: any) => {
1717
)
1818
}
1919

20-
export default ComponentCallout
20+
export default Callout

components/mdx/MDXComponents.tsx renamed to components/mdx/Components.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { Box, Code, Heading, Image, Text } from '@chakra-ui/react'
22
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
33
import dracula from 'react-syntax-highlighter/dist/cjs/styles/prism/dracula'
44
import { CopyToClipboard } from '../CopyToClipboard'
5+
import SideDrawer from './SideDrawer'
6+
import Callout from './Callout'
57

6-
const MDXcomponents = {
8+
const Components = {
79
code: (props: any) => {
810
const [, language] =
911
(props.className as string)?.match(/language-(\w+)/) ?? []
@@ -37,8 +39,8 @@ const MDXcomponents = {
3739
img: (props: any) => (
3840
<Image as="img" apply="mdx.image" m="0 auto" alt="" {...props} />
3941
),
40-
// ContentSideDrawer,
41-
// ContentCallout,
42+
SideDrawer,
43+
Callout,
4244
}
4345

44-
export default MDXcomponents
46+
export default Components

components/ContentSideDrawer.tsx renamed to components/mdx/SideDrawer.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ import {
1212
} from '@chakra-ui/react'
1313
import React from 'react'
1414

15-
function ContentSideDrawer(props: any) {
15+
function SideDrawer(props: any) {
1616
const { isOpen, onOpen, onClose } = useDisclosure()
1717

18+
const { buttonText, title } = props
19+
const drawerTitle = title ? title : buttonText
20+
1821
return (
1922
<>
2023
<Button
@@ -25,14 +28,16 @@ function ContentSideDrawer(props: any) {
2528
fontWeight="bold"
2629
bg="gray.700"
2730
mt="1em"
28-
height={[`${props.title.length > 30 ? '3.75rem' : '2.5rem'}`, '2.5rem']}
31+
height={[`${buttonText.length > 30 ? '3.75rem' : '2.5rem'}`, '2.5rem']}
2932
style={{
3033
whiteSpace: 'normal',
3134
wordWrap: 'break-word',
3235
}}
36+
rightIcon={<ArrowRightIcon />}
3337
>
34-
{props.title}&nbsp;&nbsp;
35-
<ArrowRightIcon />
38+
{buttonText}
39+
{/* &nbsp;&nbsp; */}
40+
{/* <ArrowRightIcon /> */}
3641
</Button>
3742
<Drawer isOpen={isOpen} placement="right" onClose={onClose} size="xl">
3843
<DrawerOverlay
@@ -44,7 +49,7 @@ function ContentSideDrawer(props: any) {
4449
<DrawerContent bg="#00000f" px="4" pb="8">
4550
<DrawerCloseButton />
4651
<DrawerHeader fontSize="3xl" textColor="yellow.300">
47-
{props.title}
52+
{drawerTitle}
4853
</DrawerHeader>
4954
<DrawerBody>{props.children}</DrawerBody>
5055
</DrawerContent>
@@ -53,4 +58,4 @@ function ContentSideDrawer(props: any) {
5358
)
5459
}
5560

56-
export default ContentSideDrawer
61+
export default SideDrawer

lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const CONTENT_PATH = 'pages/lessons'

next.config.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
/** @type {import('next').NextConfig} */
2-
// const nextConfig = {
3-
// reactStrictMode: true,
4-
// }
5-
6-
// module.exports = nextConfig
72

83
import remarkFrontmatter from 'remark-frontmatter'
94
import nextMDX from '@next/mdx'
@@ -12,7 +7,6 @@ const withMDX = nextMDX({
127
extension: /\.mdx?$/,
138
options: {
149
remarkPlugins: [remarkFrontmatter],
15-
// remarkPlugins: [],
1610
rehypePlugins: [],
1711
// If you use `MDXProvider`, uncomment the following line.
1812
providerImportSource: '@mdx-js/react',

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"jest": "^28.1.1",
6767
"jest-environment-jsdom": "^28.1.1",
6868
"lint-staged": "^13.0.0",
69-
"next-mdx-remote": "^4.0.3",
7069
"prettier": "^2.6.2",
7170
"react-syntax-highlighter": "^15.5.0",
7271
"remark-frontmatter": "^4.0.1",

pages/_app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Footer from '../components/footer/Footer'
88
import ConsentBanner from '../components/ConsentBanner'
99
import { DefaultSeo } from 'next-seo'
1010
import { MDXProvider } from '@mdx-js/react'
11-
import MDXcomponents from '../components/mdx/MDXComponents'
11+
import Components from '../components/mdx/Components'
1212

1313
function MyApp({ Component, pageProps }: AppProps) {
1414
return (
@@ -74,7 +74,7 @@ function MyApp({ Component, pageProps }: AppProps) {
7474
/>
7575
<Box p="1.25em" px="5%" mx={{ base: '2rem', md: '6rem', lg: '10rem' }}>
7676
<Header />
77-
<MDXProvider components={MDXcomponents}>
77+
<MDXProvider components={Components}>
7878
<Component {...pageProps} />
7979
</MDXProvider>
8080
<Footer />

pages/getting-started/index.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import fs from 'fs'
1616
import path from 'path'
1717
import matter from 'gray-matter'
18+
import { CONTENT_PATH } from '../../lib/constants'
1819

1920
interface LessonProps {
2021
lessons: {
@@ -221,22 +222,27 @@ const GettingStarted: React.FC<LessonProps> = ({ lessons }) => {
221222
export default GettingStarted
222223

223224
export const getStaticProps = async () => {
224-
const directories = fs.readdirSync(path.join('lessons'))
225+
const contentDir = path.join(CONTENT_PATH)
226+
const directories = fs.readdirSync(path.join(contentDir))
225227
const lessons: object[] = []
226-
directories.reverse().map((filename) => {
227-
fs.readdirSync(path.join('lessons', filename)).map((file) => {
228-
const markdownWithMeta = fs.readFileSync(
229-
path.join('lessons', filename, file),
230-
'utf-8',
231-
)
228+
directories.reverse().map((folder) => {
229+
if (fs.lstatSync(path.join(contentDir, folder)).isDirectory()) {
230+
fs.readdirSync(path.join(contentDir, folder)).map((file) => {
231+
if (!fs.lstatSync(path.join(contentDir, folder, file)).isDirectory()) {
232+
const markdownWithMeta = fs.readFileSync(
233+
path.join(contentDir, folder, file),
234+
'utf-8',
235+
)
232236

233-
const { data: frontMatter } = matter(markdownWithMeta)
234-
lessons.push({
235-
path: filename,
236-
frontMatter,
237-
slug: file.replace('.mdx', ''),
237+
const { data: frontMatter } = matter(markdownWithMeta)
238+
lessons.push({
239+
path: folder,
240+
frontMatter,
241+
slug: file.replace('.mdx', ''),
242+
})
243+
}
238244
})
239-
})
245+
}
240246
})
241247
return {
242248
props: {

pages/lessons/[lesson]/[slug].tsx

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

0 commit comments

Comments
 (0)