| 27 | } |
| 28 | |
| 29 | export function getBreadcrumbs({ |
| 30 | path: originalPath, |
| 31 | docs, |
| 32 | }: { |
| 33 | path: string; |
| 34 | docs: Record<string, DocsEntry>; |
| 35 | }) { |
| 36 | const path = originalPath.replace(/\/$/, "").replace(/^\//, ""); |
| 37 | const breadcrumbs = []; |
| 38 | |
| 39 | let foundIndex = 0; |
| 40 | while ((foundIndex = path.indexOf("/", foundIndex + 1)) !== -1) { |
| 41 | const part = path.slice(0, foundIndex); |
| 42 | breadcrumbs.push(part); |
| 43 | } |
| 44 | |
| 45 | return breadcrumbs |
| 46 | .filter((path) => docs[path]) |
| 47 | .map((path) => ({ |
| 48 | title: docs[path].data.title, |
| 49 | path: `/${path}`, |
| 50 | })); |
| 51 | } |