@raystack/chronicle 0.1.0-canary.e11f924 → 0.1.0-canary.f0d9bde
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/dist/cli/index.js +878 -9684
- package/package.json +17 -12
- package/src/cli/__tests__/config.test.ts +25 -0
- package/src/cli/__tests__/scaffold.test.ts +10 -0
- package/src/cli/commands/build.ts +66 -19
- package/src/cli/commands/dev.ts +9 -22
- package/src/cli/commands/init.ts +107 -11
- package/src/cli/commands/serve.ts +36 -35
- package/src/cli/commands/start.ts +11 -21
- package/src/cli/utils/config.ts +2 -2
- package/src/cli/utils/index.ts +1 -1
- package/src/cli/utils/resolve.ts +6 -0
- package/src/cli/utils/scaffold.ts +20 -0
- package/src/components/mdx/code.tsx +10 -1
- package/src/components/mdx/details.module.css +1 -24
- package/src/components/mdx/details.tsx +2 -3
- package/src/components/mdx/image.tsx +5 -19
- package/src/components/mdx/index.tsx +3 -3
- package/src/components/mdx/link.tsx +10 -11
- package/src/components/ui/footer.tsx +3 -2
- package/src/components/ui/search.module.css +7 -0
- package/src/components/ui/search.tsx +62 -87
- package/src/lib/config.ts +9 -0
- package/src/lib/head.tsx +45 -0
- package/src/lib/page-context.tsx +95 -0
- package/src/lib/source.ts +92 -21
- package/src/{app/apis/[[...slug]]/layout.tsx → pages/ApiLayout.tsx} +10 -7
- package/src/pages/ApiPage.tsx +68 -0
- package/src/pages/DocsLayout.tsx +18 -0
- package/src/pages/DocsPage.tsx +43 -0
- package/src/pages/NotFound.tsx +10 -0
- package/src/pages/__tests__/head.test.tsx +57 -0
- package/src/server/App.tsx +59 -0
- package/src/server/__tests__/entry-server.test.tsx +35 -0
- package/src/server/__tests__/handlers.test.ts +77 -0
- package/src/server/__tests__/og.test.ts +23 -0
- package/src/server/__tests__/router.test.ts +72 -0
- package/src/server/__tests__/vite-config.test.ts +25 -0
- package/src/server/adapters/vercel.ts +133 -0
- package/src/server/build-search-index.ts +107 -0
- package/src/server/dev.ts +158 -0
- package/src/server/entry-client.tsx +74 -0
- package/src/server/entry-prod.ts +98 -0
- package/src/server/entry-server.tsx +35 -0
- package/src/server/entry-vercel.ts +28 -0
- package/src/server/handlers/apis-proxy.ts +57 -0
- package/src/{app/api/health/route.ts → server/handlers/health.ts} +1 -1
- package/src/server/handlers/llms.ts +58 -0
- package/src/server/handlers/og.ts +87 -0
- package/src/server/handlers/robots.ts +11 -0
- package/src/server/handlers/search.ts +172 -0
- package/src/server/handlers/sitemap.ts +39 -0
- package/src/server/handlers/specs.ts +9 -0
- package/src/server/index.html +12 -0
- package/src/server/prod.ts +18 -0
- package/src/server/request-handler.ts +64 -0
- package/src/server/router.ts +42 -0
- package/src/server/utils/safe-path.ts +14 -0
- package/src/server/vite-config.ts +71 -0
- package/src/themes/default/Layout.tsx +9 -10
- package/src/themes/default/Page.module.css +60 -0
- package/src/themes/default/font.ts +4 -6
- package/src/themes/paper/ChapterNav.tsx +5 -6
- package/src/themes/paper/Page.tsx +8 -9
- package/src/types/config.ts +11 -0
- package/src/types/content.ts +1 -0
- package/tsconfig.json +29 -0
- package/next.config.mjs +0 -10
- package/source.config.ts +0 -50
- package/src/app/[[...slug]]/layout.tsx +0 -15
- package/src/app/[[...slug]]/page.tsx +0 -57
- package/src/app/api/apis-proxy/route.ts +0 -59
- package/src/app/api/search/route.ts +0 -90
- package/src/app/apis/[[...slug]]/page.tsx +0 -57
- package/src/app/layout.tsx +0 -26
- package/src/app/llms-full.txt/route.ts +0 -18
- package/src/app/llms.txt/route.ts +0 -15
- package/src/app/providers.tsx +0 -8
- package/src/cli/utils/process.ts +0 -7
- package/src/lib/get-llm-text.ts +0 -10
- /package/src/{app/apis/[[...slug]]/layout.module.css → pages/ApiLayout.module.css} +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import NextLink from 'next/link'
|
|
3
|
+
import { useLocation, Link } from 'react-router-dom'
|
|
5
4
|
import { MethodBadge } from '@/components/api/method-badge'
|
|
6
5
|
import type { PageTree, PageTreeItem } from '@/types'
|
|
7
6
|
import styles from './ChapterNav.module.css'
|
|
@@ -31,7 +30,7 @@ function buildChapterIndices(children: PageTreeItem[]): Map<PageTreeItem, number
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
export function ChapterNav({ tree }: ChapterNavProps) {
|
|
34
|
-
const pathname =
|
|
33
|
+
const { pathname } = useLocation()
|
|
35
34
|
const chapterIndices = buildChapterIndices(tree.children)
|
|
36
35
|
|
|
37
36
|
return (
|
|
@@ -84,13 +83,13 @@ function ChapterItem({ item, pathname }: { item: PageTreeItem; pathname: string
|
|
|
84
83
|
|
|
85
84
|
return (
|
|
86
85
|
<li>
|
|
87
|
-
<
|
|
88
|
-
|
|
86
|
+
<Link
|
|
87
|
+
to={item.url ?? '#'}
|
|
89
88
|
className={`${styles.link} ${isActive ? styles.active : ''}`}
|
|
90
89
|
>
|
|
91
90
|
{icon && <span className={styles.icon}>{icon}</span>}
|
|
92
91
|
<span>{item.name}</span>
|
|
93
|
-
</
|
|
92
|
+
</Link>
|
|
94
93
|
</li>
|
|
95
94
|
)
|
|
96
95
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
3
|
import { useMemo } from 'react'
|
|
4
|
-
import {
|
|
5
|
-
import NextLink from 'next/link'
|
|
4
|
+
import { useLocation, Link } from 'react-router-dom'
|
|
6
5
|
import { Flex } from '@raystack/apsara'
|
|
7
6
|
import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/react/24/outline'
|
|
8
7
|
import type { ThemePageProps, PageTreeItem } from '@/types'
|
|
@@ -41,7 +40,7 @@ function findInTree(items: PageTreeItem[], path: string): PageTreeItem | undefin
|
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
export function Page({ page, config, tree }: ThemePageProps) {
|
|
44
|
-
const pathname =
|
|
43
|
+
const { pathname } = useLocation()
|
|
45
44
|
|
|
46
45
|
const { prev, next, crumbs } = useMemo(() => {
|
|
47
46
|
const pages = flattenTree(tree.children)
|
|
@@ -59,18 +58,18 @@ export function Page({ page, config, tree }: ThemePageProps) {
|
|
|
59
58
|
<Flex align="center" className={styles.navbar}>
|
|
60
59
|
<Flex align="center" gap="small" className={styles.navLeft}>
|
|
61
60
|
{prev ? (
|
|
62
|
-
<
|
|
61
|
+
<Link to={prev.url!} className={styles.arrow} aria-label="Previous page">
|
|
63
62
|
<ChevronLeftIcon width={14} height={14} />
|
|
64
|
-
</
|
|
63
|
+
</Link>
|
|
65
64
|
) : (
|
|
66
65
|
<button disabled className={styles.arrowDisabled} aria-label="Previous page">
|
|
67
66
|
<ChevronLeftIcon width={14} height={14} />
|
|
68
67
|
</button>
|
|
69
68
|
)}
|
|
70
69
|
{next ? (
|
|
71
|
-
<
|
|
70
|
+
<Link to={next.url!} className={styles.arrow} aria-label="Next page">
|
|
72
71
|
<ChevronRightIcon width={14} height={14} />
|
|
73
|
-
</
|
|
72
|
+
</Link>
|
|
74
73
|
) : (
|
|
75
74
|
<button disabled className={styles.arrowDisabled} aria-label="Next page">
|
|
76
75
|
<ChevronRightIcon width={14} height={14} />
|
|
@@ -83,9 +82,9 @@ export function Page({ page, config, tree }: ThemePageProps) {
|
|
|
83
82
|
{i === crumbs.length - 1 ? (
|
|
84
83
|
<span className={styles.crumbActive}>{crumb.label}</span>
|
|
85
84
|
) : (
|
|
86
|
-
<
|
|
85
|
+
<Link to={crumb.href} className={styles.crumbLink}>
|
|
87
86
|
{crumb.label}
|
|
88
|
-
</
|
|
87
|
+
</Link>
|
|
89
88
|
)}
|
|
90
89
|
</span>
|
|
91
90
|
))}
|
package/src/types/config.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export interface ChronicleConfig {
|
|
2
2
|
title: string
|
|
3
3
|
description?: string
|
|
4
|
+
url?: string
|
|
4
5
|
logo?: LogoConfig
|
|
5
6
|
theme?: ThemeConfig
|
|
6
7
|
navigation?: NavigationConfig
|
|
@@ -8,12 +9,22 @@ export interface ChronicleConfig {
|
|
|
8
9
|
footer?: FooterConfig
|
|
9
10
|
api?: ApiConfig[]
|
|
10
11
|
llms?: LlmsConfig
|
|
12
|
+
analytics?: AnalyticsConfig
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export interface LlmsConfig {
|
|
14
16
|
enabled?: boolean
|
|
15
17
|
}
|
|
16
18
|
|
|
19
|
+
export interface AnalyticsConfig {
|
|
20
|
+
enabled?: boolean
|
|
21
|
+
googleAnalytics?: GoogleAnalyticsConfig
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface GoogleAnalyticsConfig {
|
|
25
|
+
measurementId: string
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
export interface ApiConfig {
|
|
18
29
|
name: string
|
|
19
30
|
spec: string
|
package/src/types/content.ts
CHANGED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"composite": false,
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"declarationMap": true,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"forceConsistentCasingInFileNames": true,
|
|
8
|
+
"inlineSources": false,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"noUnusedLocals": false,
|
|
11
|
+
"noUnusedParameters": false,
|
|
12
|
+
"preserveWatchOutput": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"strict": true,
|
|
15
|
+
"jsx": "react-jsx",
|
|
16
|
+
"module": "ESNext",
|
|
17
|
+
"target": "es6",
|
|
18
|
+
"outDir": "dist",
|
|
19
|
+
"rootDir": ".",
|
|
20
|
+
"baseUrl": ".",
|
|
21
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
22
|
+
"moduleResolution": "bundler",
|
|
23
|
+
"paths": {
|
|
24
|
+
"@/*": ["./src/*"]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"include": ["src"],
|
|
28
|
+
"exclude": ["node_modules", "dist"]
|
|
29
|
+
}
|
package/next.config.mjs
DELETED
package/source.config.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { defineDocs, defineConfig, frontmatterSchema } from 'fumadocs-mdx/config'
|
|
2
|
-
import { z } from 'zod'
|
|
3
|
-
import remarkDirective from 'remark-directive'
|
|
4
|
-
import { remarkDirectiveAdmonition, remarkMdxMermaid } from 'fumadocs-core/mdx-plugins'
|
|
5
|
-
import remarkUnusedDirectives from './src/lib/remark-unused-directives'
|
|
6
|
-
|
|
7
|
-
const contentDir = process.env.CHRONICLE_CONTENT_DIR || './content'
|
|
8
|
-
|
|
9
|
-
export const docs = defineDocs({
|
|
10
|
-
dir: contentDir,
|
|
11
|
-
docs: {
|
|
12
|
-
schema: frontmatterSchema.extend({
|
|
13
|
-
order: z.number().optional(),
|
|
14
|
-
}),
|
|
15
|
-
postprocess: {
|
|
16
|
-
includeProcessedMarkdown: true,
|
|
17
|
-
},
|
|
18
|
-
files: ['**/*.mdx', '**/*.md', '!**/node_modules/**'],
|
|
19
|
-
},
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
export default defineConfig({
|
|
23
|
-
mdxOptions: {
|
|
24
|
-
remarkPlugins: [
|
|
25
|
-
remarkDirective,
|
|
26
|
-
[
|
|
27
|
-
remarkDirectiveAdmonition,
|
|
28
|
-
{
|
|
29
|
-
tags: {
|
|
30
|
-
CalloutContainer: 'Callout',
|
|
31
|
-
CalloutTitle: 'CalloutTitle',
|
|
32
|
-
CalloutDescription: 'CalloutDescription',
|
|
33
|
-
},
|
|
34
|
-
types: {
|
|
35
|
-
note: 'accent',
|
|
36
|
-
tip: 'accent',
|
|
37
|
-
info: 'accent',
|
|
38
|
-
warn: 'attention',
|
|
39
|
-
warning: 'attention',
|
|
40
|
-
danger: 'alert',
|
|
41
|
-
caution: 'alert',
|
|
42
|
-
success: 'success',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
remarkUnusedDirectives,
|
|
47
|
-
remarkMdxMermaid,
|
|
48
|
-
],
|
|
49
|
-
},
|
|
50
|
-
})
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { loadConfig } from '@/lib/config'
|
|
2
|
-
import { buildPageTree } from '@/lib/source'
|
|
3
|
-
import { getTheme } from '@/themes/registry'
|
|
4
|
-
|
|
5
|
-
export default function DocsLayout({ children }: { children: React.ReactNode }) {
|
|
6
|
-
const config = loadConfig()
|
|
7
|
-
const tree = buildPageTree()
|
|
8
|
-
const { Layout, className } = getTheme(config.theme?.name)
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<Layout config={config} tree={tree} classNames={{ layout: className }}>
|
|
12
|
-
{children}
|
|
13
|
-
</Layout>
|
|
14
|
-
)
|
|
15
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { notFound } from 'next/navigation'
|
|
2
|
-
import type { MDXContent } from 'mdx/types'
|
|
3
|
-
import { loadConfig } from '@/lib/config'
|
|
4
|
-
import { source, buildPageTree } from '@/lib/source'
|
|
5
|
-
import { getTheme } from '@/themes/registry'
|
|
6
|
-
import { mdxComponents } from '@/components/mdx'
|
|
7
|
-
|
|
8
|
-
interface PageProps {
|
|
9
|
-
params: Promise<{ slug?: string[] }>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface PageData {
|
|
13
|
-
title: string
|
|
14
|
-
description?: string
|
|
15
|
-
body: MDXContent
|
|
16
|
-
toc: { title: string; url: string; depth: number }[]
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default async function DocsPage({ params }: PageProps) {
|
|
20
|
-
const { slug } = await params
|
|
21
|
-
const config = loadConfig()
|
|
22
|
-
|
|
23
|
-
const page = source.getPage(slug)
|
|
24
|
-
|
|
25
|
-
if (!page) {
|
|
26
|
-
notFound()
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const { Page } = getTheme(config.theme?.name)
|
|
30
|
-
|
|
31
|
-
const data = page.data as PageData
|
|
32
|
-
const MDXBody = data.body
|
|
33
|
-
|
|
34
|
-
const tree = buildPageTree()
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<Page
|
|
38
|
-
page={{
|
|
39
|
-
slug: slug ?? [],
|
|
40
|
-
frontmatter: {
|
|
41
|
-
title: data.title,
|
|
42
|
-
description: data.description,
|
|
43
|
-
},
|
|
44
|
-
content: <MDXBody components={mdxComponents} />,
|
|
45
|
-
toc: data.toc ?? [],
|
|
46
|
-
}}
|
|
47
|
-
config={config}
|
|
48
|
-
tree={tree}
|
|
49
|
-
/>
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function generateStaticParams() {
|
|
54
|
-
return source.getPages().map((page) => ({
|
|
55
|
-
slug: page.slugs,
|
|
56
|
-
}))
|
|
57
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
-
import { loadConfig } from "@/lib/config";
|
|
3
|
-
import { loadApiSpecs } from "@/lib/openapi";
|
|
4
|
-
|
|
5
|
-
export async function POST(request: NextRequest) {
|
|
6
|
-
const { specName, method, path, headers, body } = await request.json();
|
|
7
|
-
|
|
8
|
-
if (!specName || !method || !path) {
|
|
9
|
-
return NextResponse.json(
|
|
10
|
-
{ error: "Missing specName, method, or path" },
|
|
11
|
-
{ status: 400 },
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const config = loadConfig();
|
|
16
|
-
const specs = loadApiSpecs(config.api ?? []);
|
|
17
|
-
const spec = specs.find((s) => s.name === specName);
|
|
18
|
-
|
|
19
|
-
if (!spec) {
|
|
20
|
-
return NextResponse.json(
|
|
21
|
-
{ error: `Unknown spec: ${specName}` },
|
|
22
|
-
{ status: 404 },
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const url = spec.server.url + path;
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const response = await fetch(url, {
|
|
30
|
-
method,
|
|
31
|
-
headers,
|
|
32
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
36
|
-
const responseBody = contentType.includes("application/json")
|
|
37
|
-
? await response.json()
|
|
38
|
-
: await response.text();
|
|
39
|
-
|
|
40
|
-
return NextResponse.json({
|
|
41
|
-
status: response.status,
|
|
42
|
-
statusText: response.statusText,
|
|
43
|
-
body: responseBody,
|
|
44
|
-
}, { status: response.status });
|
|
45
|
-
} catch (error) {
|
|
46
|
-
const message =
|
|
47
|
-
error instanceof Error
|
|
48
|
-
? `${error.message}${error.cause ? `: ${(error.cause as Error).message}` : ""}`
|
|
49
|
-
: "Request failed";
|
|
50
|
-
return NextResponse.json(
|
|
51
|
-
{
|
|
52
|
-
status: 502,
|
|
53
|
-
statusText: "Bad Gateway",
|
|
54
|
-
body: `Could not reach ${url}\n${message}`,
|
|
55
|
-
},
|
|
56
|
-
{ status: 502 },
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { source } from '@/lib/source'
|
|
2
|
-
import { createSearchAPI, type AdvancedIndex } from 'fumadocs-core/search/server'
|
|
3
|
-
import type { StructuredData } from 'fumadocs-core/mdx-plugins'
|
|
4
|
-
import type { OpenAPIV3 } from 'openapi-types'
|
|
5
|
-
import { loadConfig } from '@/lib/config'
|
|
6
|
-
import { loadApiSpecs, type ApiSpec } from '@/lib/openapi'
|
|
7
|
-
import { getSpecSlug } from '@/lib/api-routes'
|
|
8
|
-
|
|
9
|
-
interface PageData {
|
|
10
|
-
title?: string
|
|
11
|
-
description?: string
|
|
12
|
-
structuredData?: StructuredData
|
|
13
|
-
load?: () => Promise<{ structuredData?: StructuredData }>
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const HTTP_METHODS = ['get', 'post', 'put', 'delete', 'patch'] as const
|
|
17
|
-
type HttpMethod = (typeof HTTP_METHODS)[number]
|
|
18
|
-
|
|
19
|
-
function getParamNames(op: OpenAPIV3.OperationObject): string[] {
|
|
20
|
-
const params = (op.parameters as OpenAPIV3.ParameterObject[] | undefined) ?? []
|
|
21
|
-
return params.map((p) => p.name)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function buildStructuredData(op: OpenAPIV3.OperationObject, method: string, pathStr: string) {
|
|
25
|
-
return {
|
|
26
|
-
headings: [{ id: op.operationId!, content: `${method.toUpperCase()} ${pathStr}` }],
|
|
27
|
-
contents: [{ heading: op.operationId!, content: `${method.toUpperCase()} ${[op.description, ...getParamNames(op)].filter(Boolean).join(' ')}` }],
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function operationToIndex(specSlug: string, pathStr: string, method: HttpMethod, op: OpenAPIV3.OperationObject): AdvancedIndex {
|
|
32
|
-
const url = `/apis/${specSlug}/${encodeURIComponent(op.operationId!)}`
|
|
33
|
-
return {
|
|
34
|
-
id: url,
|
|
35
|
-
url,
|
|
36
|
-
title: `${method.toUpperCase()} ${op.summary ?? op.operationId!}`,
|
|
37
|
-
description: op.description ?? '',
|
|
38
|
-
structuredData: buildStructuredData(op, method, pathStr),
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function pathEntryToIndexes(specSlug: string) {
|
|
43
|
-
return ([pathStr, pathItem]: [string, OpenAPIV3.PathItemObject | undefined]): AdvancedIndex[] => {
|
|
44
|
-
if (!pathItem) return []
|
|
45
|
-
const hasOp = (m: HttpMethod) => !!pathItem[m]?.operationId
|
|
46
|
-
const toIndex = (m: HttpMethod) => operationToIndex(specSlug, pathStr, m, pathItem[m]!)
|
|
47
|
-
return HTTP_METHODS.filter(hasOp).map(toIndex)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function specToIndexes(spec: ApiSpec): AdvancedIndex[] {
|
|
52
|
-
const specSlug = getSpecSlug(spec)
|
|
53
|
-
return Object.entries(spec.document.paths ?? {}).flatMap(pathEntryToIndexes(specSlug))
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function buildApiIndexes(): AdvancedIndex[] {
|
|
57
|
-
const config = loadConfig()
|
|
58
|
-
if (!config.api?.length) return []
|
|
59
|
-
return loadApiSpecs(config.api).flatMap(specToIndexes)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const { GET } = createSearchAPI('advanced', {
|
|
63
|
-
indexes: async (): Promise<AdvancedIndex[]> => {
|
|
64
|
-
const pages = source.getPages()
|
|
65
|
-
const indexes = await Promise.all(
|
|
66
|
-
pages.map(async (page): Promise<AdvancedIndex> => {
|
|
67
|
-
const data = page.data as PageData
|
|
68
|
-
let structuredData: StructuredData | undefined = data.structuredData
|
|
69
|
-
|
|
70
|
-
if (!structuredData && data.load) {
|
|
71
|
-
try {
|
|
72
|
-
const loaded = await data.load()
|
|
73
|
-
structuredData = loaded.structuredData
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.error(`Failed to load structured data for ${page.url}:`, error)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
id: page.url,
|
|
81
|
-
url: page.url,
|
|
82
|
-
title: data.title ?? '',
|
|
83
|
-
description: data.description ?? '',
|
|
84
|
-
structuredData: structuredData ?? { headings: [], contents: [] },
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
)
|
|
88
|
-
return [...indexes, ...buildApiIndexes()]
|
|
89
|
-
},
|
|
90
|
-
})
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { notFound } from 'next/navigation'
|
|
2
|
-
import type { OpenAPIV3 } from 'openapi-types'
|
|
3
|
-
import { Flex, Headline, Text } from '@raystack/apsara'
|
|
4
|
-
import { loadConfig } from '@/lib/config'
|
|
5
|
-
import { loadApiSpecs } from '@/lib/openapi'
|
|
6
|
-
import { buildApiRoutes, findApiOperation } from '@/lib/api-routes'
|
|
7
|
-
import { EndpointPage } from '@/components/api'
|
|
8
|
-
|
|
9
|
-
interface PageProps {
|
|
10
|
-
params: Promise<{ slug?: string[] }>
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default async function ApiPage({ params }: PageProps) {
|
|
14
|
-
const { slug } = await params
|
|
15
|
-
const config = loadConfig()
|
|
16
|
-
const specs = loadApiSpecs(config.api ?? [])
|
|
17
|
-
|
|
18
|
-
if (!slug || slug.length === 0) {
|
|
19
|
-
return <ApiLanding specs={specs} />
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const match = findApiOperation(specs, slug)
|
|
23
|
-
if (!match) notFound()
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<EndpointPage
|
|
27
|
-
method={match.method}
|
|
28
|
-
path={match.path}
|
|
29
|
-
operation={match.operation}
|
|
30
|
-
serverUrl={match.spec.server.url}
|
|
31
|
-
specName={match.spec.name}
|
|
32
|
-
auth={match.spec.auth}
|
|
33
|
-
/>
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function ApiLanding({ specs }: { specs: { name: string; document: OpenAPIV3.Document }[] }) {
|
|
38
|
-
return (
|
|
39
|
-
<Flex direction="column" gap="large" style={{ padding: 'var(--rs-space-7)' }}>
|
|
40
|
-
<Headline size="medium" as="h1">API Reference</Headline>
|
|
41
|
-
{specs.map((spec) => (
|
|
42
|
-
<Flex key={spec.name} direction="column" gap="small">
|
|
43
|
-
<Headline size="small" as="h2">{spec.name}</Headline>
|
|
44
|
-
{spec.document.info.description && (
|
|
45
|
-
<Text size={3}>{spec.document.info.description}</Text>
|
|
46
|
-
)}
|
|
47
|
-
</Flex>
|
|
48
|
-
))}
|
|
49
|
-
</Flex>
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function generateStaticParams() {
|
|
54
|
-
const config = loadConfig()
|
|
55
|
-
const specs = loadApiSpecs(config.api ?? [])
|
|
56
|
-
return [{ slug: [] }, ...buildApiRoutes(specs)]
|
|
57
|
-
}
|
package/src/app/layout.tsx
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import '@raystack/apsara/normalize.css'
|
|
2
|
-
import '@raystack/apsara/style.css'
|
|
3
|
-
import type { Metadata } from 'next'
|
|
4
|
-
import { loadConfig } from '@/lib/config'
|
|
5
|
-
import { Providers } from './providers'
|
|
6
|
-
|
|
7
|
-
const config = loadConfig()
|
|
8
|
-
|
|
9
|
-
export const metadata: Metadata = {
|
|
10
|
-
title: config.title,
|
|
11
|
-
description: config.description,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default function RootLayout({
|
|
15
|
-
children,
|
|
16
|
-
}: {
|
|
17
|
-
children: React.ReactNode
|
|
18
|
-
}) {
|
|
19
|
-
return (
|
|
20
|
-
<html lang="en" suppressHydrationWarning>
|
|
21
|
-
<body suppressHydrationWarning>
|
|
22
|
-
<Providers>{children}</Providers>
|
|
23
|
-
</body>
|
|
24
|
-
</html>
|
|
25
|
-
)
|
|
26
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { source } from '@/lib/source'
|
|
2
|
-
import { loadConfig } from '@/lib/config'
|
|
3
|
-
import { getLLMText } from '@/lib/get-llm-text'
|
|
4
|
-
|
|
5
|
-
export const revalidate = false
|
|
6
|
-
|
|
7
|
-
export async function GET() {
|
|
8
|
-
const config = loadConfig()
|
|
9
|
-
|
|
10
|
-
if (!config.llms?.enabled) {
|
|
11
|
-
return new Response('Not Found', { status: 404 })
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const scan = source.getPages().map(getLLMText)
|
|
15
|
-
const scanned = await Promise.all(scan)
|
|
16
|
-
|
|
17
|
-
return new Response(scanned.join('\n\n'))
|
|
18
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { source } from '@/lib/source'
|
|
2
|
-
import { loadConfig } from '@/lib/config'
|
|
3
|
-
import { llms } from 'fumadocs-core/source'
|
|
4
|
-
|
|
5
|
-
export const revalidate = false
|
|
6
|
-
|
|
7
|
-
export function GET() {
|
|
8
|
-
const config = loadConfig()
|
|
9
|
-
|
|
10
|
-
if (!config.llms?.enabled) {
|
|
11
|
-
return new Response('Not Found', { status: 404 })
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return new Response(llms(source).index())
|
|
15
|
-
}
|
package/src/app/providers.tsx
DELETED
package/src/cli/utils/process.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { ChildProcess } from 'child_process'
|
|
2
|
-
|
|
3
|
-
export function attachLifecycleHandlers(child: ChildProcess) {
|
|
4
|
-
child.on('close', (code) => process.exit(code ?? 0))
|
|
5
|
-
process.on('SIGINT', () => child.kill('SIGINT'))
|
|
6
|
-
process.on('SIGTERM', () => child.kill('SIGTERM'))
|
|
7
|
-
}
|
package/src/lib/get-llm-text.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { source } from '@/lib/source'
|
|
2
|
-
import type { InferPageType } from 'fumadocs-core/source'
|
|
3
|
-
|
|
4
|
-
export async function getLLMText(page: InferPageType<typeof source>) {
|
|
5
|
-
const processed = await page.data.getText('processed')
|
|
6
|
-
|
|
7
|
-
return `# ${page.data.title} (${page.url})
|
|
8
|
-
|
|
9
|
-
${processed}`
|
|
10
|
-
}
|
|
File without changes
|