|
| 1 | +import { RemoteContent } from 'nextra/data' |
| 2 | +import { buildDynamicMDX } from 'nextra/remote' |
| 3 | +import { getPageMap } from '@/src/getPageMap' |
| 4 | +import { remarkReplaceLinks } from '@/src/remarkReplaceLinks' |
| 5 | +import { Mermaid } from 'nextra/components' |
| 6 | +import { visit } from 'unist-util-visit' |
| 7 | +import json from '@/remote-files/graph-ts.json' |
| 8 | + |
| 9 | +export const getStaticPaths = () => ({ |
| 10 | + fallback: false, |
| 11 | + paths: json.filePaths.map((filePath) => ({ |
| 12 | + params: { |
| 13 | + slug: filePath.replace(/\.mdx?/, '').split('/'), |
| 14 | + }, |
| 15 | + })), |
| 16 | +}) |
| 17 | + |
| 18 | +export async function getStaticProps({ params }) { |
| 19 | + const { filePaths, user, repo, branch, docsPath } = json |
| 20 | + const paths = params?.slug?.join('/') |
| 21 | + const foundPath = filePaths.find((filePath) => filePath.startsWith(paths)) |
| 22 | + const baseURL = `https://raw.githubusercontent.com/${user}/${repo}/${branch}/${docsPath}${foundPath}` |
| 23 | + const response = await fetch(baseURL) |
| 24 | + const content = await response.text() |
| 25 | + const mdx = await buildDynamicMDX(content, { |
| 26 | + mdxOptions: { |
| 27 | + format: 'md', |
| 28 | + remarkPlugins: [ |
| 29 | + () => (tree, _file, done) => { |
| 30 | + visit(tree, 'link', (node) => { |
| 31 | + if (node.url.startsWith('../')) { |
| 32 | + node.url = node.url.replace('../', `https://github.com/${user}/${repo}/tree/${branch}/`) |
| 33 | + } |
| 34 | + }) |
| 35 | + done() |
| 36 | + }, |
| 37 | + [remarkReplaceLinks, { foundPath, basePath: '/developing/graph-ts/' }], |
| 38 | + ], |
| 39 | + }, |
| 40 | + codeHighlight: false, |
| 41 | + }) |
| 42 | + return { |
| 43 | + props: { |
| 44 | + ...mdx, |
| 45 | + __nextra_pageMap: await getPageMap('en'), |
| 46 | + hideLocaleSwitcher: true, |
| 47 | + remoteFilePath: `https://github.com/${user}/${repo}/tree/${branch}/${docsPath}${foundPath}`, |
| 48 | + }, |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +<RemoteContent components={{ Mermaid }} /> |
0 commit comments