Skip to content

Commit 7d1ad5c

Browse files
committed
Install the same version of GitHub Slugger as Nextra
1 parent 7ddee8b commit 7d1ad5c

File tree

4 files changed

+53
-48
lines changed

4 files changed

+53
-48
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"codemirror-graphql": "1.3.2",
3434
"date-fns": "^2.30.0",
3535
"fast-glob": "^3.3.3",
36+
"github-slugger": "2.0.0",
3637
"graphql": "16.10.0",
3738
"gray-matter": "^4.0.3",
3839
"hast-util-to-string": "3.0.1",

pnpm-lock.yaml

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/conf/2025/code-of-conduct/page.tsx

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,32 @@ export const metadata: Metadata = {
1515
title: "Code of Conduct | GraphQLConf 2025",
1616
}
1717

18+
const components = {
19+
a: (props: React.AnchorHTMLAttributes<HTMLAnchorElement>) => {
20+
return (
21+
<Anchor
22+
{...props}
23+
href={props.href ?? ""}
24+
className={clsx(props.className, "typography-link")}
25+
/>
26+
)
27+
},
28+
ul: (props: React.HTMLAttributes<HTMLUListElement>) => {
29+
return <ul {...props} className={clsx(props.className, "-mt-6")} />
30+
},
31+
Callout: (props: React.HTMLAttributes<HTMLDivElement>) => {
32+
return (
33+
<div
34+
{...props}
35+
className={clsx(
36+
props.className,
37+
"gql-prose-inner -mx-4 w-fit border border-neu-300 bg-neu-50 p-4 dark:border-neu-100 dark:bg-neu-50/50 max-md:border-x-0 xl:my-4",
38+
)}
39+
/>
40+
)
41+
},
42+
}
43+
1844
export default function ResourcesPage() {
1945
return (
2046
<>
@@ -39,19 +65,19 @@ export default function ResourcesPage() {
3965
</Button>
4066
</Hero>
4167
<main className="gql-all-anchors-focusable gql-conf-navbar-strip text-neu-900 before:bg-white/40 before:dark:bg-blk/30">
42-
<div className="gql-conf-container gql-conf-section gql-prose xl:mb-16 xl:mt-8">
68+
<div className="gql-conf-container gql-conf-section xl:mb-16 xl:mt-8">
4369
<ServerComponentMarkdown
4470
markdown={markdown}
4571
extractToc
46-
Wrapper={({ children, data }) => {
72+
render={({ mdx, data }) => {
4773
return (
48-
<div>
49-
<aside className="gql-sticky-aside row-span-8 -mt-1 w-fit sm:max-xl:grid sm:max-xl:grid-cols-2 sm:max-xl:bg-neu-100 sm:max-xl:p-4 dark:sm:max-xl:bg-neu-50/50">
74+
<div className="gql-prose md:max-lg:[&>:not(:first-child)]:mx-4">
75+
<aside className="gql-sticky-aside row-span-8 -mt-1 w-fit sm:max-xl:grid sm:max-xl:grid-cols-2 sm:max-xl:bg-neu-100 sm:max-xl:p-4 dark:sm:max-xl:bg-neu-50/50 xl:max-w-[284px]">
5076
{data.toc.map(({ value, id, depth }) => (
5177
<a
5278
key={id}
5379
data-depth={depth}
54-
className="raw typography-menu block p-4 py-2 text-neu-800 hover:bg-neu-100 hover:text-neu-900 data-[depth=2]:font-semibold dark:hover:bg-neu-50 max-xl:-ml-4 xl:data-[depth=2]:text-lg"
80+
className="raw typography-menu block p-4 py-2 text-neu-800 hover:bg-neu-100 hover:text-neu-900 dark:hover:bg-neu-50 max-xl:-ml-4"
5581
style={{
5682
paddingLeft: (depth - 2) * 16 + 16,
5783
}}
@@ -61,37 +87,10 @@ export default function ResourcesPage() {
6187
</a>
6288
))}
6389
</aside>
64-
{children}
90+
{mdx({ components })}
6591
</div>
6692
)
6793
}}
68-
components={{
69-
a: (props: React.AnchorHTMLAttributes<HTMLAnchorElement>) => {
70-
return (
71-
<Anchor
72-
{...props}
73-
href={props.href ?? ""}
74-
className={clsx(props.className, "typography-link")}
75-
/>
76-
)
77-
},
78-
ul: (props: React.HTMLAttributes<HTMLUListElement>) => {
79-
return (
80-
<ul {...props} className={clsx(props.className, "-mt-6")} />
81-
)
82-
},
83-
Callout: (props: React.HTMLAttributes<HTMLDivElement>) => {
84-
return (
85-
<div
86-
{...props}
87-
className={clsx(
88-
props.className,
89-
"gql-prose-inner -mx-4 w-fit border border-neu-300 bg-neu-50 p-4 dark:border-neu-100 dark:bg-neu-50/50 xl:my-4",
90-
)}
91-
/>
92-
)
93-
},
94-
}}
9594
/>
9695
</div>
9796
</main>

src/app/conf/_components/server-component-markdown.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as runtime from "react/jsx-runtime"
66
import { Root, Element } from "hast"
77
import { visit } from "unist-util-visit"
88
import { toString } from "hast-util-to-string"
9-
// @ts-expect-error
109
import Slugger from "github-slugger"
1110

1211
/**
@@ -18,17 +17,19 @@ import Slugger from "github-slugger"
1817
*/
1918
export async function ServerComponentMarkdown({
2019
markdown,
21-
components = {},
2220
extractToc = false,
23-
Wrapper = ({ children }) => children,
21+
render = ({ mdx }) => mdx({}),
2422
}: {
2523
markdown: string
26-
components?: Record<string, React.ComponentType>
2724
extractToc?: boolean
28-
Wrapper?: React.ComponentType<{
29-
children: React.ReactNode
25+
render?: (props: {
26+
mdx: ({
27+
components,
28+
}: {
29+
components?: MdxComponents
30+
}) => React.AwaitedReactNode
3031
data: { toc: TableOfContents }
31-
}>
32+
}) => React.AwaitedReactNode
3233
}) {
3334
try {
3435
const rehypePlugins = extractToc ? [rehypeExtractTableOfContents] : []
@@ -40,12 +41,12 @@ export async function ServerComponentMarkdown({
4041
recmaPlugins: [],
4142
})
4243

43-
const { default: Mdx } = await run(String(vfile), {
44+
const { default: mdx } = await run(vfile, {
4445
...runtime,
4546
baseUrl: import.meta.url,
4647
})
4748

48-
return <Wrapper data={vfile.data}>{Mdx({ components })}</Wrapper>
49+
return render({ data: vfile.data, mdx })
4950
} catch (error) {
5051
console.error(error)
5152
return (
@@ -55,6 +56,7 @@ export async function ServerComponentMarkdown({
5556
}
5657

5758
type TableOfContents = Array<{ value: string; id: string; depth: number }>
59+
type MdxComponents = Record<string, React.ComponentType>
5860

5961
/**
6062
* Nextra has a built-in plugin like this, but it also steals the heading contents

0 commit comments

Comments
 (0)