-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
131 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useMDXComponents as getDocsMDXComponents } from '@theguild/components/server'; | ||
import { docsMDXComponents } from './src/components/docs-mdx-components'; | ||
|
||
export const useMDXComponents = () => { | ||
return getDocsMDXComponents(docsMDXComponents); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
website/src/app/(content-pages)/docs/[[...mdxPath]]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import { generateStaticParamsFor, importPage } from 'nextra/pages'; | ||
import { NextPageProps } from '@theguild/components'; | ||
import { useMDXComponents } from '../../../../../mdx-components.js'; | ||
import { ConfiguredGiscus } from '../../../../components/configured-giscus'; | ||
|
||
/** | ||
* You might have an urge to try to refactor this to a separate file and reuse between product-updates and docs. | ||
* I had the same urge. It's absurdly finicky. I warned you. | ||
* | ||
* BTW, even if we moved the product updates to page.mdx pattern, we still need this nesting to fix links in sidebar. | ||
*/ | ||
export const generateStaticParams = async () => { | ||
const pages = await generateStaticParamsFor('mdxPath')(); | ||
return pages | ||
.map(page => (page.mdxPath[0] === 'docs' ? { mdxPath: page.mdxPath.slice(1) } : null)) | ||
.filter(Boolean); | ||
}; | ||
|
||
export async function generateMetadata(props: NextPageProps<'...mdxPath'>) { | ||
const params = await props.params; | ||
const { metadata } = await importPage(['docs', ...(params.mdxPath || [])]); | ||
return metadata; | ||
} | ||
|
||
const Wrapper = useMDXComponents().wrapper; | ||
|
||
export default async function Page(props: NextPageProps<'...mdxPath'>) { | ||
const params = await props.params; | ||
|
||
const result = await importPage(['docs', ...(params.mdxPath || [])]); | ||
const { default: MDXContent, toc, metadata } = result; | ||
|
||
return ( | ||
<Wrapper toc={toc} metadata={metadata}> | ||
<MDXContent params={params} /> | ||
<ConfiguredGiscus /> | ||
</Wrapper> | ||
); | ||
} |
40 changes: 40 additions & 0 deletions
40
website/src/app/(content-pages)/v1/[[...mdxPath]]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import { generateStaticParamsFor, importPage } from 'nextra/pages'; | ||
import { NextPageProps } from '@theguild/components'; | ||
import { useMDXComponents } from '../../../../../mdx-components.js'; | ||
import { ConfiguredGiscus } from '../../../../components/configured-giscus'; | ||
|
||
/** | ||
* You might have an urge to try to refactor this to a separate file and reuse between product-updates and docs. | ||
* I had the same urge. It's absurdly finicky. I warned you. | ||
* | ||
* BTW, even if we moved the product updates to page.mdx pattern, we still need this nesting to fix links in sidebar. | ||
*/ | ||
export const generateStaticParams = async () => { | ||
const pages = await generateStaticParamsFor('mdxPath')(); | ||
return pages | ||
.map(page => (page.mdxPath[0] === 'docs' ? { mdxPath: page.mdxPath.slice(1) } : null)) | ||
.filter(Boolean); | ||
}; | ||
|
||
export async function generateMetadata(props: NextPageProps<'...mdxPath'>) { | ||
const params = await props.params; | ||
const { metadata } = await importPage(['docs', ...(params.mdxPath || [])]); | ||
return metadata; | ||
} | ||
|
||
const Wrapper = useMDXComponents().wrapper; | ||
|
||
export default async function Page(props: NextPageProps<'...mdxPath'>) { | ||
const params = await props.params; | ||
|
||
const result = await importPage(['docs', ...(params.mdxPath || [])]); | ||
const { default: MDXContent, toc, metadata } = result; | ||
|
||
return ( | ||
<Wrapper toc={toc} metadata={metadata}> | ||
<MDXContent params={params} /> | ||
<ConfiguredGiscus /> | ||
</Wrapper> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use client'; | ||
|
||
import { usePathname } from 'next/navigation'; | ||
import { Giscus } from '@theguild/components'; | ||
|
||
export function ConfiguredGiscus() { | ||
const route = usePathname(); | ||
|
||
return ( | ||
<Giscus | ||
// ensure giscus is reloaded when client side route is changed | ||
key={route} | ||
repo="ardatan/graphql-mesh" | ||
repoId="MDEwOlJlcG9zaXRvcnkyMzM1OTc1MTc=" | ||
category="Docs Discussions" | ||
categoryId="DIC_kwDODexqTc4CSDDQ" | ||
mapping="pathname" | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { Anchor } from 'nextra/components'; | ||
import { cn } from '@theguild/components'; | ||
|
||
export const Link: typeof Anchor = ({ className, ...props }) => { | ||
return ( | ||
<Anchor | ||
// we remove `text-underline-position` from default Nextra link styles | ||
className={cn( | ||
'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', | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
export const docsMDXComponents = { | ||
a: Link, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters