@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.
Files changed (80) hide show
  1. package/dist/cli/index.js +268 -9902
  2. package/package.json +20 -12
  3. package/src/cli/commands/build.ts +27 -25
  4. package/src/cli/commands/dev.ts +24 -25
  5. package/src/cli/commands/init.ts +38 -132
  6. package/src/cli/commands/serve.ts +36 -49
  7. package/src/cli/commands/start.ts +20 -25
  8. package/src/cli/index.ts +14 -14
  9. package/src/cli/utils/config.ts +25 -26
  10. package/src/cli/utils/index.ts +3 -3
  11. package/src/cli/utils/resolve.ts +9 -3
  12. package/src/cli/utils/scaffold.ts +11 -124
  13. package/src/components/mdx/code.tsx +10 -1
  14. package/src/components/mdx/details.module.css +1 -26
  15. package/src/components/mdx/details.tsx +2 -3
  16. package/src/components/mdx/image.tsx +5 -34
  17. package/src/components/mdx/index.tsx +15 -1
  18. package/src/components/mdx/link.tsx +18 -15
  19. package/src/components/ui/breadcrumbs.tsx +8 -42
  20. package/src/components/ui/search.tsx +63 -51
  21. package/src/lib/api-routes.ts +6 -8
  22. package/src/lib/config.ts +12 -35
  23. package/src/lib/head.tsx +49 -0
  24. package/src/lib/openapi.ts +8 -8
  25. package/src/lib/page-context.tsx +111 -0
  26. package/src/lib/source.ts +134 -63
  27. package/src/pages/ApiLayout.tsx +33 -0
  28. package/src/pages/ApiPage.tsx +73 -0
  29. package/src/pages/DocsLayout.tsx +18 -0
  30. package/src/pages/DocsPage.tsx +43 -0
  31. package/src/pages/NotFound.tsx +17 -0
  32. package/src/server/App.tsx +67 -0
  33. package/src/server/api/apis-proxy.ts +69 -0
  34. package/src/server/api/health.ts +5 -0
  35. package/src/server/api/page/[...slug].ts +17 -0
  36. package/src/server/api/search.ts +118 -0
  37. package/src/server/api/specs.ts +9 -0
  38. package/src/server/build-search-index.ts +117 -0
  39. package/src/server/entry-client.tsx +86 -0
  40. package/src/server/entry-server.tsx +100 -0
  41. package/src/server/routes/llms.txt.ts +21 -0
  42. package/src/server/routes/og.tsx +75 -0
  43. package/src/server/routes/robots.txt.ts +11 -0
  44. package/src/server/routes/sitemap.xml.ts +40 -0
  45. package/src/server/utils/safe-path.ts +17 -0
  46. package/src/server/vite-config.ts +126 -0
  47. package/src/themes/default/Layout.tsx +78 -48
  48. package/src/themes/default/Page.module.css +44 -0
  49. package/src/themes/default/Page.tsx +9 -11
  50. package/src/themes/default/Toc.tsx +25 -39
  51. package/src/themes/default/index.ts +7 -9
  52. package/src/themes/paper/ChapterNav.tsx +64 -45
  53. package/src/themes/paper/Layout.module.css +1 -1
  54. package/src/themes/paper/Layout.tsx +24 -12
  55. package/src/themes/paper/Page.module.css +16 -4
  56. package/src/themes/paper/Page.tsx +56 -63
  57. package/src/themes/paper/ReadingProgress.tsx +160 -139
  58. package/src/themes/paper/index.ts +5 -5
  59. package/src/themes/registry.ts +7 -7
  60. package/src/types/config.ts +11 -0
  61. package/src/types/content.ts +6 -21
  62. package/src/types/globals.d.ts +4 -0
  63. package/src/types/theme.ts +4 -3
  64. package/tsconfig.json +2 -3
  65. package/next.config.mjs +0 -10
  66. package/source.config.ts +0 -50
  67. package/src/app/[[...slug]]/layout.tsx +0 -15
  68. package/src/app/[[...slug]]/page.tsx +0 -57
  69. package/src/app/api/apis-proxy/route.ts +0 -59
  70. package/src/app/api/health/route.ts +0 -3
  71. package/src/app/api/search/route.ts +0 -90
  72. package/src/app/apis/[[...slug]]/layout.tsx +0 -26
  73. package/src/app/apis/[[...slug]]/page.tsx +0 -57
  74. package/src/app/layout.tsx +0 -26
  75. package/src/app/llms-full.txt/route.ts +0 -18
  76. package/src/app/llms.txt/route.ts +0 -15
  77. package/src/app/providers.tsx +0 -8
  78. package/src/cli/utils/process.ts +0 -7
  79. package/src/themes/default/font.ts +0 -6
  80. /package/src/{app/apis/[[...slug]]/layout.module.css → pages/ApiLayout.module.css} +0 -0
@@ -1,96 +1,115 @@
1
- 'use client'
2
-
3
- import { usePathname } from 'next/navigation'
4
- import NextLink from 'next/link'
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="GET" size="micro" />,
11
- 'method-post': <MethodBadge method="POST" size="micro" />,
12
- 'method-put': <MethodBadge method="PUT" size="micro" />,
13
- 'method-delete': <MethodBadge method="DELETE" size="micro" />,
14
- 'method-patch': <MethodBadge method="PATCH" size="micro" />,
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: PageTree
15
+ tree: Root;
19
16
  }
20
17
 
21
- function buildChapterIndices(children: PageTreeItem[]): Map<PageTreeItem, number> {
22
- const indices = new Map<PageTreeItem, number>()
23
- let index = 0
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' && item.children) {
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 = usePathname()
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((item) => {
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' && item.children) {
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((child) => (
52
- <ChapterItem key={child.url ?? child.name} item={child} pathname={pathname} />
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 <ChapterItem key={item.url ?? item.name} item={item} pathname={pathname} />
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({ item, pathname }: { item: PageTreeItem; pathname: string }) {
67
- if (item.type === 'separator') return null
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' && item.children) {
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((child) => (
75
- <ChapterItem key={child.url ?? child.name} item={child} pathname={pathname} />
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] : null
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
- <NextLink
88
- href={item.url ?? '#'}
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
- </NextLink>
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: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', monospace;
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 { ChapterNav } from './ChapterNav'
7
- import type { ThemeLayoutProps } from '@/types'
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({ children, config, tree, classNames }: ThemeLayoutProps) {
10
+ export function Layout({
11
+ children,
12
+ config,
13
+ tree,
14
+ classNames
15
+ }: ThemeLayoutProps) {
11
16
  return (
12
- <Flex direction="column" className={cx(styles.layout, classNames?.layout)}>
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 size="small" weight="medium" as="h1" className={styles.title}>
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)}>{children}</div>
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(var(--paper-navbar-height) + var(--paper-navbar-padding) * 2 + 1px);
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: 'SF Mono', 'Fira Code', monospace;
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, 'Times New Roman', serif;
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: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
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
- 'use client'
2
-
3
- import { useMemo } from 'react'
4
- import { usePathname } from 'next/navigation'
5
- import NextLink from 'next/link'
6
- import { Flex } from '@raystack/apsara'
7
- import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/react/24/outline'
8
- import type { ThemePageProps, PageTreeItem } from '@/types'
9
- import { Search } from '@/components/ui/search'
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 = usePathname()
13
+ const { pathname } = useLocation();
45
14
 
46
15
  const { prev, next, crumbs } = useMemo(() => {
47
- const pages = flattenTree(tree.children)
48
- const currentIndex = pages.findIndex((p) => p.url === pathname)
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: findBreadcrumb(tree.children, page.slug),
53
- }
54
- }, [tree, pathname, page.slug])
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="center" className={styles.navbar}>
60
- <Flex align="center" gap="small" className={styles.navLeft}>
36
+ <Flex align='center' className={styles.navbar}>
37
+ <Flex align='center' gap='small' className={styles.navLeft}>
61
38
  {prev ? (
62
- <NextLink href={prev.url!} className={styles.arrow} aria-label="Previous page">
39
+ <RouterLink
40
+ to={prev.url}
41
+ className={styles.arrow}
42
+ aria-label='Previous page'
43
+ >
63
44
  <ChevronLeftIcon width={14} height={14} />
64
- </NextLink>
45
+ </RouterLink>
65
46
  ) : (
66
- <button disabled className={styles.arrowDisabled} aria-label="Previous page">
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
- <NextLink href={next.url!} className={styles.arrow} aria-label="Next page">
56
+ <RouterLink
57
+ to={next.url}
58
+ className={styles.arrow}
59
+ aria-label='Next page'
60
+ >
72
61
  <ChevronRightIcon width={14} height={14} />
73
- </NextLink>
62
+ </RouterLink>
74
63
  ) : (
75
- <button disabled className={styles.arrowDisabled} aria-label="Next page">
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
- <NextLink href={crumb.href} className={styles.crumbLink}>
79
+ <RouterLink to={crumb.href} className={styles.crumbLink}>
87
80
  {crumb.label}
88
- </NextLink>
81
+ </RouterLink>
89
82
  )}
90
83
  </span>
91
84
  ))}
92
85
  </nav>
93
86
  </Flex>
94
- <Flex align="center" className={styles.navRight}>
95
- {config.search?.enabled && <Search className={styles.searchButton} />}
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
  }