Skip to content

Commit 82ce63a

Browse files
committed
make the mdx setup work
1 parent afc2f86 commit 82ce63a

File tree

18 files changed

+218
-294
lines changed

18 files changed

+218
-294
lines changed

src/_pages/errors/[errorCode].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Fragment, useMemo} from 'react';
22
import {Page} from 'components/Layout/Page';
3-
import {MDXComponents} from 'components/MDX/MDXComponents';
3+
import {MDXComponents} from 'components/MDX/MDXComponentsWrapper';
44
import sidebarLearn from 'sidebarLearn.json';
55
import type {RouteItem} from 'components/Layout/getRouteMeta';
66
import {GetStaticPaths, GetStaticProps, InferGetStaticPropsType} from 'next';

src/app/[[...markdownPath]]/page.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,29 +123,27 @@ export async function generateStaticParams() {
123123
markdownPath: getSegments(file),
124124
}));
125125
}
126-
127126
export default async function WrapperPage({params}) {
128-
const {markdownPath} = params;
127+
const {markdownPath} = await params;
128+
129+
// Get the MDX content and associated data
129130
const {content, toc, meta, languages} = await getPageContent(markdownPath);
130131

131132
const pathname = '/' + (markdownPath?.join('/') || '');
132133
const section = getActiveSection(pathname);
133134
const routeTree = await getRouteTree(section);
134135

135-
const parsedContent = JSON.parse(content, reviveNodeOnClient);
136-
const parsedToc = JSON.parse(toc, reviveNodeOnClient);
137-
136+
// Pass the content and TOC directly, as `getPageContent` should already return them in the correct format
138137
return (
139138
<Page
140-
toc={parsedToc}
139+
toc={toc} // Pass the TOC directly without parsing
141140
routeTree={routeTree}
142141
meta={meta}
143142
section={section}
144143
languages={languages}>
145-
{parsedContent}
144+
{content}
146145
</Page>
147146
);
148147
}
149-
150148
// Configure dynamic segments to be statically generated
151149
export const dynamicParams = false;

src/app/layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export default function RootLayout({children}) {
174174
<ScrollHandler />
175175
<ThemeScript />
176176
<UwuScript />
177+
177178
{children}
178179
</body>
179180
</html>

src/components/MDX/Challenges/Challenges.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
/*
24
* Copyright (c) Facebook, Inc. and its affiliates.
35
*/

src/components/MDX/CodeBlock/CodeBlock.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
/*
24
* Copyright (c) Facebook, Inc. and its affiliates.
35
*/

src/components/MDX/CodeBlock/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
/*
24
* Copyright (c) Facebook, Inc. and its affiliates.
35
*/

src/components/MDX/ErrorDecoder.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import {useEffect, useState} from 'react';
24
import {useErrorDecoderParams} from '../ErrorDecoderContext';
35
import cn from 'classnames';

src/components/MDX/ExpandableExample.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
/*
24
* Copyright (c) Facebook, Inc. and its affiliates.
35
*/

src/components/MDX/LanguagesContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
/*
24
* Copyright (c) Facebook, Inc. and its affiliates.
35
*/

src/components/MDX/MDXComponents.tsx

Lines changed: 116 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
'use client';
1+
// 'use client';
22

33
/*
44
* Copyright (c) Facebook, Inc. and its affiliates.
55
*/
66

7-
import {Children, useContext, useMemo} from 'react';
7+
// import {Children, useContext, useMemo} from 'react';
88
import * as React from 'react';
99
import cn from 'classnames';
1010
import type {HTMLAttributes} from 'react';
@@ -263,99 +263,99 @@ function AuthorCredit({
263263
);
264264
}
265265

266-
const IllustrationContext = React.createContext<{
267-
isInBlock?: boolean;
268-
}>({
269-
isInBlock: false,
270-
});
271-
272-
function Illustration({
273-
caption,
274-
src,
275-
alt,
276-
author,
277-
authorLink,
278-
}: {
279-
caption: string;
280-
src: string;
281-
alt: string;
282-
author: string;
283-
authorLink: string;
284-
}) {
285-
const {isInBlock} = React.useContext(IllustrationContext);
286-
287-
return (
288-
<div className="relative group before:absolute before:-inset-y-16 before:inset-x-0 my-16 mx-0 2xl:mx-auto max-w-4xl 2xl:max-w-6xl">
289-
<figure className="my-8 flex justify-center">
290-
<img
291-
src={src}
292-
alt={alt}
293-
style={{maxHeight: 300}}
294-
className="rounded-lg"
295-
/>
296-
{caption ? (
297-
<figcaption className="text-center leading-tight mt-4">
298-
{caption}
299-
</figcaption>
300-
) : null}
301-
</figure>
302-
{!isInBlock && <AuthorCredit author={author} authorLink={authorLink} />}
303-
</div>
304-
);
305-
}
266+
// const IllustrationContext = React.createContext<{
267+
// isInBlock?: boolean;
268+
// }>({
269+
// isInBlock: false,
270+
// });
271+
272+
// function Illustration({
273+
// caption,
274+
// src,
275+
// alt,
276+
// author,
277+
// authorLink,
278+
// }: {
279+
// caption: string;
280+
// src: string;
281+
// alt: string;
282+
// author: string;
283+
// authorLink: string;
284+
// }) {
285+
// const {isInBlock} = React.useContext(IllustrationContext);
286+
287+
// return (
288+
// <div className="relative group before:absolute before:-inset-y-16 before:inset-x-0 my-16 mx-0 2xl:mx-auto max-w-4xl 2xl:max-w-6xl">
289+
// <figure className="my-8 flex justify-center">
290+
// <img
291+
// src={src}
292+
// alt={alt}
293+
// style={{maxHeight: 300}}
294+
// className="rounded-lg"
295+
// />
296+
// {caption ? (
297+
// <figcaption className="text-center leading-tight mt-4">
298+
// {caption}
299+
// </figcaption>
300+
// ) : null}
301+
// </figure>
302+
// {!isInBlock && <AuthorCredit author={author} authorLink={authorLink} />}
303+
// </div>
304+
// );
305+
// }
306306

307307
const isInBlockTrue = {isInBlock: true};
308308

309-
function IllustrationBlock({
310-
sequential,
311-
author,
312-
authorLink,
313-
children,
314-
}: {
315-
author: string;
316-
authorLink: string;
317-
sequential: boolean;
318-
children: any;
319-
}) {
320-
const imageInfos = Children.toArray(children).map(
321-
(child: any) => child.props
322-
);
323-
const images = imageInfos.map((info, index) => (
324-
<figure key={index}>
325-
<div className="bg-white rounded-lg p-4 flex-1 flex xl:p-6 justify-center items-center my-4">
326-
<img
327-
className="text-primary"
328-
src={info.src}
329-
alt={info.alt}
330-
height={info.height}
331-
/>
332-
</div>
333-
{info.caption ? (
334-
<figcaption className="text-secondary dark:text-secondary-dark text-center leading-tight mt-4">
335-
{info.caption}
336-
</figcaption>
337-
) : null}
338-
</figure>
339-
));
340-
return (
341-
<IllustrationContext.Provider value={isInBlockTrue}>
342-
<div className="relative group before:absolute before:-inset-y-16 before:inset-x-0 my-16 mx-0 2xl:mx-auto max-w-4xl 2xl:max-w-6xl">
343-
{sequential ? (
344-
<ol className="mdx-illustration-block flex">
345-
{images.map((x: any, i: number) => (
346-
<li className="flex-1" key={i}>
347-
{x}
348-
</li>
349-
))}
350-
</ol>
351-
) : (
352-
<div className="mdx-illustration-block">{images}</div>
353-
)}
354-
<AuthorCredit author={author} authorLink={authorLink} />
355-
</div>
356-
</IllustrationContext.Provider>
357-
);
358-
}
309+
// function IllustrationBlock({
310+
// sequential,
311+
// author,
312+
// authorLink,
313+
// children,
314+
// }: {
315+
// author: string;
316+
// authorLink: string;
317+
// sequential: boolean;
318+
// children: any;
319+
// }) {
320+
// const imageInfos = Children.toArray(children).map(
321+
// (child: any) => child.props
322+
// );
323+
// const images = imageInfos.map((info, index) => (
324+
// <figure key={index}>
325+
// <div className="bg-white rounded-lg p-4 flex-1 flex xl:p-6 justify-center items-center my-4">
326+
// <img
327+
// className="text-primary"
328+
// src={info.src}
329+
// alt={info.alt}
330+
// height={info.height}
331+
// />
332+
// </div>
333+
// {info.caption ? (
334+
// <figcaption className="text-secondary dark:text-secondary-dark text-center leading-tight mt-4">
335+
// {info.caption}
336+
// </figcaption>
337+
// ) : null}
338+
// </figure>
339+
// ));
340+
// return (
341+
// <IllustrationContext.Provider value={isInBlockTrue}>
342+
// <div className="relative group before:absolute before:-inset-y-16 before:inset-x-0 my-16 mx-0 2xl:mx-auto max-w-4xl 2xl:max-w-6xl">
343+
// {sequential ? (
344+
// <ol className="mdx-illustration-block flex">
345+
// {images.map((x: any, i: number) => (
346+
// <li className="flex-1" key={i}>
347+
// {x}
348+
// </li>
349+
// ))}
350+
// </ol>
351+
// ) : (
352+
// <div className="mdx-illustration-block">{images}</div>
353+
// )}
354+
// <AuthorCredit author={author} authorLink={authorLink} />
355+
// </div>
356+
// </IllustrationContext.Provider>
357+
// );
358+
// }
359359

360360
type NestedTocRoot = {
361361
item: null;
@@ -388,27 +388,27 @@ function calculateNestedToc(toc: Toc): NestedTocRoot {
388388
return root;
389389
}
390390

391-
function InlineToc() {
392-
const toc = useContext(TocContext);
393-
const root = useMemo(() => calculateNestedToc(toc), [toc]);
394-
if (root.children.length < 2) {
395-
return null;
396-
}
397-
return <InlineTocItem items={root.children} />;
398-
}
399-
400-
function InlineTocItem({items}: {items: Array<NestedTocNode>}) {
401-
return (
402-
<UL>
403-
{items.map((node) => (
404-
<LI key={node.item.url}>
405-
<Link href={node.item.url}>{node.item.text}</Link>
406-
{node.children.length > 0 && <InlineTocItem items={node.children} />}
407-
</LI>
408-
))}
409-
</UL>
410-
);
411-
}
391+
// function InlineToc() {
392+
// const toc = useContext(TocContext);
393+
// const root = useMemo(() => calculateNestedToc(toc), [toc]);
394+
// if (root.children.length < 2) {
395+
// return null;
396+
// }
397+
// return <InlineTocItem items={root.children} />;
398+
// }
399+
400+
// function InlineTocItem({items}: {items: Array<NestedTocNode>}) {
401+
// return (
402+
// <UL>
403+
// {items.map((node) => (
404+
// <LI key={node.item.url}>
405+
// <Link href={node.item.url}>{node.item.text}</Link>
406+
// {node.children.length > 0 && <InlineTocItem items={node.children} />}
407+
// </LI>
408+
// ))}
409+
// </UL>
410+
// );
411+
// }
412412

413413
type TranslationProgress = 'complete' | 'in-progress';
414414

@@ -500,10 +500,10 @@ export const MDXComponents = {
500500
Pitfall,
501501
Deprecated,
502502
Wip,
503-
Illustration,
504-
IllustrationBlock,
503+
// Illustration,
504+
// IllustrationBlock,
505505
Intro,
506-
InlineToc,
506+
// InlineToc,
507507
LanguageList,
508508
LearnMore,
509509
Math,

0 commit comments

Comments
 (0)