Skip to content

Commit 6ac2040

Browse files
committed
Add MDX page templates
1 parent 9e3e109 commit 6ac2040

File tree

8 files changed

+131
-9
lines changed

8 files changed

+131
-9
lines changed

website/mdx-components.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { useMDXComponents as getDocsMDXComponents } from '@theguild/components/server';
2+
import { docsMDXComponents } from './src/components/docs-mdx-components';
3+
4+
export const useMDXComponents = () => {
5+
return getDocsMDXComponents(docsMDXComponents);
6+
};

website/next.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ export default withGuildDocs({
66
eslint: {
77
ignoreDuringBuilds: true,
88
},
9-
experimental: {
10-
typedRoutes: true,
11-
},
129
eslint: {
1310
ignoreDuringBuilds: true,
1411
turbo: {

website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"start": "next start"
1212
},
1313
"dependencies": {
14-
"@theguild/components": "8.0.0-alpha-20241206100653-e3101f5b94712d9fed27f767b4190b4167baa82e",
14+
"@theguild/components": "8.0.0-alpha-20241210180007-0c38d3328d098a4dbb572c0142b7801d993cee1f",
1515
"next": "^15.0.0",
1616
"next-sitemap": "^4.2.3",
1717
"pagefind": "^1.2.0",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
import { generateStaticParamsFor, importPage } from 'nextra/pages';
3+
import { NextPageProps } from '@theguild/components';
4+
import { useMDXComponents } from '../../../../../mdx-components.js';
5+
import { ConfiguredGiscus } from '../../../../components/configured-giscus';
6+
7+
/**
8+
* You might have an urge to try to refactor this to a separate file and reuse between product-updates and docs.
9+
* I had the same urge. It's absurdly finicky. I warned you.
10+
*
11+
* BTW, even if we moved the product updates to page.mdx pattern, we still need this nesting to fix links in sidebar.
12+
*/
13+
export const generateStaticParams = async () => {
14+
const pages = await generateStaticParamsFor('mdxPath')();
15+
return pages
16+
.map(page => (page.mdxPath[0] === 'docs' ? { mdxPath: page.mdxPath.slice(1) } : null))
17+
.filter(Boolean);
18+
};
19+
20+
export async function generateMetadata(props: NextPageProps<'...mdxPath'>) {
21+
const params = await props.params;
22+
const { metadata } = await importPage(['docs', ...(params.mdxPath || [])]);
23+
return metadata;
24+
}
25+
26+
const Wrapper = useMDXComponents().wrapper;
27+
28+
export default async function Page(props: NextPageProps<'...mdxPath'>) {
29+
const params = await props.params;
30+
31+
const result = await importPage(['docs', ...(params.mdxPath || [])]);
32+
const { default: MDXContent, toc, metadata } = result;
33+
34+
return (
35+
<Wrapper toc={toc} metadata={metadata}>
36+
<MDXContent params={params} />
37+
<ConfiguredGiscus />
38+
</Wrapper>
39+
);
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
import { generateStaticParamsFor, importPage } from 'nextra/pages';
3+
import { NextPageProps } from '@theguild/components';
4+
import { useMDXComponents } from '../../../../../mdx-components.js';
5+
import { ConfiguredGiscus } from '../../../../components/configured-giscus';
6+
7+
/**
8+
* You might have an urge to try to refactor this to a separate file and reuse between product-updates and docs.
9+
* I had the same urge. It's absurdly finicky. I warned you.
10+
*
11+
* BTW, even if we moved the product updates to page.mdx pattern, we still need this nesting to fix links in sidebar.
12+
*/
13+
export const generateStaticParams = async () => {
14+
const pages = await generateStaticParamsFor('mdxPath')();
15+
return pages
16+
.map(page => (page.mdxPath[0] === 'docs' ? { mdxPath: page.mdxPath.slice(1) } : null))
17+
.filter(Boolean);
18+
};
19+
20+
export async function generateMetadata(props: NextPageProps<'...mdxPath'>) {
21+
const params = await props.params;
22+
const { metadata } = await importPage(['docs', ...(params.mdxPath || [])]);
23+
return metadata;
24+
}
25+
26+
const Wrapper = useMDXComponents().wrapper;
27+
28+
export default async function Page(props: NextPageProps<'...mdxPath'>) {
29+
const params = await props.params;
30+
31+
const result = await importPage(['docs', ...(params.mdxPath || [])]);
32+
const { default: MDXContent, toc, metadata } = result;
33+
34+
return (
35+
<Wrapper toc={toc} metadata={metadata}>
36+
<MDXContent params={params} />
37+
<ConfiguredGiscus />
38+
</Wrapper>
39+
);
40+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use client';
2+
3+
import { usePathname } from 'next/navigation';
4+
import { Giscus } from '@theguild/components';
5+
6+
export function ConfiguredGiscus() {
7+
const route = usePathname();
8+
9+
return (
10+
<Giscus
11+
// ensure giscus is reloaded when client side route is changed
12+
key={route}
13+
repo="ardatan/graphql-mesh"
14+
repoId="MDEwOlJlcG9zaXRvcnkyMzM1OTc1MTc="
15+
category="Docs Discussions"
16+
categoryId="DIC_kwDODexqTc4CSDDQ"
17+
mapping="pathname"
18+
/>
19+
);
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies
2+
import { Anchor } from 'nextra/components';
3+
import { cn } from '@theguild/components';
4+
5+
export const Link: typeof Anchor = ({ className, ...props }) => {
6+
return (
7+
<Anchor
8+
// we remove `text-underline-position` from default Nextra link styles
9+
className={cn(
10+
'hive-focus dark:text-primary/90 dark:focus-visible:ring-primary/50 -mx-1 -my-0.5 rounded px-1 py-0.5 font-medium text-blue-700 underline underline-offset-[2px] hover:no-underline focus-visible:no-underline focus-visible:ring-current focus-visible:ring-offset-blue-200',
11+
className,
12+
)}
13+
{...props}
14+
/>
15+
);
16+
};
17+
export const docsMDXComponents = {
18+
a: Link,
19+
};

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12429,9 +12429,9 @@ __metadata:
1242912429
languageName: node
1243012430
linkType: hard
1243112431

12432-
"@theguild/components@npm:8.0.0-alpha-20241206100653-e3101f5b94712d9fed27f767b4190b4167baa82e":
12433-
version: 8.0.0-alpha-20241206100653-e3101f5b94712d9fed27f767b4190b4167baa82e
12434-
resolution: "@theguild/components@npm:8.0.0-alpha-20241206100653-e3101f5b94712d9fed27f767b4190b4167baa82e"
12432+
"@theguild/components@npm:8.0.0-alpha-20241210180007-0c38d3328d098a4dbb572c0142b7801d993cee1f":
12433+
version: 8.0.0-alpha-20241210180007-0c38d3328d098a4dbb572c0142b7801d993cee1f
12434+
resolution: "@theguild/components@npm:8.0.0-alpha-20241210180007-0c38d3328d098a4dbb572c0142b7801d993cee1f"
1243512435
dependencies:
1243612436
"@giscus/react": "npm:3.0.0"
1243712437
"@next/bundle-analyzer": "npm:15.0.3"
@@ -12449,7 +12449,7 @@ __metadata:
1244912449
next: ^13 || ^14 || ^15.0.0
1245012450
react: ^18.2.0
1245112451
react-dom: ^18.2.0
12452-
checksum: 10c0/c627f32a21a08f8d54d270dacd3c5fcfe97a37f58513cf3d4b97539ce091217a83b7251c01e113a862eb48e731eccd6c150635645e456856f904e2048ee36479
12452+
checksum: 10c0/3b20b282cd98a97be01c6a2463822d25be95329dfa1299387a990659f505cd7cf1c24468682fe24d5b578783158342249892302996e19f1ce111ce4cead8caff
1245312453
languageName: node
1245412454
linkType: hard
1245512455

@@ -36726,7 +36726,7 @@ __metadata:
3672636726
version: 0.0.0-use.local
3672736727
resolution: "website@workspace:website"
3672836728
dependencies:
36729-
"@theguild/components": "npm:8.0.0-alpha-20241206100653-e3101f5b94712d9fed27f767b4190b4167baa82e"
36729+
"@theguild/components": "npm:8.0.0-alpha-20241210180007-0c38d3328d098a4dbb572c0142b7801d993cee1f"
3673036730
"@theguild/tailwind-config": "npm:0.6.1"
3673136731
"@types/node": "npm:22.10.1"
3673236732
"@types/react": "npm:19.0.1"

0 commit comments

Comments
 (0)