Manual Installation
Manual Installation of Docstra in your existing Next.js project.
Follow the Steps
Follow these steps to set up Docstra in your project.
1. Install Docstra:
Install Docstra using your preferred package manager:
Terminal1npm install docstra
Note: Note: Docstra currently supports only Next.js. Official documentation for other frameworks will be added soon.
2. Configure Docstra:
Create a docstra.config.ts file in your project’s root directory and add your configuration:
docstra.config.ts1import { defineDocstraConfig } from "docstra/config";23export default defineDocstraConfig({4 siteName: "Docstra",5 githubRepo: "https://github.com/sudhucodes/docstra",6 contentDir: "app/docs/content",7 editOnGithub: {8 owner: "sudhucodes",9 repo: "docstra",10 path: "docs/content",11 },12 feedback: {13 enabled: true,14 formSyncFormID: "69c728a1-ccd2-4dab-a9f7-bb52baeb4d31",15 },16 navbar: {17 logo: {18 link: "/",19 src: "/brand/logo.svg",20 alt: "Logo",21 className: "h-8 w-auto",22 },23 links: [24 { name: "Guides", href: "/docs/guides" },25 { name: "Examples", href: "/docs/examples" },26 ],27 },28 sidebar: {29 links: [30 {31 section: 'Section 1',32 items: [33 {34 name: 'Link 1',35 href: '/docs/link-1',36 icon: '<Any-Lucide-Icon>'37 },38 {39 name: 'Link 2',40 href: '/docs/link-2',41 },42 ],43 },44 {45 section: 'Section 2',46 items: [47 { name: 'Link 3', href: '/docs/link-3' },48 ],49 },50 ],51 },52});
3. Create Source Entry:
- Create a
libfolder inside the app directory - Inside
lib, create asource.tsfile - Paste the following code:
lib/source.ts1import { docs } from "@/.docstra/index";2import { createSource } from "docstra/server";34export const source = createSource(docs);
This enables dynamic routing for all your documentation pages.
4. Create the Components Entry:
- Create a
mdx-components.tsxfile inside the app directory - Paste the following code:
mdx-components.tsx1import { defaultMdxComponents } from "docstra/server";2import { DocstraCodeBlock } from "docstra";34export function useMDXComponents() {5 return {6 ...defaultMdxComponents,7 code: DocstraCodeBlock8 };9}
5. Create the Docs Route:
- Create a
docsfolder inside the app directory - Inside
docs, create a folder named[[...slug]] - Inside that folder, create a
page.tsxfile
app/docs/[[...slug]]/page.tsx1import docstraConfig from "@/docstra.config";2import { useMDXComponents } from "@/mdx-components";3import {4 DocstraBody,5 DocstraHeader,6 DocstraPage,7 DocstraProvider,8} from "docstra";910import { source } from "@/lib/source";11import { notFound } from "next/navigation";1213export default async function Page({ params }: {14 params: Promise<{ slug?: string[] }>15}) {16 const { slug } = await params17 const page = source.getPage(slug);18 if (!page) return notFound();1920 const MDX = page.body;2122 return (23 <DocstraProvider24 docstraConfig={docstraConfig}25 docs={source.files}26 pageData={page.info}27 >28 <DocstraHeader />29 <DocstraPage>30 <DocstraBody>31 <MDX components={useMDXComponents()} />32 </DocstraBody>33 </DocstraPage>34 </DocstraProvider>35 );36}3738export function generateStaticParams() {39 return source.generateStaticParams();40}4142export async function generateMetadata({ params }: {43 params: Promise<{ slug?: string[] }>44}) {45 const { slug } = await params46 const page = source.getPage(slug);47 if (!page) return notFound();4849 return {50 title: page.info.data.metadata.title,51 description: page.info.data.metadata.description,52 }53}
This enables dynamic routing for all your documentation pages.
5 Import CSS File
If you are already using Tailwind CSS, import the CSS file in your globals.css file:
globals.css1@import 'docstra/css';
Note: If you are not using Tailwind CSS then you need to install Tailwind CSS and import the CSS file in your
globals.cssfile.
6. Create Your First Content Page
Now add your first MDX documentation file:
- Inside
app/docs, create a content folder - Inside
content, createindex.mdx
app/docs/content/index.mdx1---2title: Docstra3description: Welcome to the Docstra documentation!4---56# Overview78Docstra is a modern documentation framework9built specifically for Next.js.1011You can start writing your MDX content here.
You’re All Set!
Visit:
Open in Browser1http://localhost:3000/docs
You should now see your first documentation page live 🎉
Intergrating FormSync is easy. Just add the following code to your docstra.config.ts file:
Checkout the FormSync Docs and get your FormSync FORM_ID.
After getting your FORM_ID, add that in the docstra.config.ts file:
docstra.config.ts1import { defineDocstraConfig } from "docstra/config";23export default defineDocstraConfig({4 // your rest of the config5 feedback: {6 enabled: true,7 formSyncFormID: "FORM_ID",8 },9});
Replace FORM_ID with your actual FORM_ID.
Happy documenting! :)
How is this guide?