@raystack/chronicle 0.1.0-canary.323385a → 0.1.0-canary.3e58cd9
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 +268 -9902
- package/package.json +20 -12
- package/src/cli/commands/build.ts +27 -25
- package/src/cli/commands/dev.ts +24 -25
- package/src/cli/commands/init.ts +38 -132
- package/src/cli/commands/serve.ts +36 -49
- package/src/cli/commands/start.ts +20 -25
- package/src/cli/index.ts +14 -14
- package/src/cli/utils/config.ts +25 -26
- package/src/cli/utils/index.ts +3 -3
- package/src/cli/utils/resolve.ts +9 -3
- package/src/cli/utils/scaffold.ts +11 -124
- package/src/components/mdx/code.tsx +10 -1
- package/src/components/mdx/details.module.css +1 -26
- package/src/components/mdx/details.tsx +2 -3
- package/src/components/mdx/image.tsx +5 -34
- package/src/components/mdx/index.tsx +15 -1
- package/src/components/mdx/link.tsx +18 -15
- package/src/components/ui/breadcrumbs.tsx +8 -42
- package/src/components/ui/search.tsx +63 -51
- package/src/lib/api-routes.ts +6 -8
- package/src/lib/config.ts +12 -35
- package/src/lib/head.tsx +49 -0
- package/src/lib/openapi.ts +8 -8
- package/src/lib/page-context.tsx +111 -0
- package/src/lib/source.ts +134 -63
- package/src/pages/ApiLayout.tsx +33 -0
- package/src/pages/ApiPage.tsx +73 -0
- package/src/pages/DocsLayout.tsx +18 -0
- package/src/pages/DocsPage.tsx +43 -0
- package/src/pages/NotFound.tsx +17 -0
- package/src/server/App.tsx +67 -0
- package/src/server/api/apis-proxy.ts +69 -0
- package/src/server/api/health.ts +5 -0
- package/src/server/api/page/[...slug].ts +17 -0
- package/src/server/api/search.ts +118 -0
- package/src/server/api/specs.ts +9 -0
- package/src/server/build-search-index.ts +117 -0
- package/src/server/entry-client.tsx +86 -0
- package/src/server/entry-server.tsx +100 -0
- package/src/server/routes/llms.txt.ts +21 -0
- package/src/server/routes/og.tsx +75 -0
- package/src/server/routes/robots.txt.ts +11 -0
- package/src/server/routes/sitemap.xml.ts +40 -0
- package/src/server/utils/safe-path.ts +17 -0
- package/src/server/vite-config.ts +126 -0
- package/src/themes/default/Layout.tsx +78 -48
- package/src/themes/default/Page.module.css +44 -0
- package/src/themes/default/Page.tsx +9 -11
- package/src/themes/default/Toc.tsx +25 -39
- package/src/themes/default/index.ts +7 -9
- package/src/themes/paper/ChapterNav.tsx +64 -45
- package/src/themes/paper/Layout.module.css +1 -1
- package/src/themes/paper/Layout.tsx +24 -12
- package/src/themes/paper/Page.module.css +16 -4
- package/src/themes/paper/Page.tsx +56 -63
- package/src/themes/paper/ReadingProgress.tsx +160 -139
- package/src/themes/paper/index.ts +5 -5
- package/src/themes/registry.ts +7 -7
- package/src/types/config.ts +11 -0
- package/src/types/content.ts +6 -21
- package/src/types/globals.d.ts +4 -0
- package/src/types/theme.ts +4 -3
- package/tsconfig.json +2 -3
- 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/health/route.ts +0 -3
- package/src/app/api/search/route.ts +0 -90
- package/src/app/apis/[[...slug]]/layout.tsx +0 -26
- 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/themes/default/font.ts +0 -6
- /package/src/{app/apis/[[...slug]]/layout.module.css → pages/ApiLayout.module.css} +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { defineHandler } from 'nitro';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import satori from 'satori';
|
|
4
|
+
import { loadConfig } from '@/lib/config';
|
|
5
|
+
|
|
6
|
+
let fontData: ArrayBuffer | null = null;
|
|
7
|
+
|
|
8
|
+
async function loadFont(): Promise<ArrayBuffer> {
|
|
9
|
+
if (fontData) return fontData;
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const response = await fetch(
|
|
13
|
+
'https://fonts.gstatic.com/s/inter/v18/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZ9hiA.woff2'
|
|
14
|
+
);
|
|
15
|
+
fontData = await response.arrayBuffer();
|
|
16
|
+
} catch {
|
|
17
|
+
fontData = new ArrayBuffer(0);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return fontData;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default defineHandler(async event => {
|
|
24
|
+
const config = loadConfig();
|
|
25
|
+
const title = event.url.searchParams.get('title') ?? config.title;
|
|
26
|
+
const description = event.url.searchParams.get('description') ?? '';
|
|
27
|
+
const siteName = config.title;
|
|
28
|
+
|
|
29
|
+
const font = await loadFont();
|
|
30
|
+
|
|
31
|
+
const svg = await satori(
|
|
32
|
+
<div
|
|
33
|
+
style={{
|
|
34
|
+
height: '100%',
|
|
35
|
+
width: '100%',
|
|
36
|
+
display: 'flex',
|
|
37
|
+
flexDirection: 'column',
|
|
38
|
+
justifyContent: 'center',
|
|
39
|
+
padding: '60px 80px',
|
|
40
|
+
backgroundColor: '#0a0a0a',
|
|
41
|
+
color: '#fafafa',
|
|
42
|
+
}}
|
|
43
|
+
>
|
|
44
|
+
<div style={{ fontSize: 24, color: '#888', marginBottom: 16 }}>
|
|
45
|
+
{siteName}
|
|
46
|
+
</div>
|
|
47
|
+
<div
|
|
48
|
+
style={{
|
|
49
|
+
fontSize: 56,
|
|
50
|
+
fontWeight: 700,
|
|
51
|
+
lineHeight: 1.2,
|
|
52
|
+
marginBottom: 24,
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{title}
|
|
56
|
+
</div>
|
|
57
|
+
{description && (
|
|
58
|
+
<div style={{ fontSize: 24, color: '#999', lineHeight: 1.4 }}>
|
|
59
|
+
{description}
|
|
60
|
+
</div>
|
|
61
|
+
)}
|
|
62
|
+
</div>,
|
|
63
|
+
{
|
|
64
|
+
width: 1200,
|
|
65
|
+
height: 630,
|
|
66
|
+
fonts: [
|
|
67
|
+
{ name: 'Inter', data: font, weight: 400, style: 'normal' as const },
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
event.res.headers.set('Content-Type', 'image/svg+xml');
|
|
73
|
+
event.res.headers.set('Cache-Control', 'public, max-age=86400');
|
|
74
|
+
return svg;
|
|
75
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineHandler } from 'nitro';
|
|
2
|
+
import { loadConfig } from '@/lib/config';
|
|
3
|
+
|
|
4
|
+
export default defineHandler(event => {
|
|
5
|
+
const config = loadConfig();
|
|
6
|
+
const sitemap = config.url ? `\nSitemap: ${config.url}/sitemap.xml` : '';
|
|
7
|
+
const body = `User-agent: *\nAllow: /${sitemap}`;
|
|
8
|
+
|
|
9
|
+
event.res.headers.set('Content-Type', 'text/plain');
|
|
10
|
+
return body;
|
|
11
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defineHandler } from 'nitro';
|
|
2
|
+
import { buildApiRoutes } from '@/lib/api-routes';
|
|
3
|
+
import { loadConfig } from '@/lib/config';
|
|
4
|
+
import { loadApiSpecs } from '@/lib/openapi';
|
|
5
|
+
import { getPages } from '@/lib/source';
|
|
6
|
+
|
|
7
|
+
export default defineHandler(async event => {
|
|
8
|
+
const config = loadConfig();
|
|
9
|
+
|
|
10
|
+
if (!config.url) {
|
|
11
|
+
event.res.headers.set('Content-Type', 'application/xml');
|
|
12
|
+
return '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"/>';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const baseUrl = config.url.replace(/\/$/, '');
|
|
16
|
+
|
|
17
|
+
const pages = await getPages();
|
|
18
|
+
const docPages = pages.map(page => {
|
|
19
|
+
const data = page.data as Record<string, unknown>;
|
|
20
|
+
const lastmod = data.lastModified
|
|
21
|
+
? `<lastmod>${new Date(data.lastModified as string).toISOString()}</lastmod>`
|
|
22
|
+
: '';
|
|
23
|
+
return `<url><loc>${baseUrl}/${page.slugs.join('/')}</loc>${lastmod}</url>`;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const apiPages = config.api?.length
|
|
27
|
+
? buildApiRoutes(await loadApiSpecs(config.api)).map(
|
|
28
|
+
route => `<url><loc>${baseUrl}/apis/${route.slug.join('/')}</loc></url>`
|
|
29
|
+
)
|
|
30
|
+
: [];
|
|
31
|
+
|
|
32
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
33
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
34
|
+
<url><loc>${baseUrl}</loc></url>
|
|
35
|
+
${[...docPages, ...apiPages].join('\n')}
|
|
36
|
+
</urlset>`;
|
|
37
|
+
|
|
38
|
+
event.res.headers.set('Content-Type', 'application/xml');
|
|
39
|
+
return xml;
|
|
40
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolve a URL path within a base directory, preventing path traversal.
|
|
5
|
+
* Returns null if the resolved path escapes the base directory.
|
|
6
|
+
*/
|
|
7
|
+
export function safePath(baseDir: string, urlPath: string): string | null {
|
|
8
|
+
const decoded = decodeURIComponent(urlPath.split('?')[0]);
|
|
9
|
+
const resolved = path.resolve(baseDir, '.' + decoded);
|
|
10
|
+
if (
|
|
11
|
+
!resolved.startsWith(path.resolve(baseDir) + path.sep) &&
|
|
12
|
+
resolved !== path.resolve(baseDir)
|
|
13
|
+
) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return resolved;
|
|
17
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import react from '@vitejs/plugin-react';
|
|
2
|
+
import { remarkDirectiveAdmonition, remarkMdxMermaid } from 'fumadocs-core/mdx-plugins';
|
|
3
|
+
import { defineConfig as defineFumadocsConfig } from 'fumadocs-mdx/config';
|
|
4
|
+
import mdx from 'fumadocs-mdx/vite';
|
|
5
|
+
import { nitro } from 'nitro/vite';
|
|
6
|
+
import fs from 'node:fs/promises';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import remarkDirective from 'remark-directive';
|
|
9
|
+
import { type InlineConfig } from 'vite';
|
|
10
|
+
import remarkUnusedDirectives from '../lib/remark-unused-directives';
|
|
11
|
+
|
|
12
|
+
function resolveOutputDir(projectRoot: string, preset?: string): string {
|
|
13
|
+
if (preset === 'vercel' || preset === 'vercel-static') return path.resolve(projectRoot, '.vercel/output');
|
|
14
|
+
return path.resolve(projectRoot, '.output');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ViteConfigOptions {
|
|
18
|
+
packageRoot: string;
|
|
19
|
+
projectRoot: string;
|
|
20
|
+
contentDir: string;
|
|
21
|
+
preset?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function readChronicleConfig(projectRoot: string, contentDir: string): Promise<string | null> {
|
|
25
|
+
for (const dir of [projectRoot, contentDir]) {
|
|
26
|
+
const filePath = path.join(dir, 'chronicle.yaml');
|
|
27
|
+
try {
|
|
28
|
+
return await fs.readFile(filePath, 'utf-8');
|
|
29
|
+
} catch {
|
|
30
|
+
// not found, try next
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function createViteConfig(
|
|
37
|
+
options: ViteConfigOptions
|
|
38
|
+
): Promise<InlineConfig> {
|
|
39
|
+
const { packageRoot, projectRoot, contentDir, preset } = options;
|
|
40
|
+
const rawConfig = await readChronicleConfig(projectRoot, contentDir);
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
root: packageRoot,
|
|
44
|
+
configFile: false,
|
|
45
|
+
plugins: [
|
|
46
|
+
nitro({
|
|
47
|
+
serverDir: path.resolve(packageRoot, 'src/server'),
|
|
48
|
+
...(preset && { preset }),
|
|
49
|
+
}),
|
|
50
|
+
mdx({
|
|
51
|
+
default: defineFumadocsConfig({
|
|
52
|
+
mdxOptions: {
|
|
53
|
+
remarkPlugins: [
|
|
54
|
+
remarkDirective,
|
|
55
|
+
[remarkDirectiveAdmonition, {
|
|
56
|
+
tags: {
|
|
57
|
+
CalloutContainer: 'Callout',
|
|
58
|
+
CalloutTitle: 'CalloutTitle',
|
|
59
|
+
CalloutDescription: 'CalloutDescription',
|
|
60
|
+
},
|
|
61
|
+
types: {
|
|
62
|
+
note: 'accent',
|
|
63
|
+
tip: 'accent',
|
|
64
|
+
info: 'accent',
|
|
65
|
+
warn: 'attention',
|
|
66
|
+
warning: 'attention',
|
|
67
|
+
danger: 'alert',
|
|
68
|
+
caution: 'alert',
|
|
69
|
+
success: 'success',
|
|
70
|
+
},
|
|
71
|
+
}],
|
|
72
|
+
remarkUnusedDirectives,
|
|
73
|
+
remarkMdxMermaid,
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
}, { index: false }),
|
|
78
|
+
react()
|
|
79
|
+
],
|
|
80
|
+
resolve: {
|
|
81
|
+
alias: {
|
|
82
|
+
'@': path.resolve(packageRoot, 'src'),
|
|
83
|
+
},
|
|
84
|
+
conditions: ['module-sync', 'import', 'node'],
|
|
85
|
+
dedupe: [
|
|
86
|
+
'react',
|
|
87
|
+
'react-dom',
|
|
88
|
+
'react/jsx-runtime',
|
|
89
|
+
'react/jsx-dev-runtime',
|
|
90
|
+
'react-router',
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
server: {
|
|
94
|
+
fs: {
|
|
95
|
+
allow: [packageRoot, projectRoot, contentDir]
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
define: {
|
|
99
|
+
__CHRONICLE_CONTENT_DIR__: JSON.stringify(contentDir),
|
|
100
|
+
__CHRONICLE_PROJECT_ROOT__: JSON.stringify(projectRoot),
|
|
101
|
+
__CHRONICLE_CONFIG_RAW__: JSON.stringify(rawConfig),
|
|
102
|
+
},
|
|
103
|
+
css: {
|
|
104
|
+
modules: {
|
|
105
|
+
localsConvention: 'camelCase'
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
ssr: {
|
|
109
|
+
noExternal: ['@raystack/apsara', 'dayjs', 'fumadocs-core']
|
|
110
|
+
},
|
|
111
|
+
environments: {
|
|
112
|
+
client: {
|
|
113
|
+
build: {
|
|
114
|
+
rollupOptions: {
|
|
115
|
+
input: path.resolve(packageRoot, 'src/server/entry-client.tsx')
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
nitro: {
|
|
121
|
+
output: {
|
|
122
|
+
dir: resolveOutputDir(projectRoot, preset),
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -1,64 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import
|
|
1
|
+
import { RectangleStackIcon } from '@heroicons/react/24/outline';
|
|
2
|
+
import {
|
|
3
|
+
Button,
|
|
4
|
+
Flex,
|
|
5
|
+
Headline,
|
|
6
|
+
Link,
|
|
7
|
+
Navbar,
|
|
8
|
+
Sidebar
|
|
9
|
+
} from '@raystack/apsara';
|
|
10
|
+
import { cx } from 'class-variance-authority';
|
|
11
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
12
|
+
import { Link as RouterLink, useLocation } from 'react-router';
|
|
13
|
+
import { MethodBadge } from '@/components/api/method-badge';
|
|
14
|
+
import { ClientThemeSwitcher } from '@/components/ui/client-theme-switcher';
|
|
15
|
+
import { Footer } from '@/components/ui/footer';
|
|
16
|
+
import { Search } from '@/components/ui/search';
|
|
17
|
+
import type { Node } from 'fumadocs-core/page-tree';
|
|
18
|
+
import type { ThemeLayoutProps } from '@/types';
|
|
19
|
+
import styles from './Layout.module.css';
|
|
15
20
|
|
|
16
21
|
const iconMap: Record<string, React.ReactNode> = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
'rectangle-stack': <RectangleStackIcon width={16} height={16} />,
|
|
23
|
+
'method-get': <MethodBadge method='GET' size='micro' />,
|
|
24
|
+
'method-post': <MethodBadge method='POST' size='micro' />,
|
|
25
|
+
'method-put': <MethodBadge method='PUT' size='micro' />,
|
|
26
|
+
'method-delete': <MethodBadge method='DELETE' size='micro' />,
|
|
27
|
+
'method-patch': <MethodBadge method='PATCH' size='micro' />
|
|
23
28
|
};
|
|
24
29
|
|
|
25
30
|
let savedScrollTop = 0;
|
|
26
31
|
|
|
27
|
-
export function Layout({
|
|
28
|
-
|
|
32
|
+
export function Layout({
|
|
33
|
+
children,
|
|
34
|
+
config,
|
|
35
|
+
tree,
|
|
36
|
+
classNames
|
|
37
|
+
}: ThemeLayoutProps) {
|
|
38
|
+
const { pathname } = useLocation();
|
|
29
39
|
const scrollRef = useRef<HTMLDivElement>(null);
|
|
30
40
|
|
|
31
41
|
useEffect(() => {
|
|
32
42
|
const el = scrollRef.current;
|
|
33
43
|
if (!el) return;
|
|
34
|
-
const onScroll = () => {
|
|
44
|
+
const onScroll = () => {
|
|
45
|
+
savedScrollTop = el.scrollTop;
|
|
46
|
+
};
|
|
35
47
|
el.addEventListener('scroll', onScroll);
|
|
36
48
|
return () => el.removeEventListener('scroll', onScroll);
|
|
37
49
|
}, []);
|
|
38
50
|
|
|
39
51
|
useEffect(() => {
|
|
40
52
|
const el = scrollRef.current;
|
|
41
|
-
if (el)
|
|
53
|
+
if (el)
|
|
54
|
+
requestAnimationFrame(() => {
|
|
55
|
+
el.scrollTop = savedScrollTop;
|
|
56
|
+
});
|
|
42
57
|
}, [pathname]);
|
|
43
58
|
|
|
44
59
|
return (
|
|
45
|
-
<Flex direction=
|
|
60
|
+
<Flex direction='column' className={cx(styles.layout, classNames?.layout)}>
|
|
46
61
|
<Navbar className={styles.header}>
|
|
47
62
|
<Navbar.Start>
|
|
48
|
-
<
|
|
49
|
-
|
|
63
|
+
<RouterLink
|
|
64
|
+
to='/'
|
|
65
|
+
style={{ textDecoration: 'none', color: 'inherit' }}
|
|
66
|
+
>
|
|
67
|
+
<Headline size='small' weight='medium' as='h1'>
|
|
50
68
|
{config.title}
|
|
51
69
|
</Headline>
|
|
52
|
-
</
|
|
70
|
+
</RouterLink>
|
|
53
71
|
</Navbar.Start>
|
|
54
72
|
<Navbar.End>
|
|
55
|
-
<Flex gap=
|
|
56
|
-
{config.api?.map(
|
|
57
|
-
<
|
|
73
|
+
<Flex gap='medium' align='center' className={styles.navActions}>
|
|
74
|
+
{config.api?.map(api => (
|
|
75
|
+
<RouterLink
|
|
76
|
+
key={api.basePath}
|
|
77
|
+
to={api.basePath}
|
|
78
|
+
className={styles.navButton}
|
|
79
|
+
>
|
|
58
80
|
{api.name} API
|
|
59
|
-
</
|
|
81
|
+
</RouterLink>
|
|
60
82
|
))}
|
|
61
|
-
{config.navigation?.links?.map(
|
|
83
|
+
{config.navigation?.links?.map(link => (
|
|
62
84
|
<Link key={link.href} href={link.href}>
|
|
63
85
|
{link.label}
|
|
64
86
|
</Link>
|
|
@@ -69,18 +91,24 @@ export function Layout({ children, config, tree, classNames }: ThemeLayoutProps)
|
|
|
69
91
|
</Navbar.End>
|
|
70
92
|
</Navbar>
|
|
71
93
|
<Flex className={cx(styles.body, classNames?.body)}>
|
|
72
|
-
<Sidebar
|
|
94
|
+
<Sidebar
|
|
95
|
+
defaultOpen
|
|
96
|
+
collapsible={false}
|
|
97
|
+
className={cx(styles.sidebar, classNames?.sidebar)}
|
|
98
|
+
>
|
|
73
99
|
<Sidebar.Main ref={scrollRef}>
|
|
74
|
-
{tree.children.map((item) => (
|
|
100
|
+
{tree.children.map((item, i) => (
|
|
75
101
|
<SidebarNode
|
|
76
|
-
key={item.url
|
|
102
|
+
key={item.type === 'page' ? item.url : (item.name?.toString() ?? i)}
|
|
77
103
|
item={item}
|
|
78
104
|
pathname={pathname}
|
|
79
105
|
/>
|
|
80
106
|
))}
|
|
81
107
|
</Sidebar.Main>
|
|
82
108
|
</Sidebar>
|
|
83
|
-
<main className={cx(styles.content, classNames?.content)}>
|
|
109
|
+
<main className={cx(styles.content, classNames?.content)}>
|
|
110
|
+
{children}
|
|
111
|
+
</main>
|
|
84
112
|
</Flex>
|
|
85
113
|
<Footer config={config.footer} />
|
|
86
114
|
</Flex>
|
|
@@ -89,25 +117,26 @@ export function Layout({ children, config, tree, classNames }: ThemeLayoutProps)
|
|
|
89
117
|
|
|
90
118
|
function SidebarNode({
|
|
91
119
|
item,
|
|
92
|
-
pathname
|
|
120
|
+
pathname
|
|
93
121
|
}: {
|
|
94
|
-
item:
|
|
122
|
+
item: Node;
|
|
95
123
|
pathname: string;
|
|
96
124
|
}) {
|
|
97
|
-
if (item.type ===
|
|
125
|
+
if (item.type === 'separator') {
|
|
98
126
|
return null;
|
|
99
127
|
}
|
|
100
128
|
|
|
101
|
-
if (item.type ===
|
|
129
|
+
if (item.type === 'folder') {
|
|
130
|
+
const icon = typeof item.icon === 'string' ? iconMap[item.icon] : item.icon;
|
|
102
131
|
return (
|
|
103
132
|
<Sidebar.Group
|
|
104
|
-
label={item.name}
|
|
105
|
-
leadingIcon={
|
|
133
|
+
label={item.name?.toString() ?? ''}
|
|
134
|
+
leadingIcon={icon ?? undefined}
|
|
106
135
|
classNames={{ items: styles.groupItems }}
|
|
107
136
|
>
|
|
108
|
-
{item.children.map((child) => (
|
|
137
|
+
{item.children.map((child, i) => (
|
|
109
138
|
<SidebarNode
|
|
110
|
-
key={child.url
|
|
139
|
+
key={child.type === 'page' ? child.url : (child.name?.toString() ?? i)}
|
|
111
140
|
item={child}
|
|
112
141
|
pathname={pathname}
|
|
113
142
|
/>
|
|
@@ -117,14 +146,15 @@ function SidebarNode({
|
|
|
117
146
|
}
|
|
118
147
|
|
|
119
148
|
const isActive = pathname === item.url;
|
|
120
|
-
const href = item.url ??
|
|
121
|
-
const
|
|
149
|
+
const href = item.url ?? '#';
|
|
150
|
+
const icon = typeof item.icon === 'string' ? iconMap[item.icon] : item.icon;
|
|
151
|
+
const link = useMemo(() => <RouterLink to={href} />, [href]);
|
|
122
152
|
|
|
123
153
|
return (
|
|
124
154
|
<Sidebar.Item
|
|
125
155
|
href={href}
|
|
126
156
|
active={isActive}
|
|
127
|
-
leadingIcon={
|
|
157
|
+
leadingIcon={icon ?? undefined}
|
|
128
158
|
as={link}
|
|
129
159
|
>
|
|
130
160
|
{item.name}
|
|
@@ -38,9 +38,53 @@
|
|
|
38
38
|
margin-bottom: var(--rs-space-3);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
.content img {
|
|
42
|
+
max-width: 100%;
|
|
43
|
+
height: auto;
|
|
44
|
+
}
|
|
45
|
+
|
|
41
46
|
.content table {
|
|
42
47
|
display: block;
|
|
43
48
|
max-width: 100%;
|
|
44
49
|
overflow-x: auto;
|
|
45
50
|
margin-bottom: var(--rs-space-5);
|
|
46
51
|
}
|
|
52
|
+
|
|
53
|
+
.content details {
|
|
54
|
+
border: 1px solid var(--rs-color-border-base-primary);
|
|
55
|
+
border-radius: var(--rs-radius-2);
|
|
56
|
+
margin: var(--rs-space-5) 0;
|
|
57
|
+
overflow: hidden;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.content details summary {
|
|
61
|
+
padding: var(--rs-space-4) var(--rs-space-5);
|
|
62
|
+
cursor: pointer;
|
|
63
|
+
font-weight: 500;
|
|
64
|
+
font-size: var(--rs-font-size-small);
|
|
65
|
+
color: var(--rs-color-text-base-primary);
|
|
66
|
+
background: var(--rs-color-background-base-secondary);
|
|
67
|
+
list-style: none;
|
|
68
|
+
display: flex;
|
|
69
|
+
align-items: center;
|
|
70
|
+
gap: var(--rs-space-3);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.content details summary::-webkit-details-marker {
|
|
74
|
+
display: none;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.content details summary::before {
|
|
78
|
+
content: '▶';
|
|
79
|
+
font-size: 10px;
|
|
80
|
+
transition: transform 0.2s ease;
|
|
81
|
+
color: var(--rs-color-text-base-secondary);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.content details[open] > summary::before {
|
|
85
|
+
transform: rotate(90deg);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.content details > :not(summary) {
|
|
89
|
+
padding: var(--rs-space-4) var(--rs-space-5);
|
|
90
|
+
}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
'use client'
|
|
1
|
+
'use client';
|
|
2
2
|
|
|
3
|
-
import { Flex } from '@raystack/apsara'
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
3
|
+
import { Flex } from '@raystack/apsara';
|
|
4
|
+
import { Breadcrumbs } from '@/components/ui/breadcrumbs';
|
|
5
|
+
import type { ThemePageProps } from '@/types';
|
|
6
|
+
import styles from './Page.module.css';
|
|
7
|
+
import { Toc } from './Toc';
|
|
8
8
|
|
|
9
9
|
export function Page({ page, tree }: ThemePageProps) {
|
|
10
10
|
return (
|
|
11
11
|
<Flex className={styles.page}>
|
|
12
|
-
<article className={styles.article}>
|
|
12
|
+
<article className={styles.article} data-article-content>
|
|
13
13
|
<Breadcrumbs slug={page.slug} tree={tree} />
|
|
14
|
-
<div className={styles.content}>
|
|
15
|
-
{page.content}
|
|
16
|
-
</div>
|
|
14
|
+
<div className={styles.content}>{page.content}</div>
|
|
17
15
|
</article>
|
|
18
16
|
<Toc items={page.toc} />
|
|
19
17
|
</Flex>
|
|
20
|
-
)
|
|
18
|
+
);
|
|
21
19
|
}
|
|
@@ -1,55 +1,41 @@
|
|
|
1
|
-
'use client'
|
|
1
|
+
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
6
|
-
import styles from './Toc.module.css'
|
|
3
|
+
import { Text } from '@raystack/apsara';
|
|
4
|
+
import { AnchorProvider, useActiveAnchor } from 'fumadocs-core/toc';
|
|
5
|
+
import type { TableOfContents, TOCItemType } from 'fumadocs-core/toc';
|
|
6
|
+
import styles from './Toc.module.css';
|
|
7
7
|
|
|
8
8
|
interface TocProps {
|
|
9
|
-
items:
|
|
9
|
+
items: TableOfContents;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function Toc({ items }: TocProps) {
|
|
13
|
-
const
|
|
13
|
+
const filteredItems = items.filter(
|
|
14
|
+
item => item.depth >= 2 && item.depth <= 3
|
|
15
|
+
);
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
const filteredItems = items.filter((item) => item.depth >= 2 && item.depth <= 3)
|
|
17
|
+
if (filteredItems.length === 0) return null;
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (entry.isIntersecting) {
|
|
25
|
-
setActiveId(entry.target.id)
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
},
|
|
29
|
-
// -80px top: offset for fixed header, -80% bottom: trigger when heading is in top 20% of viewport
|
|
30
|
-
{ rootMargin: '-80px 0px -80% 0px' }
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
headingIds.forEach((id) => {
|
|
34
|
-
const element = document.getElementById(id)
|
|
35
|
-
if (element) observer.observe(element)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
return () => observer.disconnect()
|
|
39
|
-
}, [filteredItems])
|
|
19
|
+
return (
|
|
20
|
+
<AnchorProvider toc={filteredItems} single>
|
|
21
|
+
<TocContent items={filteredItems} />
|
|
22
|
+
</AnchorProvider>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
40
25
|
|
|
41
|
-
|
|
26
|
+
function TocContent({ items }: { items: TOCItemType[] }) {
|
|
27
|
+
const activeAnchor = useActiveAnchor();
|
|
42
28
|
|
|
43
29
|
return (
|
|
44
30
|
<aside className={styles.toc}>
|
|
45
|
-
<Text size={1} weight=
|
|
31
|
+
<Text size={1} weight='medium' className={styles.title}>
|
|
46
32
|
On this page
|
|
47
33
|
</Text>
|
|
48
34
|
<nav className={styles.nav}>
|
|
49
|
-
{
|
|
50
|
-
const id = item.url.replace('#', '')
|
|
51
|
-
const isActive =
|
|
52
|
-
const isNested = item.depth > 2
|
|
35
|
+
{items.map(item => {
|
|
36
|
+
const id = item.url.replace('#', '');
|
|
37
|
+
const isActive = activeAnchor === id;
|
|
38
|
+
const isNested = item.depth > 2;
|
|
53
39
|
return (
|
|
54
40
|
<a
|
|
55
41
|
key={item.url}
|
|
@@ -58,9 +44,9 @@ export function Toc({ items }: TocProps) {
|
|
|
58
44
|
>
|
|
59
45
|
{item.title}
|
|
60
46
|
</a>
|
|
61
|
-
)
|
|
47
|
+
);
|
|
62
48
|
})}
|
|
63
49
|
</nav>
|
|
64
50
|
</aside>
|
|
65
|
-
)
|
|
51
|
+
);
|
|
66
52
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import type { Theme } from '@/types'
|
|
1
|
+
import type { Theme } from '@/types';
|
|
2
|
+
import { Layout } from './Layout';
|
|
3
|
+
import { Page } from './Page';
|
|
4
|
+
import { Toc } from './Toc';
|
|
6
5
|
|
|
7
6
|
export const defaultTheme: Theme = {
|
|
8
7
|
Layout,
|
|
9
|
-
Page
|
|
10
|
-
|
|
11
|
-
}
|
|
8
|
+
Page
|
|
9
|
+
};
|
|
12
10
|
|
|
13
|
-
export { Layout, Page, Toc }
|
|
11
|
+
export { Layout, Page, Toc };
|