-
-
Notifications
You must be signed in to change notification settings - Fork 329
Expand file tree
/
Copy pathDocBreadcrumb.tsx
More file actions
61 lines (53 loc) · 1.47 KB
/
DocBreadcrumb.tsx
File metadata and controls
61 lines (53 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { useParams } from '@tanstack/react-router'
import { Breadcrumbs } from './Breadcrumbs'
import type { ConfigSchema } from '~/utils/config'
import type { MarkdownHeading } from '~/utils/markdown/types'
function findSectionForDoc(
config: ConfigSchema,
docPath: string,
): string | null {
for (const section of config.sections) {
// Check core docs
for (const child of section.children) {
if (child.to === docPath) {
return section.label
}
}
// Check framework-specific docs in all frameworks
if (section.frameworks) {
for (const frameworkSection of section.frameworks) {
for (const child of frameworkSection.children) {
if (child.to === docPath) {
return section.label
}
}
}
}
}
return null
}
export function DocBreadcrumb({
config,
headings,
}: {
config: ConfigSchema
headings?: MarkdownHeading[]
}) {
const { _splat, framework } = useParams({ strict: false })
// Build the full doc path as it appears in config
// Config paths are like "overview" or "framework/react/overview"
const fullDocPath = framework ? `framework/${framework}/${_splat}` : _splat
// Find the section for this doc
const section = fullDocPath ? findSectionForDoc(config, fullDocPath) : null
// Only show if we found a section
if (!section) {
return null
}
return (
<Breadcrumbs
section={section}
headings={headings}
tocHiddenBreakpoint="lg"
/>
)
}