@raystack/chronicle 0.1.0-canary.323385a → 0.1.0-canary.4a4a3f8
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 -9914
- 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/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 +31 -28
- package/src/lib/head.tsx +49 -0
- package/src/lib/mdx-loader.ts +21 -0
- package/src/lib/openapi.ts +8 -8
- package/src/lib/page-context.tsx +108 -0
- package/src/lib/source.ts +145 -56
- 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 +170 -0
- package/src/server/api/specs.ts +9 -0
- package/src/server/build-search-index.ts +117 -0
- package/src/server/entry-client.tsx +65 -0
- package/src/server/entry-server.tsx +95 -0
- package/src/server/routes/llms.txt.ts +61 -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 +111 -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 +3 -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
|
@@ -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 };
|
|
@@ -1,96 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { MethodBadge } from '@/components/api/method-badge'
|
|
6
|
-
import type { PageTree, PageTreeItem } from '@/types'
|
|
7
|
-
import styles from './ChapterNav.module.css'
|
|
1
|
+
import { Link as RouterLink, useLocation } from 'react-router';
|
|
2
|
+
import { MethodBadge } from '@/components/api/method-badge';
|
|
3
|
+
import type { Root, Node } from 'fumadocs-core/page-tree';
|
|
4
|
+
import styles from './ChapterNav.module.css';
|
|
8
5
|
|
|
9
6
|
const iconMap: Record<string, React.ReactNode> = {
|
|
10
|
-
'method-get': <MethodBadge method=
|
|
11
|
-
'method-post': <MethodBadge method=
|
|
12
|
-
'method-put': <MethodBadge method=
|
|
13
|
-
'method-delete': <MethodBadge method=
|
|
14
|
-
'method-patch': <MethodBadge method=
|
|
15
|
-
}
|
|
7
|
+
'method-get': <MethodBadge method='GET' size='micro' />,
|
|
8
|
+
'method-post': <MethodBadge method='POST' size='micro' />,
|
|
9
|
+
'method-put': <MethodBadge method='PUT' size='micro' />,
|
|
10
|
+
'method-delete': <MethodBadge method='DELETE' size='micro' />,
|
|
11
|
+
'method-patch': <MethodBadge method='PATCH' size='micro' />
|
|
12
|
+
};
|
|
16
13
|
|
|
17
14
|
interface ChapterNavProps {
|
|
18
|
-
tree:
|
|
15
|
+
tree: Root;
|
|
19
16
|
}
|
|
20
17
|
|
|
21
|
-
function buildChapterIndices(
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
function buildChapterIndices(
|
|
19
|
+
children: Node[]
|
|
20
|
+
): Map<Node, number> {
|
|
21
|
+
const indices = new Map<Node, number>();
|
|
22
|
+
let index = 0;
|
|
24
23
|
for (const item of children) {
|
|
25
|
-
if (item.type === 'folder'
|
|
26
|
-
index
|
|
27
|
-
indices.set(item, index)
|
|
24
|
+
if (item.type === 'folder') {
|
|
25
|
+
index++;
|
|
26
|
+
indices.set(item, index);
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
|
-
return indices
|
|
29
|
+
return indices;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
export function ChapterNav({ tree }: ChapterNavProps) {
|
|
34
|
-
const pathname =
|
|
35
|
-
const chapterIndices = buildChapterIndices(tree.children)
|
|
33
|
+
const { pathname } = useLocation();
|
|
34
|
+
const chapterIndices = buildChapterIndices(tree.children);
|
|
36
35
|
|
|
37
36
|
return (
|
|
38
37
|
<nav className={styles.nav}>
|
|
39
38
|
<ul className={styles.chapterItems}>
|
|
40
|
-
{tree.children.map(
|
|
41
|
-
if (item.type === 'separator') return null
|
|
39
|
+
{tree.children.map(item => {
|
|
40
|
+
if (item.type === 'separator') return null;
|
|
42
41
|
|
|
43
|
-
if (item.type === 'folder'
|
|
44
|
-
const chapterIndex = chapterIndices.get(item) ?? 0
|
|
42
|
+
if (item.type === 'folder') {
|
|
43
|
+
const chapterIndex = chapterIndices.get(item) ?? 0;
|
|
45
44
|
return (
|
|
46
|
-
<li key={item.name} className={styles.chapter}>
|
|
45
|
+
<li key={item.name?.toString()} className={styles.chapter}>
|
|
47
46
|
<span className={styles.chapterLabel}>
|
|
48
47
|
{String(chapterIndex).padStart(2, '0')}. {item.name}
|
|
49
48
|
</span>
|
|
50
49
|
<ul className={styles.chapterItems}>
|
|
51
|
-
{item.children.map(
|
|
52
|
-
<ChapterItem
|
|
50
|
+
{item.children.map(child => (
|
|
51
|
+
<ChapterItem
|
|
52
|
+
key={child.type === 'page' ? child.url : (child.name?.toString() ?? '')}
|
|
53
|
+
item={child}
|
|
54
|
+
pathname={pathname}
|
|
55
|
+
/>
|
|
53
56
|
))}
|
|
54
57
|
</ul>
|
|
55
58
|
</li>
|
|
56
|
-
)
|
|
59
|
+
);
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
return
|
|
62
|
+
return (
|
|
63
|
+
<ChapterItem
|
|
64
|
+
key={item.url ?? item.name?.toString() ?? ''}
|
|
65
|
+
item={item}
|
|
66
|
+
pathname={pathname}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
60
69
|
})}
|
|
61
70
|
</ul>
|
|
62
71
|
</nav>
|
|
63
|
-
)
|
|
72
|
+
);
|
|
64
73
|
}
|
|
65
74
|
|
|
66
|
-
function ChapterItem({
|
|
67
|
-
|
|
75
|
+
function ChapterItem({
|
|
76
|
+
item,
|
|
77
|
+
pathname
|
|
78
|
+
}: {
|
|
79
|
+
item: Node;
|
|
80
|
+
pathname: string;
|
|
81
|
+
}) {
|
|
82
|
+
if (item.type === 'separator') return null;
|
|
68
83
|
|
|
69
|
-
if (item.type === 'folder'
|
|
84
|
+
if (item.type === 'folder') {
|
|
70
85
|
return (
|
|
71
86
|
<li>
|
|
72
87
|
<span className={styles.subLabel}>{item.name}</span>
|
|
73
88
|
<ul className={styles.chapterItems}>
|
|
74
|
-
{item.children.map(
|
|
75
|
-
<ChapterItem
|
|
89
|
+
{item.children.map(child => (
|
|
90
|
+
<ChapterItem
|
|
91
|
+
key={child.type === 'page' ? child.url : (child.name?.toString() ?? '')}
|
|
92
|
+
item={child}
|
|
93
|
+
pathname={pathname}
|
|
94
|
+
/>
|
|
76
95
|
))}
|
|
77
96
|
</ul>
|
|
78
97
|
</li>
|
|
79
|
-
)
|
|
98
|
+
);
|
|
80
99
|
}
|
|
81
100
|
|
|
82
|
-
const isActive = pathname === item.url
|
|
83
|
-
const icon = item.icon ? iconMap[item.icon] :
|
|
101
|
+
const isActive = pathname === item.url;
|
|
102
|
+
const icon = typeof item.icon === 'string' ? iconMap[item.icon] : item.icon;
|
|
84
103
|
|
|
85
104
|
return (
|
|
86
105
|
<li>
|
|
87
|
-
<
|
|
88
|
-
|
|
106
|
+
<RouterLink
|
|
107
|
+
to={item.url ?? '#'}
|
|
89
108
|
className={`${styles.link} ${isActive ? styles.active : ''}`}
|
|
90
109
|
>
|
|
91
110
|
{icon && <span className={styles.icon}>{icon}</span>}
|
|
92
111
|
<span>{item.name}</span>
|
|
93
|
-
</
|
|
112
|
+
</RouterLink>
|
|
94
113
|
</li>
|
|
95
|
-
)
|
|
114
|
+
);
|
|
96
115
|
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
padding: var(--rs-space-7) var(--rs-space-5);
|
|
14
14
|
background: var(--rs-color-background-neutral-primary);
|
|
15
15
|
overflow-y: auto;
|
|
16
|
-
font-family:
|
|
16
|
+
font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
.title {
|
|
@@ -1,25 +1,37 @@
|
|
|
1
|
-
'use client'
|
|
1
|
+
'use client';
|
|
2
2
|
|
|
3
|
-
import { Flex, Headline } from '@raystack/apsara'
|
|
4
|
-
import { cx } from 'class-variance-authority'
|
|
5
|
-
import { Footer } from '@/components/ui/footer'
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import styles from './Layout.module.css'
|
|
3
|
+
import { Flex, Headline } from '@raystack/apsara';
|
|
4
|
+
import { cx } from 'class-variance-authority';
|
|
5
|
+
import { Footer } from '@/components/ui/footer';
|
|
6
|
+
import type { ThemeLayoutProps } from '@/types';
|
|
7
|
+
import { ChapterNav } from './ChapterNav';
|
|
8
|
+
import styles from './Layout.module.css';
|
|
9
9
|
|
|
10
|
-
export function Layout({
|
|
10
|
+
export function Layout({
|
|
11
|
+
children,
|
|
12
|
+
config,
|
|
13
|
+
tree,
|
|
14
|
+
classNames
|
|
15
|
+
}: ThemeLayoutProps) {
|
|
11
16
|
return (
|
|
12
|
-
<Flex direction=
|
|
17
|
+
<Flex direction='column' className={cx(styles.layout, classNames?.layout)}>
|
|
13
18
|
<Flex className={cx(styles.body, classNames?.body)}>
|
|
14
19
|
<aside className={cx(styles.sidebar, classNames?.sidebar)}>
|
|
15
|
-
<Headline
|
|
20
|
+
<Headline
|
|
21
|
+
size='small'
|
|
22
|
+
weight='medium'
|
|
23
|
+
as='h1'
|
|
24
|
+
className={styles.title}
|
|
25
|
+
>
|
|
16
26
|
{config.title}
|
|
17
27
|
</Headline>
|
|
18
28
|
<ChapterNav tree={tree} />
|
|
19
29
|
</aside>
|
|
20
|
-
<div className={cx(styles.content, classNames?.content)}>
|
|
30
|
+
<div className={cx(styles.content, classNames?.content)}>
|
|
31
|
+
{children}
|
|
32
|
+
</div>
|
|
21
33
|
</Flex>
|
|
22
34
|
<Footer config={config.footer} />
|
|
23
35
|
</Flex>
|
|
24
|
-
)
|
|
36
|
+
);
|
|
25
37
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
.main {
|
|
2
2
|
--paper-navbar-height: 40px;
|
|
3
3
|
--paper-navbar-padding: var(--rs-space-3);
|
|
4
|
-
--paper-navbar-total: calc(
|
|
4
|
+
--paper-navbar-total: calc(
|
|
5
|
+
var(--paper-navbar-height) +
|
|
6
|
+
var(--paper-navbar-padding) *
|
|
7
|
+
2 +
|
|
8
|
+
1px
|
|
9
|
+
);
|
|
5
10
|
|
|
6
11
|
flex: 1;
|
|
7
12
|
max-width: 1024px;
|
|
@@ -52,7 +57,7 @@
|
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
.breadcrumb {
|
|
55
|
-
font-family:
|
|
60
|
+
font-family: "SF Mono", "Fira Code", monospace;
|
|
56
61
|
font-size: var(--rs-font-size-small);
|
|
57
62
|
text-transform: uppercase;
|
|
58
63
|
letter-spacing: 0.05em;
|
|
@@ -94,13 +99,15 @@
|
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
.content {
|
|
97
|
-
font-family: Georgia,
|
|
102
|
+
font-family: Georgia, "Times New Roman", serif;
|
|
98
103
|
line-height: 1.8;
|
|
99
104
|
background: var(--rs-color-background-base-primary);
|
|
100
105
|
padding: var(--rs-space-9);
|
|
101
106
|
border-left: 1px solid var(--rs-color-border-base-primary);
|
|
102
107
|
border-right: 1px solid var(--rs-color-border-base-primary);
|
|
103
|
-
box-shadow:
|
|
108
|
+
box-shadow:
|
|
109
|
+
0 1px 3px rgba(0, 0, 0, 0.08),
|
|
110
|
+
0 4px 12px rgba(0, 0, 0, 0.04);
|
|
104
111
|
margin-bottom: var(--rs-space-9);
|
|
105
112
|
}
|
|
106
113
|
|
|
@@ -167,6 +174,11 @@
|
|
|
167
174
|
margin-bottom: var(--rs-space-3);
|
|
168
175
|
}
|
|
169
176
|
|
|
177
|
+
.content img {
|
|
178
|
+
max-width: 100%;
|
|
179
|
+
height: auto;
|
|
180
|
+
}
|
|
181
|
+
|
|
170
182
|
.content blockquote {
|
|
171
183
|
margin: 1rem 0;
|
|
172
184
|
padding-left: 1rem;
|
|
@@ -1,78 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { useMemo } from 'react'
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import type { ThemePageProps
|
|
9
|
-
import
|
|
10
|
-
import { ReadingProgress } from './ReadingProgress'
|
|
11
|
-
import styles from './Page.module.css'
|
|
12
|
-
|
|
13
|
-
function flattenTree(items: PageTreeItem[]): PageTreeItem[] {
|
|
14
|
-
const result: PageTreeItem[] = []
|
|
15
|
-
for (const item of items) {
|
|
16
|
-
if (item.type === 'page' && item.url) result.push(item)
|
|
17
|
-
if (item.children) result.push(...flattenTree(item.children))
|
|
18
|
-
}
|
|
19
|
-
return result
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function findBreadcrumb(items: PageTreeItem[], slug: string[]): { label: string; href: string }[] {
|
|
23
|
-
const result: { label: string; href: string }[] = []
|
|
24
|
-
for (let i = 0; i < slug.length; i++) {
|
|
25
|
-
const path = '/' + slug.slice(0, i + 1).join('/')
|
|
26
|
-
const found = findInTree(items, path)
|
|
27
|
-
result.push({ label: found?.name ?? slug[i], href: path })
|
|
28
|
-
}
|
|
29
|
-
return result
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function findInTree(items: PageTreeItem[], path: string): PageTreeItem | undefined {
|
|
33
|
-
for (const item of items) {
|
|
34
|
-
if (item.url === path) return item
|
|
35
|
-
if (item.children) {
|
|
36
|
-
const found = findInTree(item.children, path)
|
|
37
|
-
if (found) return found
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return undefined
|
|
41
|
-
}
|
|
1
|
+
import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/react/24/outline';
|
|
2
|
+
import { Flex } from '@raystack/apsara';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { Link as RouterLink, useLocation } from 'react-router';
|
|
5
|
+
import { getBreadcrumbItems } from 'fumadocs-core/breadcrumb';
|
|
6
|
+
import { flattenTree } from 'fumadocs-core/page-tree';
|
|
7
|
+
import { Search } from '@/components/ui/search';
|
|
8
|
+
import type { ThemePageProps } from '@/types';
|
|
9
|
+
import styles from './Page.module.css';
|
|
10
|
+
import { ReadingProgress } from './ReadingProgress';
|
|
42
11
|
|
|
43
12
|
export function Page({ page, config, tree }: ThemePageProps) {
|
|
44
|
-
const pathname =
|
|
13
|
+
const { pathname } = useLocation();
|
|
45
14
|
|
|
46
15
|
const { prev, next, crumbs } = useMemo(() => {
|
|
47
|
-
const pages = flattenTree(tree.children)
|
|
48
|
-
const currentIndex = pages.findIndex(
|
|
16
|
+
const pages = flattenTree(tree.children);
|
|
17
|
+
const currentIndex = pages.findIndex(p => p.url === pathname);
|
|
18
|
+
const breadcrumbItems = getBreadcrumbItems(
|
|
19
|
+
pathname,
|
|
20
|
+
tree,
|
|
21
|
+
{ includePage: true }
|
|
22
|
+
);
|
|
49
23
|
return {
|
|
50
24
|
prev: currentIndex > 0 ? pages[currentIndex - 1] : null,
|
|
51
25
|
next: currentIndex < pages.length - 1 ? pages[currentIndex + 1] : null,
|
|
52
|
-
crumbs:
|
|
53
|
-
|
|
54
|
-
|
|
26
|
+
crumbs: breadcrumbItems.map(item => ({
|
|
27
|
+
label: item.name,
|
|
28
|
+
href: item.url ?? pathname,
|
|
29
|
+
})),
|
|
30
|
+
};
|
|
31
|
+
}, [tree, pathname]);
|
|
55
32
|
|
|
56
33
|
return (
|
|
57
34
|
<>
|
|
58
35
|
<main className={styles.main}>
|
|
59
|
-
<Flex align=
|
|
60
|
-
<Flex align=
|
|
36
|
+
<Flex align='center' className={styles.navbar}>
|
|
37
|
+
<Flex align='center' gap='small' className={styles.navLeft}>
|
|
61
38
|
{prev ? (
|
|
62
|
-
<
|
|
39
|
+
<RouterLink
|
|
40
|
+
to={prev.url}
|
|
41
|
+
className={styles.arrow}
|
|
42
|
+
aria-label='Previous page'
|
|
43
|
+
>
|
|
63
44
|
<ChevronLeftIcon width={14} height={14} />
|
|
64
|
-
</
|
|
45
|
+
</RouterLink>
|
|
65
46
|
) : (
|
|
66
|
-
<button
|
|
47
|
+
<button
|
|
48
|
+
disabled
|
|
49
|
+
className={styles.arrowDisabled}
|
|
50
|
+
aria-label='Previous page'
|
|
51
|
+
>
|
|
67
52
|
<ChevronLeftIcon width={14} height={14} />
|
|
68
53
|
</button>
|
|
69
54
|
)}
|
|
70
55
|
{next ? (
|
|
71
|
-
<
|
|
56
|
+
<RouterLink
|
|
57
|
+
to={next.url}
|
|
58
|
+
className={styles.arrow}
|
|
59
|
+
aria-label='Next page'
|
|
60
|
+
>
|
|
72
61
|
<ChevronRightIcon width={14} height={14} />
|
|
73
|
-
</
|
|
62
|
+
</RouterLink>
|
|
74
63
|
) : (
|
|
75
|
-
<button
|
|
64
|
+
<button
|
|
65
|
+
disabled
|
|
66
|
+
className={styles.arrowDisabled}
|
|
67
|
+
aria-label='Next page'
|
|
68
|
+
>
|
|
76
69
|
<ChevronRightIcon width={14} height={14} />
|
|
77
70
|
</button>
|
|
78
71
|
)}
|
|
@@ -83,25 +76,25 @@ export function Page({ page, config, tree }: ThemePageProps) {
|
|
|
83
76
|
{i === crumbs.length - 1 ? (
|
|
84
77
|
<span className={styles.crumbActive}>{crumb.label}</span>
|
|
85
78
|
) : (
|
|
86
|
-
<
|
|
79
|
+
<RouterLink to={crumb.href} className={styles.crumbLink}>
|
|
87
80
|
{crumb.label}
|
|
88
|
-
</
|
|
81
|
+
</RouterLink>
|
|
89
82
|
)}
|
|
90
83
|
</span>
|
|
91
84
|
))}
|
|
92
85
|
</nav>
|
|
93
86
|
</Flex>
|
|
94
|
-
<Flex align=
|
|
95
|
-
{config.search?.enabled &&
|
|
87
|
+
<Flex align='center' className={styles.navRight}>
|
|
88
|
+
{config.search?.enabled && (
|
|
89
|
+
<Search className={styles.searchButton} />
|
|
90
|
+
)}
|
|
96
91
|
</Flex>
|
|
97
92
|
</Flex>
|
|
98
93
|
<article className={styles.article} data-article-content>
|
|
99
|
-
<div className={styles.content}>
|
|
100
|
-
{page.content}
|
|
101
|
-
</div>
|
|
94
|
+
<div className={styles.content}>{page.content}</div>
|
|
102
95
|
</article>
|
|
103
96
|
</main>
|
|
104
97
|
<ReadingProgress items={page.toc} />
|
|
105
98
|
</>
|
|
106
|
-
)
|
|
99
|
+
);
|
|
107
100
|
}
|