---
title: "Next.js"
description: "The reference Next.js app that exercises collections, trees, items, and relations."
canonical: "https://www.qino.works/docs/examples/next-js"
---

# Next.js

> The reference Next.js app that exercises collections, trees, items, and relations.

The canonical qino example is a Next.js App Router site. It lives in the repository at [`examples/next-js`](https://github.com/CharlyMartin/qino/tree/main/examples/next-js).

## What it covers

- **Collections**: `posts` (`.md`), `authors` (`.json`), and `categories` (`.json`).
- **Relations**: `author` and `category` on posts; `featured-posts[*]` on the home item.
- **Markdown stats**: `markdown.stats` on posts, with a reading time derived from `_stats.wordCount` by a local `getReadingTimes` helper.
- **Tree**: a `.mdx` docs tree with nested sections, `_order.json` ordering, and prev/next navigation.
- **Item**: `pages/home.md` with resolved featured posts.
- **CLI**: `qino build` as the `prebuild` script, with `qino/_generated/` gitignored.
- **Agent-ready content**: `pages` on posts and docs, served as page Markdown at each page's Markdown URL and to requests whose `Accept` header lists Markdown first. `llms.txt` and the homepage's `index.md` are built from `src/content/llms.md`, and `index.md` also answers Markdown requests for `/`. Unknown paths get the Markdown 404. See [Next.js](https://www.qino.works/docs/guide/agent-ready-content/next-js).

## Layout

```txt title="Folder structure"
examples/next-js/
  qino/
    index.ts
    collections/{posts,authors,categories}.ts
    trees/docs.ts
    items/home.ts
  src/content/
    posts/*.md
    authors/*.json
    categories/*.json
    docs/**
    pages/home.md
    llms.md                  the llms.txt template
  src/app/
    page.tsx                 home item
    posts/page.tsx           collection listing
    posts/[slug]/page.tsx    getAllSlugs + getEntry
    posts/tags/[tag]/page.tsx        posts filtered by category
    posts/authors/[author]/page.tsx  posts filtered by author
    docs/[...slug]/page.tsx  getTree, getEntry, getPreviousNode, getNextNode
    md/route.ts              the homepage's Markdown, from public/index.md
    md/missing/route.ts      the Markdown 404
    md/posts/route.ts        the posts index page's Markdown
    md/posts/[slug]/route.ts         a post's page Markdown
    md/docs/route.ts                 the docs index page's Markdown
    md/docs/[...slug]/route.ts       a docs page's Markdown
  next.config.ts             beforeFiles and fallback rewrites to the md/ routes
```

## Key snippets

Static params from a collection:

```ts title="src/app/posts/[slug]/page.tsx"
export async function generateStaticParams() {
  const slugs = await postCollection.getAllSlugs();
  return slugs.map((slug) => ({ slug }));
}
```

A docs page reading structure, content, and neighbors in one go:

```ts title="src/app/docs/[...slug]/page.tsx"
const [nodes, entry, previousNode, nextNode] = await Promise.all([
  docsTree.getTree(),
  docsTree.getEntry(fullSlug),
  docsTree.getPreviousNode(fullSlug),
  docsTree.getNextNode(fullSlug),
]);
```

## Rendering

qino returns raw Markdown. The example renders `.md` posts with `react-markdown` and `.mdx` docs with `next-mdx-remote`, both with `remark-gfm`, `rehype-slug`, `rehype-autolink-headings`, and `rehype-highlight`.

<Callout type="note">
The example on Github lives in a monorepo and imports `@qino/cms` from the workspace, which exposes raw TypeScript, so Next.js must transpile it. Apps installing `@qino/cms` from `npm` get compiled JavaScript and don't need to add it to `transpilePackages` in `nextConfig`.

</Callout>

## Run it

```sh title="Terminal"
pnpm install
pnpm --filter next-js dev
```
