Next.js
Serve the docs at a path of a Next.js app with @yaakdoc/next.
@yaakdoc/next serves your yaakdoc site at a path of a Next.js app, such as /docs, in development and in production.
npm i @yaakdoc/nextimport type { NextConfig } from "next";
import { createNextYaakdoc } from "@yaakdoc/next";
const withYaakdoc = createNextYaakdoc({
path: "/docs",
export: "./yaak.json",
config: {
branding: {
title: "Acme API"
},
pages: "per-request",
},
});
const nextConfig: NextConfig = {};
export default withYaakdoc(nextConfig);Add the build output to .gitignore:
public/docscreateNextYaakdoc(options) returns withYaakdoc. You can keep it in a file of its own and import it into next.config.ts. withYaakdoc(nextConfig) accepts an object or a function ((phase, context) => config), like any Next.js config. Next's basePath is respected.
The docs are configured inline, so you don't need a yaakdoc.config.* file. If there is one, config is merged over it. See the options.
How it works
next dev. The yaakdoc dev server starts in a child process, and the docs are proxied to it with rewrites. Editing the export or the theme reloads the page.next build. The docs are prerendered intopublic/<path>and served as static files, so they're deployed with the app, on Vercel or any other host. The build replaces that folder each time, and refuses to touch one that yaakdoc didn't create.next start. The docs are served frompublic/<path>through rewrites.output: "export". The docs are part of the exported site, and no rewrites are added.
Notes
- Trailing slashes. yaakdoc links to
/docs/page/. With Next's defaulttrailingSlash: false, these redirect to/docs/page, which then serves the page. - Not found pages. An unknown page under
/docsshows your app's 404 page.
Options
| Option | Description |
|---|---|
path | Where the docs are served. Default: /docs. It takes precedence over config.base. |
config | yaakdoc config, merged over yaakdoc.config.* if there is one. Paths are relative to cwd. |
export | Path of the Yaak export. Shorthand for config.export. By default, yaakdoc.json, then yaak.json, is looked up in cwd. |
cwd | Project directory. Default: process.cwd(). |
configFile | An explicit config file, or false to not look for one. |
publicDir | A folder copied to the docs' root as is. Default: none, because the app's public/ folder isn't meant for the docs. |