@raystack/chronicle 0.1.0-canary.49fe67c → 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 +72 -19
- package/package.json +1 -1
- 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/ui/breadcrumbs.tsx +8 -42
- package/src/lib/api-routes.ts +6 -8
- package/src/lib/mdx-loader.ts +21 -0
- package/src/lib/page-context.tsx +10 -16
- package/src/lib/source.ts +70 -100
- package/src/pages/DocsPage.tsx +1 -1
- package/src/server/api/page/[...slug].ts +5 -6
- package/src/server/entry-client.tsx +20 -25
- package/src/server/entry-server.tsx +23 -23
- package/src/server/routes/sitemap.xml.ts +3 -2
- package/src/server/vite-config.ts +45 -18
- package/src/themes/default/Layout.tsx +13 -10
- package/src/themes/default/Page.module.css +44 -0
- package/src/themes/default/Toc.tsx +14 -30
- package/src/themes/paper/ChapterNav.tsx +14 -14
- package/src/themes/paper/Page.module.css +5 -0
- package/src/themes/paper/Page.tsx +15 -41
- package/src/themes/paper/ReadingProgress.tsx +2 -2
- package/src/types/content.ts +5 -21
- package/src/types/globals.d.ts +0 -1
- package/src/types/theme.ts +4 -3
|
@@ -2,59 +2,33 @@ import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/react/24/outline';
|
|
|
2
2
|
import { Flex } from '@raystack/apsara';
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
import { Link as RouterLink, useLocation } from 'react-router';
|
|
5
|
+
import { getBreadcrumbItems } from 'fumadocs-core/breadcrumb';
|
|
6
|
+
import { flattenTree } from 'fumadocs-core/page-tree';
|
|
5
7
|
import { Search } from '@/components/ui/search';
|
|
6
|
-
import type {
|
|
8
|
+
import type { ThemePageProps } from '@/types';
|
|
7
9
|
import styles from './Page.module.css';
|
|
8
10
|
import { ReadingProgress } from './ReadingProgress';
|
|
9
11
|
|
|
10
|
-
function flattenTree(items: PageTreeItem[]): PageTreeItem[] {
|
|
11
|
-
const result: PageTreeItem[] = [];
|
|
12
|
-
for (const item of items) {
|
|
13
|
-
if (item.type === 'page' && item.url) result.push(item);
|
|
14
|
-
if (item.children) result.push(...flattenTree(item.children));
|
|
15
|
-
}
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function findBreadcrumb(
|
|
20
|
-
items: PageTreeItem[],
|
|
21
|
-
slug: string[]
|
|
22
|
-
): { 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(
|
|
33
|
-
items: PageTreeItem[],
|
|
34
|
-
path: string
|
|
35
|
-
): PageTreeItem | undefined {
|
|
36
|
-
for (const item of items) {
|
|
37
|
-
if (item.url === path) return item;
|
|
38
|
-
if (item.children) {
|
|
39
|
-
const found = findInTree(item.children, path);
|
|
40
|
-
if (found) return found;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
12
|
export function Page({ page, config, tree }: ThemePageProps) {
|
|
47
13
|
const { pathname } = useLocation();
|
|
48
14
|
|
|
49
15
|
const { prev, next, crumbs } = useMemo(() => {
|
|
50
16
|
const pages = flattenTree(tree.children);
|
|
51
17
|
const currentIndex = pages.findIndex(p => p.url === pathname);
|
|
18
|
+
const breadcrumbItems = getBreadcrumbItems(
|
|
19
|
+
pathname,
|
|
20
|
+
tree,
|
|
21
|
+
{ includePage: true }
|
|
22
|
+
);
|
|
52
23
|
return {
|
|
53
24
|
prev: currentIndex > 0 ? pages[currentIndex - 1] : null,
|
|
54
25
|
next: currentIndex < pages.length - 1 ? pages[currentIndex + 1] : null,
|
|
55
|
-
crumbs:
|
|
26
|
+
crumbs: breadcrumbItems.map(item => ({
|
|
27
|
+
label: item.name,
|
|
28
|
+
href: item.url ?? pathname,
|
|
29
|
+
})),
|
|
56
30
|
};
|
|
57
|
-
}, [tree, pathname
|
|
31
|
+
}, [tree, pathname]);
|
|
58
32
|
|
|
59
33
|
return (
|
|
60
34
|
<>
|
|
@@ -63,7 +37,7 @@ export function Page({ page, config, tree }: ThemePageProps) {
|
|
|
63
37
|
<Flex align='center' gap='small' className={styles.navLeft}>
|
|
64
38
|
{prev ? (
|
|
65
39
|
<RouterLink
|
|
66
|
-
to={prev.url
|
|
40
|
+
to={prev.url}
|
|
67
41
|
className={styles.arrow}
|
|
68
42
|
aria-label='Previous page'
|
|
69
43
|
>
|
|
@@ -80,7 +54,7 @@ export function Page({ page, config, tree }: ThemePageProps) {
|
|
|
80
54
|
)}
|
|
81
55
|
{next ? (
|
|
82
56
|
<RouterLink
|
|
83
|
-
to={next.url
|
|
57
|
+
to={next.url}
|
|
84
58
|
className={styles.arrow}
|
|
85
59
|
aria-label='Next page'
|
|
86
60
|
>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { cx } from 'class-variance-authority';
|
|
4
4
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
-
import type {
|
|
5
|
+
import type { TOCItemType } from 'fumadocs-core/toc';
|
|
6
6
|
import styles from './ReadingProgress.module.css';
|
|
7
7
|
|
|
8
8
|
interface Heading {
|
|
@@ -68,7 +68,7 @@ function resolveOverlaps(headings: Heading[], maxPosition: number): Heading[] {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
interface ReadingProgressProps {
|
|
71
|
-
items:
|
|
71
|
+
items: TOCItemType[];
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export function ReadingProgress({ items }: ReadingProgressProps) {
|
package/src/types/content.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { ReactNode } from 'react'
|
|
2
|
+
import type { TableOfContents } from 'fumadocs-core/toc'
|
|
3
|
+
|
|
4
|
+
export type { Root, Node, Item, Folder, Separator } from 'fumadocs-core/page-tree'
|
|
5
|
+
export type { TOCItemType, TableOfContents } from 'fumadocs-core/toc'
|
|
2
6
|
|
|
3
7
|
export interface Frontmatter {
|
|
4
8
|
title: string
|
|
@@ -12,25 +16,5 @@ export interface Page {
|
|
|
12
16
|
slug: string[]
|
|
13
17
|
frontmatter: Frontmatter
|
|
14
18
|
content: ReactNode
|
|
15
|
-
toc:
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface TocItem {
|
|
19
|
-
title: string
|
|
20
|
-
url: string
|
|
21
|
-
depth: number
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface PageTreeItem {
|
|
25
|
-
type: 'page' | 'folder' | 'separator'
|
|
26
|
-
name: string
|
|
27
|
-
url?: string
|
|
28
|
-
order?: number
|
|
29
|
-
icon?: string
|
|
30
|
-
children?: PageTreeItem[]
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface PageTree {
|
|
34
|
-
name: string
|
|
35
|
-
children: PageTreeItem[]
|
|
19
|
+
toc: TableOfContents
|
|
36
20
|
}
|
package/src/types/globals.d.ts
CHANGED
package/src/types/theme.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import type { ReactNode } from 'react'
|
|
2
|
+
import type { Root } from 'fumadocs-core/page-tree'
|
|
2
3
|
import type { ChronicleConfig } from './config'
|
|
3
|
-
import type { Page
|
|
4
|
+
import type { Page } from './content'
|
|
4
5
|
|
|
5
6
|
export interface ThemeLayoutProps {
|
|
6
7
|
children: ReactNode
|
|
7
8
|
config: ChronicleConfig
|
|
8
|
-
tree:
|
|
9
|
+
tree: Root
|
|
9
10
|
classNames?: { layout?: string; body?: string; sidebar?: string; content?: string }
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export interface ThemePageProps {
|
|
13
14
|
page: Page
|
|
14
15
|
config: ChronicleConfig
|
|
15
|
-
tree:
|
|
16
|
+
tree: Root
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export interface Theme {
|