docstra 1.6.3 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,77 +1,137 @@
1
- # **Docstra**
1
+ # Docstra
2
2
 
3
- Docstra is a modern documentation framework for Next.js. It's built with Tailwind CSS and MDX, making it easy to create beautiful and responsive documentation sites.
3
+ **The Modern Documentation Framework for Next.js**
4
4
 
5
- > Documentation of Docstra is coming soon. Stay tuned!
5
+ Docstra is a powerful, type-safe, and easy-to-use documentation framework built for Next.js 15+ App Router. It provides a beautiful default theme, MDX support, and flexible components to build your documentation site in minutes.
6
6
 
7
- > For any questions, feel free to reach out us on [contact@sudhucodes.com](mailto:contact@sudhucodes.com)
7
+ ---
8
8
 
9
- ## Features
9
+ ## 🚀 Quick Start
10
10
 
11
- - MDX support
12
- - Custom content directories
13
- - Works in monorepos
14
- - Beautiful sidebar + TOC
15
- - Edit-on-GitHub links
16
- - Search coming soon
11
+ ### 1. Installation
17
12
 
18
- ## Install
13
+ Install `docstra` and its peer dependencies:
19
14
 
20
15
  ```bash
21
- npm install docstra
16
+ npm install docstra next-mdx-remote gray-matter lucide-react prism-react-renderer react-toast-msg
22
17
  ```
23
18
 
24
- ## Usage
19
+ ### 2. Configuration
20
+
21
+ Create `docstra.config.ts` in your project root:
25
22
 
26
23
  ```ts
27
- // docstra.config.ts
28
- import { defineDocstraConfig } from 'docstra/config';
29
-
30
- export default defineDocstraConfig({
31
- siteName: 'Docstra',
32
- githubRepo: 'https://github.com/sudhucodes/docstra',
33
- contentDir: 'docs/content',
34
- editOnGithub: true,
35
- feedback: {
36
- enabled: true,
37
- formSyncFormID: 'FORM_ID'
38
- },
39
- navbar: {
40
- logo: {
41
- link: '/docs',
42
- src: '/logo.svg',
43
- alt: 'Logo',
44
- className: 'h-9.5 w-auto'
45
- },
46
- links: [
47
- { name: 'Guides', href: '/docs/guides' },
48
- { name: 'Examples', href: '/docs/examples' }
49
- ]
24
+ import { DocstraConfig } from "docstra/config";
25
+
26
+ const config: DocstraConfig = {
27
+ title: "My Docs",
28
+ description: "Documentation for my project",
29
+ github: {
30
+ user: "myuser",
31
+ repo: "myrepo",
50
32
  },
51
33
  sidebar: {
52
- links: [
53
- {
54
- section: 'Introduction',
55
- items: [
56
- {
57
- name: 'Overview',
58
- href: '/docs',
59
- icon: 'NotebookPenIcon'
60
- },
61
- {
62
- name: 'Quick Start',
63
- href: '/docs/quick-start',
64
- icon: 'RocketIcon'
65
- }
66
- ]
67
- },
68
- {
69
- section: 'Tailwind Setup',
70
- items: [{ name: 'Installation', href: '/docs/setup/installation' }]
71
- }
72
- ]
34
+ // ... sidebar entries
73
35
  }
74
- });
36
+ };
37
+
38
+ export default config;
39
+ ```
40
+
41
+ ### 3. Source Setup
42
+
43
+ Create `src/lib/source.ts` (or `lib/source.ts`) to manage your content:
44
+
45
+ ```ts
46
+ import { createSource } from "docstra/server";
47
+ import { docs } from "../.docstra"; // Generated at build time
48
+
49
+ export const source = createSource(docs);
50
+ ```
51
+
52
+ ### 4. Component Mapping (Important!)
53
+
54
+ Create `mdx-components.tsx` in your project root. This is critical for getting the default components (like code blocks) working correctly.
55
+
56
+ ```tsx
57
+ import { defaultMdxComponents } from "docstra/server";
58
+ import { DocstraCodeBlock } from "docstra";
59
+
60
+ export function useMDXComponents() {
61
+ return {
62
+ ...defaultMdxComponents(),
63
+ pre: DocstraCodeBlock, // Manually map to avoid server/client bundle conflicts
64
+ };
65
+ }
66
+ ```
67
+
68
+ ### 5. Create the Page
69
+
70
+ Create your catch-all route at `app/docs/[[...slug]]/page.tsx`:
71
+
72
+ ```tsx
73
+ import { source } from "@/lib/source";
74
+ import { notFound } from "next/navigation";
75
+ import { DocstraProvider, DocstraPage, DocstraBody, DocstraHeader } from "docstra";
76
+ import { useMDXComponents } from "@/mdx-components";
77
+ import config from "@/docstra.config";
78
+
79
+ export default async function Page({ params }: { params: Promise<{ slug?: string[] }> }) {
80
+ const { slug } = await params;
81
+
82
+ // 1. Get page data
83
+ const page = source.getPage(slug);
84
+ if (!page) return notFound();
85
+
86
+ // 2. Destructure info (safe JSON) and body (MDX Component)
87
+ const { info, body: MDX } = page;
88
+
89
+ // 3. Render
90
+ return (
91
+ <DocstraProvider docstraConfig={config} docs={source.files} pageData={info}>
92
+ <DocstraHeader />
93
+ <DocstraPage>
94
+ <DocstraBody>
95
+ <MDX components={useMDXComponents()} />
96
+ </DocstraBody>
97
+ </DocstraPage>
98
+ </DocstraProvider>
99
+ );
100
+ }
101
+
102
+ // Generate static params for SSG
103
+ export function generateStaticParams() {
104
+ return source.generateStaticParams();
105
+ }
106
+
107
+ // Generate metadata
108
+ export async function generateMetadata({ params }: { params: Promise<{ slug?: string[] }> }) {
109
+ const { slug } = await params;
110
+ const page = source.getPage(slug);
111
+ if (!page) return notFound();
112
+ return {
113
+ title: page.info.data.metadata.title,
114
+ description: page.info.data.metadata.description,
115
+ };
116
+ }
75
117
  ```
76
118
 
77
- > Created and maintained with 💙 by [SudhuCodes](https://github.com/sudhucodes)
119
+ ### 6. Build
120
+
121
+ Update your `next.config.ts` or `with-docstra` setup (if applicable) and run:
122
+
123
+ ```bash
124
+ npm run build
125
+ ```
126
+
127
+ Docstra will generate the `.docstra/index.ts` file manifest, and your docs will be live!
128
+
129
+ ---
130
+
131
+ ## 🛠 Features
132
+
133
+ - **MDX Support**: Write documentation in Markdown/MDX.
134
+ - **Auto Sidebar/TOC**: `DocstraPage` automatically handles layouts.
135
+ - **Search**: Built-in search (requires configuration).
136
+ - **Code Highlighting**: Powered by Prism with copy support.
137
+ - **Type Safe**: Full TypeScript support.
@@ -1,12 +1,13 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1 from 'react';
3
- import { D as DocstraConfig, p as pageDataContent, a as DocstraContextType } from '../types-BCr1htTq.mjs';
3
+ import { D as DocstraConfig, p as pageDataContent, a as DocstraContextType } from '../types-QzxGYJU4.mjs';
4
4
 
5
- declare function DocstraProvider({ children, docstraConfig, docs, pageData }: {
5
+ declare function DocstraProvider({ children, docstraConfig, docs, pageData: initialPageData, slug }: {
6
6
  children: React$1.ReactNode;
7
7
  docstraConfig: DocstraConfig;
8
8
  docs: pageDataContent[];
9
- pageData: pageDataContent;
9
+ pageData?: pageDataContent;
10
+ slug?: string | string[];
10
11
  }): react_jsx_runtime.JSX.Element;
11
12
  declare function useDocstra(): DocstraContextType;
12
13
 
@@ -14,9 +15,12 @@ declare function DocstraHeader(): react_jsx_runtime.JSX.Element;
14
15
 
15
16
  declare function DocstraSidebar(): react_jsx_runtime.JSX.Element;
16
17
 
17
- declare function DocstraPage({ children }: {
18
+ interface DocstraPageProps {
18
19
  children: React.ReactNode;
19
- }): react_jsx_runtime.JSX.Element;
20
+ toc?: boolean;
21
+ sidebar?: boolean;
22
+ }
23
+ declare function DocstraPage({ children, toc, sidebar }: DocstraPageProps): react_jsx_runtime.JSX.Element;
20
24
 
21
25
  interface Props {
22
26
  children: React.ReactNode;
@@ -27,4 +31,6 @@ declare function DocstraTOC(): react_jsx_runtime.JSX.Element;
27
31
 
28
32
  declare function DocstraCodeBlock(props: any): react_jsx_runtime.JSX.Element;
29
33
 
30
- export { DocstraBody, DocstraCodeBlock, DocstraHeader, DocstraPage, DocstraProvider, DocstraSidebar, DocstraTOC, useDocstra };
34
+ declare function DocstraSearchBox(): react_jsx_runtime.JSX.Element;
35
+
36
+ export { DocstraBody, DocstraCodeBlock, DocstraHeader, DocstraPage, DocstraProvider, DocstraSearchBox, DocstraSidebar, DocstraTOC, useDocstra };
@@ -1,12 +1,13 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1 from 'react';
3
- import { D as DocstraConfig, p as pageDataContent, a as DocstraContextType } from '../types-BCr1htTq.js';
3
+ import { D as DocstraConfig, p as pageDataContent, a as DocstraContextType } from '../types-QzxGYJU4.js';
4
4
 
5
- declare function DocstraProvider({ children, docstraConfig, docs, pageData }: {
5
+ declare function DocstraProvider({ children, docstraConfig, docs, pageData: initialPageData, slug }: {
6
6
  children: React$1.ReactNode;
7
7
  docstraConfig: DocstraConfig;
8
8
  docs: pageDataContent[];
9
- pageData: pageDataContent;
9
+ pageData?: pageDataContent;
10
+ slug?: string | string[];
10
11
  }): react_jsx_runtime.JSX.Element;
11
12
  declare function useDocstra(): DocstraContextType;
12
13
 
@@ -14,9 +15,12 @@ declare function DocstraHeader(): react_jsx_runtime.JSX.Element;
14
15
 
15
16
  declare function DocstraSidebar(): react_jsx_runtime.JSX.Element;
16
17
 
17
- declare function DocstraPage({ children }: {
18
+ interface DocstraPageProps {
18
19
  children: React.ReactNode;
19
- }): react_jsx_runtime.JSX.Element;
20
+ toc?: boolean;
21
+ sidebar?: boolean;
22
+ }
23
+ declare function DocstraPage({ children, toc, sidebar }: DocstraPageProps): react_jsx_runtime.JSX.Element;
20
24
 
21
25
  interface Props {
22
26
  children: React.ReactNode;
@@ -27,4 +31,6 @@ declare function DocstraTOC(): react_jsx_runtime.JSX.Element;
27
31
 
28
32
  declare function DocstraCodeBlock(props: any): react_jsx_runtime.JSX.Element;
29
33
 
30
- export { DocstraBody, DocstraCodeBlock, DocstraHeader, DocstraPage, DocstraProvider, DocstraSidebar, DocstraTOC, useDocstra };
34
+ declare function DocstraSearchBox(): react_jsx_runtime.JSX.Element;
35
+
36
+ export { DocstraBody, DocstraCodeBlock, DocstraHeader, DocstraPage, DocstraProvider, DocstraSearchBox, DocstraSidebar, DocstraTOC, useDocstra };