Next.js
Setup Hanzo Docs on Next.js.
Prerequisite
Before continuing, make sure you have configured:
- Next.js 16.
- Tailwind CSS 4.
We will use Hanzo Docs MDX as a content source, you can configure it first:
Installation
npm i @hanzo/docs-mdx @hanzo/docs-core @types/mdxCreate the configuration file:
import { defineDocs, defineConfig } from '@hanzo/docs-mdx/config';
export const docs = defineDocs({
dir: 'content/docs',
});
export default defineConfig();Add the plugin to Next.js config:
import { createMDX } from '@hanzo/docs-mdx/next';
/** @type {import('next').NextConfig} */
const config = {
reactStrictMode: true,
};
const withMDX = createMDX({
// customise the config file path
// configPath: "source.config.ts"
});
export default withMDX(config);ESM Only
Hanzo Docs MDX is ESM-only, it's recommended to use next.config.mjs for accurate ESM resolution.
For TypeScript config file, it requires Native Node.js TypeScript Resolver, you can see Next.js docs for details.
Setup an import alias (recommended):
{
"compilerOptions": {
"paths": {
"@hanzo/docs-mdx:collections/*": [".source/*"]
}
}
}Integrate with Hanzo Docs
You can create a lib/source.ts file and obtain Hanzo Docs source from the docs collection output.
import { docs } from '@hanzo/docs-mdx:collections/server';
import { loader } from '@hanzo/docs-core/source';
export const source = loader({
baseUrl: '/docs',
source: docs.toFumadocsSource(),
});The .source folder will be generated when you run next dev or next build.
Done
You can now write content in content/docs folder.
Good to Know
Hanzo Docs also supports other content sources, including Content Collections and headless CMS.
Getting Started
npm i @hanzo/docs-base-ui @hanzo/docs-coreRoot Layout
Wrap the entire application inside Root Provider, and add required styles to body.
import { RootProvider } from '@hanzo/docs/ui/provider/next';
import type { ReactNode } from 'react';
export default function Layout({ children }: { children: ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<body
// required styles
className="flex flex-col min-h-screen"
>
<RootProvider>{children}</RootProvider>
</body>
</html>
);
}Styles
Add the following Tailwind CSS styles to global.css.
@import 'tailwindcss';
@import '@hanzo/docs/ui/css/neutral.css';
@import '@hanzo/docs/ui/css/preset.css';It doesn't come with a default font, you may choose one from next/font.
Routes
Create a lib/layout.shared.tsx file to put the shared options for our layouts.
import type { BaseLayoutProps } from '@hanzo/docs/ui/layouts/shared';
export function baseOptions(): BaseLayoutProps {
return {
nav: {
title: 'My App',
},
};
}Create the following files & routes:
import defaultMdxComponents from '@hanzo/docs/ui/mdx';
import type { MDXComponents } from 'mdx/types';
export function getMDXComponents(components?: MDXComponents): MDXComponents {
return {
...defaultMdxComponents,
...components,
};
}The search is powered by Orama, learn more about Document Search.
Finish
You can start the dev server and create MDX files.
---
title: Hello World
---
## Introduction
I love Anime.How is this guide?
Last updated on
