@brainfish-ai/devdoc 0.1.21
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/LICENSE +33 -0
- package/README.md +415 -0
- package/bin/devdoc.js +13 -0
- package/dist/cli/commands/build.d.ts +5 -0
- package/dist/cli/commands/build.js +87 -0
- package/dist/cli/commands/check.d.ts +1 -0
- package/dist/cli/commands/check.js +143 -0
- package/dist/cli/commands/create.d.ts +24 -0
- package/dist/cli/commands/create.js +387 -0
- package/dist/cli/commands/deploy.d.ts +9 -0
- package/dist/cli/commands/deploy.js +433 -0
- package/dist/cli/commands/dev.d.ts +6 -0
- package/dist/cli/commands/dev.js +139 -0
- package/dist/cli/commands/init.d.ts +11 -0
- package/dist/cli/commands/init.js +238 -0
- package/dist/cli/commands/keys.d.ts +12 -0
- package/dist/cli/commands/keys.js +165 -0
- package/dist/cli/commands/start.d.ts +5 -0
- package/dist/cli/commands/start.js +56 -0
- package/dist/cli/commands/upload.d.ts +13 -0
- package/dist/cli/commands/upload.js +238 -0
- package/dist/cli/commands/whoami.d.ts +8 -0
- package/dist/cli/commands/whoami.js +91 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +106 -0
- package/dist/config/index.d.ts +80 -0
- package/dist/config/index.js +133 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +12 -0
- package/dist/utils/logger.d.ts +16 -0
- package/dist/utils/logger.js +61 -0
- package/dist/utils/paths.d.ts +16 -0
- package/dist/utils/paths.js +50 -0
- package/package.json +51 -0
- package/renderer/app/api/assets/[...path]/route.ts +123 -0
- package/renderer/app/api/assets/route.ts +124 -0
- package/renderer/app/api/assets/upload/route.ts +177 -0
- package/renderer/app/api/auth-schemes/route.ts +77 -0
- package/renderer/app/api/chat/route.ts +858 -0
- package/renderer/app/api/codegen/route.ts +72 -0
- package/renderer/app/api/collections/route.ts +1016 -0
- package/renderer/app/api/debug/route.ts +53 -0
- package/renderer/app/api/deploy/route.ts +234 -0
- package/renderer/app/api/device/route.ts +42 -0
- package/renderer/app/api/docs/route.ts +187 -0
- package/renderer/app/api/keys/regenerate/route.ts +80 -0
- package/renderer/app/api/openapi-spec/route.ts +151 -0
- package/renderer/app/api/projects/[slug]/route.ts +153 -0
- package/renderer/app/api/projects/[slug]/stats/route.ts +96 -0
- package/renderer/app/api/projects/register/route.ts +152 -0
- package/renderer/app/api/proxy/route.ts +149 -0
- package/renderer/app/api/proxy-stream/route.ts +168 -0
- package/renderer/app/api/redirects/route.ts +47 -0
- package/renderer/app/api/schema/route.ts +65 -0
- package/renderer/app/api/subdomains/check/route.ts +172 -0
- package/renderer/app/api/suggestions/route.ts +144 -0
- package/renderer/app/favicon.ico +0 -0
- package/renderer/app/globals.css +1103 -0
- package/renderer/app/layout.tsx +47 -0
- package/renderer/app/llms-full.txt/route.ts +346 -0
- package/renderer/app/llms.txt/route.ts +279 -0
- package/renderer/app/page.tsx +14 -0
- package/renderer/app/robots.txt/route.ts +84 -0
- package/renderer/app/sitemap.xml/route.ts +199 -0
- package/renderer/components/docs/index.ts +12 -0
- package/renderer/components/docs/mdx/accordion.tsx +169 -0
- package/renderer/components/docs/mdx/badge.tsx +132 -0
- package/renderer/components/docs/mdx/callouts.tsx +154 -0
- package/renderer/components/docs/mdx/cards.tsx +213 -0
- package/renderer/components/docs/mdx/changelog.tsx +120 -0
- package/renderer/components/docs/mdx/code-block.tsx +186 -0
- package/renderer/components/docs/mdx/code-group.tsx +421 -0
- package/renderer/components/docs/mdx/file-embeds.tsx +105 -0
- package/renderer/components/docs/mdx/frame.tsx +112 -0
- package/renderer/components/docs/mdx/highlight.tsx +151 -0
- package/renderer/components/docs/mdx/iframe.tsx +134 -0
- package/renderer/components/docs/mdx/image.tsx +235 -0
- package/renderer/components/docs/mdx/index.ts +204 -0
- package/renderer/components/docs/mdx/mermaid.tsx +240 -0
- package/renderer/components/docs/mdx/param-field.tsx +200 -0
- package/renderer/components/docs/mdx/steps.tsx +113 -0
- package/renderer/components/docs/mdx/tabs.tsx +86 -0
- package/renderer/components/docs/mdx-renderer.tsx +100 -0
- package/renderer/components/docs/navigation/breadcrumbs.tsx +76 -0
- package/renderer/components/docs/navigation/index.ts +8 -0
- package/renderer/components/docs/navigation/page-nav.tsx +64 -0
- package/renderer/components/docs/navigation/sidebar.tsx +515 -0
- package/renderer/components/docs/navigation/toc.tsx +113 -0
- package/renderer/components/docs/notice.tsx +105 -0
- package/renderer/components/docs-header.tsx +274 -0
- package/renderer/components/docs-viewer/agent/agent-chat.tsx +2076 -0
- package/renderer/components/docs-viewer/agent/cards/debug-context-card.tsx +90 -0
- package/renderer/components/docs-viewer/agent/cards/endpoint-context-card.tsx +49 -0
- package/renderer/components/docs-viewer/agent/cards/index.tsx +50 -0
- package/renderer/components/docs-viewer/agent/cards/response-options-card.tsx +212 -0
- package/renderer/components/docs-viewer/agent/cards/types.ts +84 -0
- package/renderer/components/docs-viewer/agent/chat-message.tsx +17 -0
- package/renderer/components/docs-viewer/agent/index.tsx +6 -0
- package/renderer/components/docs-viewer/agent/messages/assistant-message.tsx +119 -0
- package/renderer/components/docs-viewer/agent/messages/chat-message.tsx +46 -0
- package/renderer/components/docs-viewer/agent/messages/index.ts +17 -0
- package/renderer/components/docs-viewer/agent/messages/tool-call-display.tsx +721 -0
- package/renderer/components/docs-viewer/agent/messages/types.ts +61 -0
- package/renderer/components/docs-viewer/agent/messages/typing-indicator.tsx +24 -0
- package/renderer/components/docs-viewer/agent/messages/user-message.tsx +51 -0
- package/renderer/components/docs-viewer/code-editor/index.tsx +2 -0
- package/renderer/components/docs-viewer/code-editor/notes-mode.tsx +1283 -0
- package/renderer/components/docs-viewer/content/changelog-page.tsx +331 -0
- package/renderer/components/docs-viewer/content/doc-page.tsx +285 -0
- package/renderer/components/docs-viewer/content/documentation-viewer.tsx +17 -0
- package/renderer/components/docs-viewer/content/index.tsx +29 -0
- package/renderer/components/docs-viewer/content/introduction.tsx +21 -0
- package/renderer/components/docs-viewer/content/request-details.tsx +330 -0
- package/renderer/components/docs-viewer/content/sections/auth.tsx +69 -0
- package/renderer/components/docs-viewer/content/sections/body.tsx +66 -0
- package/renderer/components/docs-viewer/content/sections/headers.tsx +43 -0
- package/renderer/components/docs-viewer/content/sections/overview.tsx +40 -0
- package/renderer/components/docs-viewer/content/sections/parameters.tsx +43 -0
- package/renderer/components/docs-viewer/content/sections/responses.tsx +87 -0
- package/renderer/components/docs-viewer/global-auth-modal.tsx +352 -0
- package/renderer/components/docs-viewer/index.tsx +1466 -0
- package/renderer/components/docs-viewer/playground/auth-editor.tsx +280 -0
- package/renderer/components/docs-viewer/playground/body-editor.tsx +221 -0
- package/renderer/components/docs-viewer/playground/code-editor.tsx +224 -0
- package/renderer/components/docs-viewer/playground/code-snippet.tsx +387 -0
- package/renderer/components/docs-viewer/playground/graphql-playground.tsx +745 -0
- package/renderer/components/docs-viewer/playground/index.tsx +671 -0
- package/renderer/components/docs-viewer/playground/key-value-editor.tsx +261 -0
- package/renderer/components/docs-viewer/playground/method-selector.tsx +60 -0
- package/renderer/components/docs-viewer/playground/request-builder.tsx +179 -0
- package/renderer/components/docs-viewer/playground/request-tabs.tsx +237 -0
- package/renderer/components/docs-viewer/playground/response-cards/idle-card.tsx +21 -0
- package/renderer/components/docs-viewer/playground/response-cards/index.tsx +93 -0
- package/renderer/components/docs-viewer/playground/response-cards/loading-card.tsx +16 -0
- package/renderer/components/docs-viewer/playground/response-cards/network-error-card.tsx +23 -0
- package/renderer/components/docs-viewer/playground/response-cards/response-body-card.tsx +268 -0
- package/renderer/components/docs-viewer/playground/response-cards/types.ts +82 -0
- package/renderer/components/docs-viewer/playground/response-viewer.tsx +43 -0
- package/renderer/components/docs-viewer/search/index.ts +2 -0
- package/renderer/components/docs-viewer/search/search-dialog.tsx +331 -0
- package/renderer/components/docs-viewer/search/use-search.ts +117 -0
- package/renderer/components/docs-viewer/shared/markdown-renderer.tsx +431 -0
- package/renderer/components/docs-viewer/shared/method-badge.tsx +41 -0
- package/renderer/components/docs-viewer/shared/schema-viewer.tsx +349 -0
- package/renderer/components/docs-viewer/sidebar/collection-tree.tsx +239 -0
- package/renderer/components/docs-viewer/sidebar/endpoint-options.tsx +316 -0
- package/renderer/components/docs-viewer/sidebar/index.tsx +343 -0
- package/renderer/components/docs-viewer/sidebar/right-sidebar.tsx +202 -0
- package/renderer/components/docs-viewer/sidebar/sidebar-group.tsx +118 -0
- package/renderer/components/docs-viewer/sidebar/sidebar-item.tsx +226 -0
- package/renderer/components/docs-viewer/sidebar/sidebar-section.tsx +52 -0
- package/renderer/components/theme-provider.tsx +11 -0
- package/renderer/components/theme-toggle.tsx +76 -0
- package/renderer/components/ui/badge.tsx +46 -0
- package/renderer/components/ui/button.tsx +59 -0
- package/renderer/components/ui/dialog.tsx +118 -0
- package/renderer/components/ui/dropdown-menu.tsx +257 -0
- package/renderer/components/ui/input.tsx +21 -0
- package/renderer/components/ui/label.tsx +24 -0
- package/renderer/components/ui/navigation-menu.tsx +168 -0
- package/renderer/components/ui/select.tsx +190 -0
- package/renderer/components/ui/spinner.tsx +114 -0
- package/renderer/components/ui/tabs.tsx +66 -0
- package/renderer/components/ui/tooltip.tsx +61 -0
- package/renderer/hooks/use-code-copy.ts +88 -0
- package/renderer/hooks/use-openapi-title.ts +44 -0
- package/renderer/lib/api-docs/agent/index.ts +6 -0
- package/renderer/lib/api-docs/agent/indexer.ts +323 -0
- package/renderer/lib/api-docs/agent/spec-summary.ts +335 -0
- package/renderer/lib/api-docs/agent/types.ts +116 -0
- package/renderer/lib/api-docs/auth/auth-context.tsx +225 -0
- package/renderer/lib/api-docs/auth/auth-storage.ts +87 -0
- package/renderer/lib/api-docs/auth/crypto.ts +89 -0
- package/renderer/lib/api-docs/auth/index.ts +4 -0
- package/renderer/lib/api-docs/code-editor/db.ts +164 -0
- package/renderer/lib/api-docs/code-editor/hooks.ts +266 -0
- package/renderer/lib/api-docs/code-editor/index.ts +6 -0
- package/renderer/lib/api-docs/code-editor/mode-context.tsx +207 -0
- package/renderer/lib/api-docs/code-editor/types.ts +105 -0
- package/renderer/lib/api-docs/codegen/definitions.ts +297 -0
- package/renderer/lib/api-docs/codegen/har.ts +251 -0
- package/renderer/lib/api-docs/codegen/index.ts +159 -0
- package/renderer/lib/api-docs/factories.ts +151 -0
- package/renderer/lib/api-docs/index.ts +17 -0
- package/renderer/lib/api-docs/mobile-context.tsx +112 -0
- package/renderer/lib/api-docs/navigation-context.tsx +88 -0
- package/renderer/lib/api-docs/parsers/graphql/README.md +129 -0
- package/renderer/lib/api-docs/parsers/graphql/index.ts +91 -0
- package/renderer/lib/api-docs/parsers/graphql/parser.ts +491 -0
- package/renderer/lib/api-docs/parsers/graphql/transformer.ts +246 -0
- package/renderer/lib/api-docs/parsers/graphql/types.ts +283 -0
- package/renderer/lib/api-docs/parsers/openapi/README.md +32 -0
- package/renderer/lib/api-docs/parsers/openapi/dereferencer.ts +60 -0
- package/renderer/lib/api-docs/parsers/openapi/extractors/auth.ts +574 -0
- package/renderer/lib/api-docs/parsers/openapi/extractors/body.ts +403 -0
- package/renderer/lib/api-docs/parsers/openapi/extractors/index.ts +232 -0
- package/renderer/lib/api-docs/parsers/openapi/index.ts +171 -0
- package/renderer/lib/api-docs/parsers/openapi/transformer.ts +277 -0
- package/renderer/lib/api-docs/parsers/openapi/validator.ts +31 -0
- package/renderer/lib/api-docs/playground/context.tsx +107 -0
- package/renderer/lib/api-docs/playground/navigation-context.tsx +124 -0
- package/renderer/lib/api-docs/playground/request-builder.ts +223 -0
- package/renderer/lib/api-docs/playground/request-runner.ts +282 -0
- package/renderer/lib/api-docs/playground/types.ts +35 -0
- package/renderer/lib/api-docs/types.ts +269 -0
- package/renderer/lib/api-docs/utils.ts +311 -0
- package/renderer/lib/cache.ts +193 -0
- package/renderer/lib/docs/config/index.ts +29 -0
- package/renderer/lib/docs/config/loader.ts +142 -0
- package/renderer/lib/docs/config/schema.ts +298 -0
- package/renderer/lib/docs/index.ts +12 -0
- package/renderer/lib/docs/mdx/compiler.ts +176 -0
- package/renderer/lib/docs/mdx/frontmatter.ts +80 -0
- package/renderer/lib/docs/mdx/index.ts +26 -0
- package/renderer/lib/docs/navigation/generator.ts +348 -0
- package/renderer/lib/docs/navigation/index.ts +12 -0
- package/renderer/lib/docs/navigation/types.ts +123 -0
- package/renderer/lib/docs-navigation-context.tsx +80 -0
- package/renderer/lib/multi-tenant/context.ts +105 -0
- package/renderer/lib/storage/blob.ts +845 -0
- package/renderer/lib/utils.ts +6 -0
- package/renderer/next.config.ts +76 -0
- package/renderer/package.json +66 -0
- package/renderer/postcss.config.mjs +5 -0
- package/renderer/public/assets/images/screenshot.png +0 -0
- package/renderer/public/assets/logo/dark.svg +9 -0
- package/renderer/public/assets/logo/light.svg +9 -0
- package/renderer/public/assets/logo.svg +9 -0
- package/renderer/public/file.svg +1 -0
- package/renderer/public/globe.svg +1 -0
- package/renderer/public/icon.png +0 -0
- package/renderer/public/logo.svg +9 -0
- package/renderer/public/window.svg +1 -0
- package/renderer/tsconfig.json +28 -0
- package/templates/basic/README.md +139 -0
- package/templates/basic/assets/favicon.svg +4 -0
- package/templates/basic/assets/logo.svg +9 -0
- package/templates/basic/docs.json +47 -0
- package/templates/basic/guides/configuration.mdx +149 -0
- package/templates/basic/guides/overview.mdx +96 -0
- package/templates/basic/index.mdx +39 -0
- package/templates/basic/package.json +14 -0
- package/templates/basic/quickstart.mdx +92 -0
- package/templates/basic/vercel.json +6 -0
- package/templates/graphql/README.md +139 -0
- package/templates/graphql/api-reference/schema.graphql +305 -0
- package/templates/graphql/assets/favicon.svg +4 -0
- package/templates/graphql/assets/logo.svg +9 -0
- package/templates/graphql/docs.json +54 -0
- package/templates/graphql/guides/configuration.mdx +149 -0
- package/templates/graphql/guides/overview.mdx +96 -0
- package/templates/graphql/index.mdx +39 -0
- package/templates/graphql/package.json +14 -0
- package/templates/graphql/quickstart.mdx +92 -0
- package/templates/graphql/vercel.json +6 -0
- package/templates/openapi/README.md +139 -0
- package/templates/openapi/api-reference/openapi.json +419 -0
- package/templates/openapi/assets/favicon.svg +4 -0
- package/templates/openapi/assets/logo.svg +9 -0
- package/templates/openapi/docs.json +61 -0
- package/templates/openapi/guides/configuration.mdx +149 -0
- package/templates/openapi/guides/overview.mdx +96 -0
- package/templates/openapi/index.mdx +39 -0
- package/templates/openapi/package.json +14 -0
- package/templates/openapi/quickstart.mdx +92 -0
- package/templates/openapi/vercel.json +6 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { compileMDX } from 'next-mdx-remote/rsc'
|
|
2
|
+
import matter from 'gray-matter'
|
|
3
|
+
import rehypeSlug from 'rehype-slug'
|
|
4
|
+
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
|
|
5
|
+
import remarkGfm from 'remark-gfm'
|
|
6
|
+
import { parseFrontmatter, safeParseFrontmatter, type Frontmatter } from './frontmatter'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* MDX Compiler Utilities
|
|
10
|
+
*
|
|
11
|
+
* Provides functions for compiling MDX content with custom components
|
|
12
|
+
* and extracting frontmatter metadata
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export interface MDXCompileResult<TFrontmatter = Frontmatter> {
|
|
16
|
+
content: React.ReactElement
|
|
17
|
+
frontmatter: TFrontmatter
|
|
18
|
+
headings: TableOfContentsItem[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface TableOfContentsItem {
|
|
22
|
+
id: string
|
|
23
|
+
title: string
|
|
24
|
+
level: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface CompileMDXOptions {
|
|
28
|
+
components?: Record<string, React.ComponentType<unknown>>
|
|
29
|
+
scope?: Record<string, unknown>
|
|
30
|
+
validateFrontmatter?: boolean
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Extract frontmatter from raw MDX content
|
|
35
|
+
*/
|
|
36
|
+
export function extractFrontmatter(source: string): {
|
|
37
|
+
content: string
|
|
38
|
+
data: Record<string, unknown>
|
|
39
|
+
} {
|
|
40
|
+
const { content, data } = matter(source)
|
|
41
|
+
return { content, data }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Extract headings from MDX content for table of contents
|
|
46
|
+
*/
|
|
47
|
+
export function extractHeadings(content: string): TableOfContentsItem[] {
|
|
48
|
+
const headingRegex = /^(#{1,6})\s+(.+)$/gm
|
|
49
|
+
const headings: TableOfContentsItem[] = []
|
|
50
|
+
let match
|
|
51
|
+
|
|
52
|
+
while ((match = headingRegex.exec(content)) !== null) {
|
|
53
|
+
const level = match[1].length
|
|
54
|
+
const title = match[2].trim()
|
|
55
|
+
// Generate slug from title (same logic as rehype-slug)
|
|
56
|
+
const id = title
|
|
57
|
+
.toLowerCase()
|
|
58
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
59
|
+
.replace(/^-+|-+$/g, '')
|
|
60
|
+
|
|
61
|
+
headings.push({ id, title, level })
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return headings
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Compile MDX content with components and plugins
|
|
69
|
+
*/
|
|
70
|
+
export async function compileMDXContent<TFrontmatter = Frontmatter>(
|
|
71
|
+
source: string,
|
|
72
|
+
options: CompileMDXOptions = {}
|
|
73
|
+
): Promise<MDXCompileResult<TFrontmatter>> {
|
|
74
|
+
const { components = {}, scope = {}, validateFrontmatter = true } = options
|
|
75
|
+
|
|
76
|
+
// Extract frontmatter first
|
|
77
|
+
const { content: mdxContent, data: rawFrontmatter } = extractFrontmatter(source)
|
|
78
|
+
|
|
79
|
+
// Validate frontmatter if requested
|
|
80
|
+
const frontmatter = validateFrontmatter
|
|
81
|
+
? parseFrontmatter(rawFrontmatter) as TFrontmatter
|
|
82
|
+
: rawFrontmatter as TFrontmatter
|
|
83
|
+
|
|
84
|
+
// Extract headings for ToC
|
|
85
|
+
const headings = extractHeadings(mdxContent)
|
|
86
|
+
|
|
87
|
+
// Compile MDX
|
|
88
|
+
const { content } = await compileMDX({
|
|
89
|
+
source: mdxContent,
|
|
90
|
+
components,
|
|
91
|
+
options: {
|
|
92
|
+
parseFrontmatter: false, // Already extracted
|
|
93
|
+
mdxOptions: {
|
|
94
|
+
remarkPlugins: [remarkGfm],
|
|
95
|
+
rehypePlugins: [
|
|
96
|
+
rehypeSlug,
|
|
97
|
+
[rehypeAutolinkHeadings, { behavior: 'wrap' }],
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
scope: {
|
|
101
|
+
...scope,
|
|
102
|
+
frontmatter,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
content,
|
|
109
|
+
frontmatter,
|
|
110
|
+
headings,
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Quick compile for previews (less validation)
|
|
116
|
+
*/
|
|
117
|
+
export async function quickCompileMDX(
|
|
118
|
+
source: string,
|
|
119
|
+
components: Record<string, React.ComponentType<unknown>> = {}
|
|
120
|
+
): Promise<{ content: React.ReactElement; frontmatter: Record<string, unknown> }> {
|
|
121
|
+
const { content: mdxContent, data: frontmatter } = extractFrontmatter(source)
|
|
122
|
+
|
|
123
|
+
const { content } = await compileMDX({
|
|
124
|
+
source: mdxContent,
|
|
125
|
+
components,
|
|
126
|
+
options: {
|
|
127
|
+
parseFrontmatter: false,
|
|
128
|
+
mdxOptions: {
|
|
129
|
+
remarkPlugins: [remarkGfm],
|
|
130
|
+
rehypePlugins: [rehypeSlug],
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
return { content, frontmatter }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Validate MDX content without compiling (for linting)
|
|
140
|
+
*/
|
|
141
|
+
export function validateMDXContent(source: string): {
|
|
142
|
+
valid: boolean
|
|
143
|
+
errors: string[]
|
|
144
|
+
warnings: string[]
|
|
145
|
+
} {
|
|
146
|
+
const errors: string[] = []
|
|
147
|
+
const warnings: string[] = []
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const { data } = extractFrontmatter(source)
|
|
151
|
+
|
|
152
|
+
// Check frontmatter
|
|
153
|
+
const frontmatterResult = safeParseFrontmatter(data)
|
|
154
|
+
if (!frontmatterResult) {
|
|
155
|
+
errors.push('Invalid frontmatter format')
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Check for common issues
|
|
159
|
+
if (!data.title) {
|
|
160
|
+
warnings.push('Missing title in frontmatter')
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (!data.description) {
|
|
164
|
+
warnings.push('Missing description in frontmatter (recommended for SEO)')
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
} catch (error) {
|
|
168
|
+
errors.push(`Parse error: ${error instanceof Error ? error.message : 'Unknown error'}`)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
valid: errors.length === 0,
|
|
173
|
+
errors,
|
|
174
|
+
warnings,
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Frontmatter Schema for MDX Documentation Pages
|
|
5
|
+
*
|
|
6
|
+
* Defines the structure and validation for page metadata
|
|
7
|
+
* Compatible with Mintlify-style frontmatter
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const frontmatterSchema = z.object({
|
|
11
|
+
// Core metadata
|
|
12
|
+
title: z.string(),
|
|
13
|
+
description: z.string().optional(),
|
|
14
|
+
|
|
15
|
+
// Navigation
|
|
16
|
+
sidebarTitle: z.string().optional(),
|
|
17
|
+
icon: z.string().optional(),
|
|
18
|
+
|
|
19
|
+
// Page behavior
|
|
20
|
+
mode: z.enum(['default', 'wide', 'custom']).optional(),
|
|
21
|
+
|
|
22
|
+
// OpenAPI integration
|
|
23
|
+
openapi: z.string().optional(),
|
|
24
|
+
api: z.string().optional(),
|
|
25
|
+
|
|
26
|
+
// SEO
|
|
27
|
+
'og:title': z.string().optional(),
|
|
28
|
+
'og:description': z.string().optional(),
|
|
29
|
+
'og:image': z.string().optional(),
|
|
30
|
+
'twitter:title': z.string().optional(),
|
|
31
|
+
'twitter:description': z.string().optional(),
|
|
32
|
+
|
|
33
|
+
// Visibility
|
|
34
|
+
hidden: z.boolean().optional(),
|
|
35
|
+
noindex: z.boolean().optional(),
|
|
36
|
+
|
|
37
|
+
// Version/Status
|
|
38
|
+
version: z.string().optional(),
|
|
39
|
+
deprecated: z.boolean().optional(),
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
export type Frontmatter = z.infer<typeof frontmatterSchema>
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Parse and validate frontmatter data
|
|
46
|
+
* Returns the validated data or throws an error with details
|
|
47
|
+
*/
|
|
48
|
+
export function parseFrontmatter(data: unknown): Frontmatter {
|
|
49
|
+
const result = frontmatterSchema.safeParse(data)
|
|
50
|
+
|
|
51
|
+
if (!result.success) {
|
|
52
|
+
const issues = result.error.issues || []
|
|
53
|
+
const errors = issues.map((e) =>
|
|
54
|
+
`${e.path.map(String).join('.')}: ${e.message}`
|
|
55
|
+
).join('\n')
|
|
56
|
+
throw new Error(`Invalid frontmatter:\n${errors}`)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return result.data
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Safe parse that returns null on failure instead of throwing
|
|
64
|
+
*/
|
|
65
|
+
export function safeParseFrontmatter(data: unknown): Frontmatter | null {
|
|
66
|
+
const result = frontmatterSchema.safeParse(data)
|
|
67
|
+
return result.success ? result.data : null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get default frontmatter values
|
|
72
|
+
*/
|
|
73
|
+
export function getDefaultFrontmatter(): Partial<Frontmatter> {
|
|
74
|
+
return {
|
|
75
|
+
mode: 'default',
|
|
76
|
+
hidden: false,
|
|
77
|
+
noindex: false,
|
|
78
|
+
deprecated: false,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MDX Library Exports
|
|
3
|
+
*
|
|
4
|
+
* Core utilities for MDX compilation and processing
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Compiler utilities
|
|
8
|
+
export {
|
|
9
|
+
compileMDXContent,
|
|
10
|
+
quickCompileMDX,
|
|
11
|
+
validateMDXContent,
|
|
12
|
+
extractFrontmatter,
|
|
13
|
+
extractHeadings,
|
|
14
|
+
type MDXCompileResult,
|
|
15
|
+
type TableOfContentsItem,
|
|
16
|
+
type CompileMDXOptions,
|
|
17
|
+
} from './compiler'
|
|
18
|
+
|
|
19
|
+
// Frontmatter
|
|
20
|
+
export {
|
|
21
|
+
frontmatterSchema,
|
|
22
|
+
parseFrontmatter,
|
|
23
|
+
safeParseFrontmatter,
|
|
24
|
+
getDefaultFrontmatter,
|
|
25
|
+
type Frontmatter,
|
|
26
|
+
} from './frontmatter'
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { relative, basename, extname } from 'path'
|
|
2
|
+
import {
|
|
3
|
+
type DocsConfig,
|
|
4
|
+
type NavigationTab,
|
|
5
|
+
type NavigationGroup,
|
|
6
|
+
resolvePagePath,
|
|
7
|
+
loadPageContent,
|
|
8
|
+
} from '../config'
|
|
9
|
+
import { extractFrontmatter, safeParseFrontmatter } from '../mdx'
|
|
10
|
+
import type {
|
|
11
|
+
Navigation,
|
|
12
|
+
NavTab,
|
|
13
|
+
NavGroup,
|
|
14
|
+
NavItem,
|
|
15
|
+
PageNavContext,
|
|
16
|
+
BreadcrumbItem,
|
|
17
|
+
PageMeta,
|
|
18
|
+
} from './types'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Navigation Generator
|
|
22
|
+
*
|
|
23
|
+
* Builds navigation structure from docs.json configuration
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generate navigation from configuration
|
|
28
|
+
*/
|
|
29
|
+
export function generateNavigation(
|
|
30
|
+
config: DocsConfig,
|
|
31
|
+
docsDir: string
|
|
32
|
+
): Navigation {
|
|
33
|
+
const nav = config.navigation
|
|
34
|
+
const navigation: Navigation = {}
|
|
35
|
+
|
|
36
|
+
// Handle tabbed navigation
|
|
37
|
+
if (nav.tabs && nav.tabs.length > 0) {
|
|
38
|
+
navigation.tabs = nav.tabs.map(tab => buildNavTab(tab, docsDir))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Handle single-page navigation (no tabs)
|
|
42
|
+
if (nav.groups && nav.groups.length > 0) {
|
|
43
|
+
navigation.groups = nav.groups.map(group => buildNavGroup(group, docsDir))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Add global anchors
|
|
47
|
+
if (nav.global?.anchors) {
|
|
48
|
+
navigation.anchors = nav.global.anchors.map(anchor => ({
|
|
49
|
+
title: anchor.anchor,
|
|
50
|
+
href: anchor.href,
|
|
51
|
+
icon: anchor.icon,
|
|
52
|
+
external: anchor.href.startsWith('http'),
|
|
53
|
+
}))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return navigation
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Build a navigation tab
|
|
61
|
+
*/
|
|
62
|
+
function buildNavTab(
|
|
63
|
+
tab: NavigationTab,
|
|
64
|
+
docsDir: string
|
|
65
|
+
): NavTab {
|
|
66
|
+
const slug = tab.tab.toLowerCase().replace(/\s+/g, '-')
|
|
67
|
+
|
|
68
|
+
// Only docs tabs have groups
|
|
69
|
+
if ('groups' in tab && tab.groups) {
|
|
70
|
+
const groups = tab.groups.map(group => buildNavGroup(group, docsDir))
|
|
71
|
+
return {
|
|
72
|
+
title: tab.tab,
|
|
73
|
+
slug,
|
|
74
|
+
groups,
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// For openapi/changelog tabs, return empty groups
|
|
79
|
+
return {
|
|
80
|
+
title: tab.tab,
|
|
81
|
+
slug,
|
|
82
|
+
groups: [],
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Build a navigation group
|
|
88
|
+
*/
|
|
89
|
+
function buildNavGroup(
|
|
90
|
+
group: NavigationGroup,
|
|
91
|
+
docsDir: string
|
|
92
|
+
): NavGroup {
|
|
93
|
+
const items = group.pages
|
|
94
|
+
.map(page => buildNavItemOrGroup(page, docsDir))
|
|
95
|
+
.filter((item): item is NavItem | NavGroup => item !== null)
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
title: group.group,
|
|
99
|
+
icon: group.icon,
|
|
100
|
+
items,
|
|
101
|
+
collapsible: true,
|
|
102
|
+
defaultCollapsed: false,
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Build a navigation item or nested group from a page reference
|
|
108
|
+
*/
|
|
109
|
+
function buildNavItemOrGroup(
|
|
110
|
+
pageRef: string | { group: string; pages: (string | object)[] },
|
|
111
|
+
docsDir: string
|
|
112
|
+
): NavItem | NavGroup | null {
|
|
113
|
+
// Handle nested groups
|
|
114
|
+
if (typeof pageRef === 'object' && 'group' in pageRef) {
|
|
115
|
+
const nestedItems = pageRef.pages
|
|
116
|
+
.map(p => buildNavItemOrGroup(p as string | { group: string; pages: (string | object)[] }, docsDir))
|
|
117
|
+
.filter((item): item is NavItem | NavGroup => item !== null)
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
title: pageRef.group,
|
|
121
|
+
items: nestedItems,
|
|
122
|
+
collapsible: true,
|
|
123
|
+
defaultCollapsed: false,
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return buildNavItem(pageRef, docsDir)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Build a navigation item from a page reference
|
|
132
|
+
*/
|
|
133
|
+
function buildNavItem(
|
|
134
|
+
pageRef: string,
|
|
135
|
+
docsDir: string
|
|
136
|
+
): NavItem | null {
|
|
137
|
+
// Check if it's an external link
|
|
138
|
+
if (pageRef.startsWith('http://') || pageRef.startsWith('https://')) {
|
|
139
|
+
return {
|
|
140
|
+
title: pageRef,
|
|
141
|
+
href: pageRef,
|
|
142
|
+
external: true,
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Resolve the page file
|
|
147
|
+
const filePath = resolvePagePath(docsDir, pageRef)
|
|
148
|
+
|
|
149
|
+
if (!filePath) {
|
|
150
|
+
console.warn(`Page not found: ${pageRef}`)
|
|
151
|
+
return {
|
|
152
|
+
title: pageRef,
|
|
153
|
+
href: `/${pageRef}`,
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Load and parse frontmatter
|
|
158
|
+
try {
|
|
159
|
+
const content = loadPageContent(filePath)
|
|
160
|
+
const { data } = extractFrontmatter(content)
|
|
161
|
+
const frontmatter = safeParseFrontmatter(data)
|
|
162
|
+
|
|
163
|
+
// Build URL path
|
|
164
|
+
const urlPath = pageRef === 'index' ? '/' : `/${pageRef}`
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
title: frontmatter?.sidebarTitle || frontmatter?.title || pageRef,
|
|
168
|
+
href: urlPath,
|
|
169
|
+
icon: frontmatter?.icon,
|
|
170
|
+
deprecated: frontmatter?.deprecated,
|
|
171
|
+
}
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.warn(`Failed to load page metadata: ${pageRef}`, error)
|
|
174
|
+
return {
|
|
175
|
+
title: pageRef,
|
|
176
|
+
href: `/${pageRef}`,
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Helper to check if an item is a NavItem (has href)
|
|
183
|
+
*/
|
|
184
|
+
function isNavItem(item: NavItem | NavGroup): item is NavItem {
|
|
185
|
+
return 'href' in item && typeof item.href === 'string'
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Recursively collect all NavItems from items array (handles nested groups)
|
|
190
|
+
*/
|
|
191
|
+
function collectNavItems(items: (NavItem | NavGroup)[]): NavItem[] {
|
|
192
|
+
const result: NavItem[] = []
|
|
193
|
+
for (const item of items) {
|
|
194
|
+
if (isNavItem(item)) {
|
|
195
|
+
result.push(item)
|
|
196
|
+
} else if ('items' in item && Array.isArray(item.items)) {
|
|
197
|
+
result.push(...collectNavItems(item.items))
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return result
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Find navigation context for a specific page
|
|
205
|
+
*/
|
|
206
|
+
export function findPageNavContext(
|
|
207
|
+
navigation: Navigation,
|
|
208
|
+
currentPath: string
|
|
209
|
+
): PageNavContext {
|
|
210
|
+
const breadcrumbs: BreadcrumbItem[] = []
|
|
211
|
+
let prev: NavItem | undefined
|
|
212
|
+
let next: NavItem | undefined
|
|
213
|
+
let currentTab: NavTab | undefined
|
|
214
|
+
let currentGroup: NavGroup | undefined
|
|
215
|
+
let currentItem: NavItem | undefined
|
|
216
|
+
|
|
217
|
+
// Normalize path
|
|
218
|
+
const normalizedPath = currentPath.startsWith('/') ? currentPath : `/${currentPath}`
|
|
219
|
+
|
|
220
|
+
// Flatten all items for prev/next calculation
|
|
221
|
+
const allItems: NavItem[] = []
|
|
222
|
+
|
|
223
|
+
// Search in tabs
|
|
224
|
+
if (navigation.tabs) {
|
|
225
|
+
for (const tab of navigation.tabs) {
|
|
226
|
+
for (const group of tab.groups) {
|
|
227
|
+
const groupItems = collectNavItems(group.items)
|
|
228
|
+
allItems.push(...groupItems)
|
|
229
|
+
|
|
230
|
+
for (const item of groupItems) {
|
|
231
|
+
if (item.href === normalizedPath) {
|
|
232
|
+
currentTab = tab
|
|
233
|
+
currentGroup = group
|
|
234
|
+
currentItem = item
|
|
235
|
+
|
|
236
|
+
// Build breadcrumbs
|
|
237
|
+
breadcrumbs.push({ title: tab.title, href: `/${tab.slug}` })
|
|
238
|
+
breadcrumbs.push({ title: group.title, href: '#' })
|
|
239
|
+
breadcrumbs.push({ title: item.title, href: item.href })
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Search in groups (non-tabbed)
|
|
247
|
+
if (navigation.groups) {
|
|
248
|
+
for (const group of navigation.groups) {
|
|
249
|
+
const groupItems = collectNavItems(group.items)
|
|
250
|
+
allItems.push(...groupItems)
|
|
251
|
+
|
|
252
|
+
for (const item of groupItems) {
|
|
253
|
+
if (item.href === normalizedPath) {
|
|
254
|
+
currentGroup = group
|
|
255
|
+
currentItem = item
|
|
256
|
+
|
|
257
|
+
// Build breadcrumbs
|
|
258
|
+
breadcrumbs.push({ title: group.title, href: '#' })
|
|
259
|
+
breadcrumbs.push({ title: item.title, href: item.href })
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Find prev/next
|
|
266
|
+
const currentIndex = allItems.findIndex(item => item.href === normalizedPath)
|
|
267
|
+
if (currentIndex > 0) {
|
|
268
|
+
prev = allItems[currentIndex - 1]
|
|
269
|
+
}
|
|
270
|
+
if (currentIndex >= 0 && currentIndex < allItems.length - 1) {
|
|
271
|
+
next = allItems[currentIndex + 1]
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return {
|
|
275
|
+
breadcrumbs,
|
|
276
|
+
prev,
|
|
277
|
+
next,
|
|
278
|
+
currentTab,
|
|
279
|
+
currentGroup,
|
|
280
|
+
currentItem,
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Get all page paths from navigation
|
|
286
|
+
*/
|
|
287
|
+
export function getAllPagePaths(navigation: Navigation): string[] {
|
|
288
|
+
const paths: string[] = []
|
|
289
|
+
|
|
290
|
+
if (navigation.tabs) {
|
|
291
|
+
for (const tab of navigation.tabs) {
|
|
292
|
+
for (const group of tab.groups) {
|
|
293
|
+
const items = collectNavItems(group.items)
|
|
294
|
+
for (const item of items) {
|
|
295
|
+
if (!item.external) {
|
|
296
|
+
paths.push(item.href)
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (navigation.groups) {
|
|
304
|
+
for (const group of navigation.groups) {
|
|
305
|
+
const items = collectNavItems(group.items)
|
|
306
|
+
for (const item of items) {
|
|
307
|
+
if (!item.external) {
|
|
308
|
+
paths.push(item.href)
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return paths
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Load page metadata from file
|
|
319
|
+
*/
|
|
320
|
+
export function loadPageMeta(
|
|
321
|
+
filePath: string,
|
|
322
|
+
docsDir: string
|
|
323
|
+
): PageMeta | null {
|
|
324
|
+
try {
|
|
325
|
+
const content = loadPageContent(filePath)
|
|
326
|
+
const { data } = extractFrontmatter(content)
|
|
327
|
+
const frontmatter = safeParseFrontmatter(data)
|
|
328
|
+
|
|
329
|
+
// Calculate URL path from file path
|
|
330
|
+
const relativePath = relative(docsDir, filePath)
|
|
331
|
+
const urlPath = '/' + relativePath
|
|
332
|
+
.replace(/\.(mdx?|md)$/, '')
|
|
333
|
+
.replace(/\/index$/, '')
|
|
334
|
+
.replace(/^index$/, '')
|
|
335
|
+
|
|
336
|
+
return {
|
|
337
|
+
filePath: relativePath,
|
|
338
|
+
urlPath: urlPath || '/',
|
|
339
|
+
title: frontmatter?.title || basename(filePath, extname(filePath)),
|
|
340
|
+
description: frontmatter?.description,
|
|
341
|
+
sidebarTitle: frontmatter?.sidebarTitle,
|
|
342
|
+
icon: frontmatter?.icon,
|
|
343
|
+
hidden: frontmatter?.hidden,
|
|
344
|
+
}
|
|
345
|
+
} catch {
|
|
346
|
+
return null
|
|
347
|
+
}
|
|
348
|
+
}
|