Nextra’s file-system routing is great for content you manage locally, but many projects need to pull MDX from an external source — a CMS, a GitHub repository, or a remote API. Nextra provides first-class support for this pattern through theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/shuding/nextra/llms.txt
Use this file to discover all available pages before exploring further.
compileMdx function and the MDXRemote component, which together let you fetch, compile, and render remote Markdown at build time with full support for syntax highlighting, Nextra components, and table of contents extraction.
Core APIs
compileMdx
Compiles a raw MDX string into executable JavaScript on the server side.
Imported from
nextra/compile.MDXRemote
A React component that renders a pre-compiled MDX string in the browser.
Imported from
nextra/mdx-remote.fetchFilePathsFromGitHub
Fetches a list of file paths from a GitHub repository tree for use in
dynamic routes. Imported from
nextra/fetch-filepaths-from-github.convertToPageMap
Converts a flat list of file paths into a Nextra page map structure.
Imported from
nextra/page-map.Basic Remote Content Page
The simplest remote content pattern fetches Markdown from a URL, compiles it, and renders it — all at request time (or build time withgenerateStaticParams).
app/remote/page.tsx
compileMdx returns a Promise<string> — the compiled JavaScript string.
Pass this string directly to the MDXRemote component via its compiledSource prop.
MDXRemote evaluates it safely at render time.Dynamic Routes from a GitHub Repository
For documentation hosted on GitHub, Nextra providesfetchFilePathsFromGitHub to discover available files, and convertToPageMap plus mergeMetaWithPageMap to build the sidebar structure.
Use
fetchFilePathsFromGitHub to query the GitHub API and write a JSON cache of available
MDX file paths. This is typically run as a prebuild script so the data is available
at build time:import { fetchFilePathsFromGitHub } from 'nextra/fetch-filepaths-from-github'
await fetchFilePathsFromGitHub({
user: 'graphql-hive',
repo: 'graphql-eslint',
branch: 'main',
docsPath: 'website/src/pages/docs/',
outputPath: './remote-paths.json'
})
The function calls
https://api.github.com/repos/{user}/{repo}/git/trees/{branch}?recursive=1,
filters to the specified docsPath, and writes the list of .md/.mdx paths to
outputPath.Use
convertToPageMap to turn the flat file path list into a Nextra page map tree,
then use mergeMetaWithPageMap to customize sidebar titles and ordering:import { notFound } from 'next/navigation'
import { compileMdx } from 'nextra/compile'
import { evaluate } from 'nextra/evaluate'
import {
convertToPageMap,
mergeMetaWithPageMap,
normalizePageMap
} from 'nextra/page-map'
const user = 'graphql-hive'
const repo = 'graphql-eslint'
const branch = '34b722a2a520599ce06a4ddcccc9623b76434089'
const docsPath = 'website/src/pages/docs/'
const filePaths = [
'configs.mdx',
'custom-rules.mdx',
'getting-started.mdx',
'getting-started/parser-options.mdx',
'getting-started/parser.mdx',
'index.mdx'
]
const { mdxPages, pageMap: _pageMap } = convertToPageMap({
filePaths,
basePath: 'docs'
})
// Customize sidebar titles and ordering
const eslintPageMap = mergeMetaWithPageMap(_pageMap[0]!, {
index: 'Introduction',
'getting-started': {
items: {
index: 'Overview',
'parser-options': '',
parser: ''
}
},
configs: '',
'custom-rules': ''
})
export const pageMap = normalizePageMap(eslintPageMap)
Add the page component that fetches each file’s content from GitHub at build time and
renders it with
compileMdx and evaluate:type PageProps = Readonly<{
params: Promise<{ slug?: string[] }>
}>
export default async function Page(props: PageProps) {
const params = await props.params
const route = params.slug?.join('/') ?? ''
const filePath = mdxPages[route]
if (!filePath) {
notFound()
}
const response = await fetch(
`https://raw.githubusercontent.com/${user}/${repo}/${branch}/${docsPath}${filePath}`
)
const data = await response.text()
const rawJs = await compileMdx(data, { filePath })
const { default: MDXContent, toc, metadata } = evaluate(rawJs, components)
return (
<Wrapper toc={toc} metadata={metadata}>
<MDXContent />
</Wrapper>
)
}
export function generateStaticParams() {
return Object.keys(mdxPages).map(route => ({
slug: route ? route.split('/') : undefined
}))
}
Merge the remote page map into the main Nextra page map in your
app/layout.tsx so the
remote pages appear in the sidebar and mobile navigation:MDXRemote Component API
The MDXRemote component accepts three props:
| Prop | Type | Description |
|---|---|---|
compiledSource | string | Required. The compiled JS string returned by compileMdx(). |
components | MDXComponents | Optional map of name → component available inside the MDX. |
scope | object | Optional variables available as identifiers inside the MDX content. |
compileMdx Function API
compileMdx accepts the raw MDX string and an optional options object, and returns a Promise<string>:
fetchFilePathsFromGitHub API
outputPath containing:
The GitHub API has rate limits for unauthenticated requests (60/hour). For CI environments,
set a
GITHUB_TOKEN environment variable to increase the limit to 5,000/hour.
fetchFilePathsFromGitHub logs an error and exits gracefully if the rate limit is exceeded.