Here’s how to set up Ariadocs with the Pages Router in just a few steps.
pnpm add @ariadocs/react
Create a config file in your project root:
// ariadocs.ts
import { type DocsConfigLocal, LocalDocs } from "@ariadocs/react/core";
import {
recommendedRehypePlugins,
recommendedRemarkPlugins,
} from "@ariadocs/react/utils";
export const docsConfig: DocsConfigLocal = {
contentDir: "/contents/docs",
rehypePlugins: recommendedRehypePlugins, // optional
remarkPlugins: recommendedRemarkPlugins, //optional
};
type F = { title: string };
export const docs = new LocalDocs<F>(docsConfig);
In the Pages Router, use a catch-all route:
// pages/docs/[[...path]].tsx
import { docs } from "@/ariadocs";
export default function Docs({
MDX,
frontmatter,
}: {
MDX: React.ReactNode;
frontmatter: { title: string };
}) {
return (
<section>
<title>{frontmatter.title}</title>
{MDX}
</section>
);
}
export const getStaticPaths = async () => {
const rawPaths = await docs.pagePaths();
return {
paths: rawPaths.map((str) => ({
params: { path: str.split("/").slice(1) },
})),
fallback: false,
};
};
export const getStaticProp = async ({ params }) => {
const slug = (params?.path as string[]).join("/");
const { MDX, frontmatter } = await docs.parse({ slug });
return { props: { MDX, frontmatter } };
};
Inside your project, add a single doc file:
my-app/
├── pages/
│ └── docs/
│ └── [[...path]].tsx
├── contents/
│ └── docs/
│ └── hello-world.mdx
├── ariadocs.ts
hello-world.mdx
---
title: Hello World
---
# Hello World 👋
Start the dev server:
pnpm dev
Then open 👉 http://localhost:3000/docs/hello-world
You should see your very first doc live! 🎉