Розроблення сайту документації за допомогою Nextra (Next.js документація)
Nextra — це фреймворк документації, побудований на Next.js командою Vercel. Він використовує MDX, підтримує App Router і працює з коробки на Vercel. На відміну від Docusaurus, це повноцінна програма Next.js — ви можете додавати маршрути API, сторінки SSR і будь-які можливості Next.js.
Ініціалізація
npx create-next-app@latest my-docs --typescript --tailwind --app
npm install nextra nextra-theme-docs
next.config.ts
import nextra from 'nextra';
const withNextra = nextra({
theme: 'nextra-theme-docs',
themeConfig: './theme.config.tsx',
defaultShowCopyCode: true,
flexsearch: {
codeblocks: false,
},
staticImage: true,
latex: true,
});
export default withNextra({
reactStrictMode: true,
images: {
remotePatterns: [{ hostname: 'images.unsplash.com' }],
},
});
theme.config.tsx
import { DocsThemeConfig } from 'nextra-theme-docs';
import React from 'react';
const config: DocsThemeConfig = {
logo: (
<span style={{ fontWeight: 700 }}>My Project</span>
),
project: { link: 'https://github.com/my-org/my-project' },
docsRepositoryBase: 'https://github.com/my-org/my-project/blob/main/docs',
footer: {
text: `© ${new Date().getFullYear()} My Company`,
},
useNextSeoProps() {
return {
titleTemplate: '%s – My Project',
};
},
primaryHue: { dark: 210, light: 212 },
navigation: { prev: true, next: true },
toc: {
backToTop: true,
float: true,
},
editLink: { text: 'Edit this page on GitHub' },
feedback: { content: 'Question? Give us feedback →' },
sidebar: {
titleComponent: ({ title, type }) => (
type === 'separator' ? (
<span style={{ textTransform: 'uppercase', fontSize: '11px', fontWeight: 600 }}>
{title}
</span>
) : <>{title}</>
),
defaultMenuCollapseLevel: 1,
autoCollapse: true,
},
};
export default config;
Структура файлів
app/
├── layout.tsx
└── [[...mdxPath]]/
└── page.tsx # catch-all для MDX-файлів
content/
├── _meta.json # порядок і заголовки навігації
├── index.mdx # головна сторінка
├── guide/
│ ├── _meta.json
│ ├── installation.mdx
│ └── configuration.mdx
└── api/
├── _meta.json
└── reference.mdx
// content/_meta.json
{
"index": "Introduction",
"guide": {
"title": "Guide",
"type": "folder"
},
"api": {
"title": "API Reference",
"type": "folder"
},
"changelog": "Changelog",
"---": { "type": "separator" },
"github_link": {
"title": "GitHub ↗",
"href": "https://github.com/my-org/my-project",
"newWindow": true
}
}
MDX з компонентами React
---
title: API Reference
---
import { Callout, Tabs, Tab } from 'nextra/components';
# API Reference
<Callout type="warning">
Breaking change in v2.0: the `apiKey` parameter was renamed to `key`.
</Callout>
<Tabs items={['cURL', 'JavaScript', 'Python']}>
<Tab>
```bash
curl https://api.myproject.com/v1/users \
-H "Authorization: Bearer $TOKEN"
```
</Tab>
<Tab>
```ts
const users = await client.users.list();
```
</Tab>
<Tab>
```python
users = client.users.list()
```
</Tab>
</Tabs>
Розгортання на Vercel
vercel --prod
# Nextra автоматично оптимізується для Vercel Edge Network
Налаштування сайту документації Nextra займає 2–3 дні.







