|
| 1 | +--- |
| 2 | +import { getCollection } from "astro:content"; |
| 3 | +import { Icon } from "astro-icon/components"; |
| 4 | +import type { DocumentedProject } from "../lib/types"; |
| 5 | +
|
| 6 | +interface Props { |
| 7 | + project: DocumentedProject; |
| 8 | + currentPath: string; |
| 9 | +} |
| 10 | +
|
| 11 | +const { project, currentPath } = Astro.props; |
| 12 | +
|
| 13 | +const allDocs = await getCollection("docs", (entry) => { |
| 14 | + return entry.data.project === project.slug; |
| 15 | +}); |
| 16 | +
|
| 17 | +const sorted = allDocs.sort((a, b) => a.data.order - b.data.order); |
| 18 | +
|
| 19 | +const sections = [ |
| 20 | + { key: "overview" as const, label: "Overview" }, |
| 21 | + { key: "guides" as const, label: "Guides" }, |
| 22 | + { key: "resources" as const, label: "Resources" }, |
| 23 | +]; |
| 24 | +
|
| 25 | +function getDocPath(entry: (typeof allDocs)[number]): string { |
| 26 | + // The glob loader generates ids like "ex_machina" for index.md |
| 27 | + // and "ex_machina/getting-started" for other files |
| 28 | + const slug = entry.id.replace(`${project.slug}/`, "").replace(project.slug, ""); |
| 29 | + if (!slug || slug === "index") { |
| 30 | + return `/projects/${project.slug}`; |
| 31 | + } |
| 32 | + return `/projects/${project.slug}/${slug}`; |
| 33 | +} |
| 34 | +--- |
| 35 | + |
| 36 | +<aside class="w-64 shrink-0"> |
| 37 | + <nav class="sticky top-20 space-y-6"> |
| 38 | + <div> |
| 39 | + <a |
| 40 | + href={`/projects/${project.slug}`} |
| 41 | + class="text-lg font-semibold text-slate-900 hover:text-purple-700 transition-colors" |
| 42 | + > |
| 43 | + {project.name} |
| 44 | + </a> |
| 45 | + </div> |
| 46 | + |
| 47 | + {sections.map((section) => { |
| 48 | + const entries = sorted.filter((e) => e.data.section === section.key); |
| 49 | + if (entries.length === 0) return null; |
| 50 | + return ( |
| 51 | + <div> |
| 52 | + <h3 class="mb-2 text-xs font-semibold uppercase tracking-wider text-slate-400"> |
| 53 | + {section.label} |
| 54 | + </h3> |
| 55 | + <ul class="space-y-1"> |
| 56 | + {entries.map((entry) => { |
| 57 | + const href = getDocPath(entry); |
| 58 | + const isActive = currentPath === href; |
| 59 | + return ( |
| 60 | + <li> |
| 61 | + <a |
| 62 | + href={href} |
| 63 | + class:list={[ |
| 64 | + "block rounded-md px-3 py-1.5 text-sm transition-colors", |
| 65 | + isActive |
| 66 | + ? "bg-purple-50 font-medium text-purple-700" |
| 67 | + : "text-slate-600 hover:bg-slate-50 hover:text-slate-900", |
| 68 | + ]} |
| 69 | + > |
| 70 | + {entry.data.title} |
| 71 | + </a> |
| 72 | + </li> |
| 73 | + ); |
| 74 | + })} |
| 75 | + </ul> |
| 76 | + </div> |
| 77 | + ); |
| 78 | + })} |
| 79 | + |
| 80 | + <hr class="border-slate-200" /> |
| 81 | + |
| 82 | + <div class="space-y-2"> |
| 83 | + <a |
| 84 | + href={project.hexdocsUrl} |
| 85 | + target="_blank" |
| 86 | + rel="noopener noreferrer" |
| 87 | + class="flex items-center gap-2 text-sm text-slate-500 hover:text-purple-700 transition-colors" |
| 88 | + > |
| 89 | + <Icon name="lucide:book-open" class="h-4 w-4" /> |
| 90 | + API Reference |
| 91 | + <Icon name="lucide:external-link" class="h-3 w-3" /> |
| 92 | + </a> |
| 93 | + <a |
| 94 | + href={project.githubUrl} |
| 95 | + target="_blank" |
| 96 | + rel="noopener noreferrer" |
| 97 | + class="flex items-center gap-2 text-sm text-slate-500 hover:text-purple-700 transition-colors" |
| 98 | + > |
| 99 | + <Icon name="simple-icons:github" class="h-4 w-4" /> |
| 100 | + GitHub |
| 101 | + <Icon name="lucide:external-link" class="h-3 w-3" /> |
| 102 | + </a> |
| 103 | + <a |
| 104 | + href={project.hexUrl} |
| 105 | + target="_blank" |
| 106 | + rel="noopener noreferrer" |
| 107 | + class="flex items-center gap-2 text-sm text-slate-500 hover:text-purple-700 transition-colors" |
| 108 | + > |
| 109 | + <Icon name="simple-icons:elixir" class="h-4 w-4" /> |
| 110 | + Hex.pm |
| 111 | + <Icon name="lucide:external-link" class="h-3 w-3" /> |
| 112 | + </a> |
| 113 | + </div> |
| 114 | + </nav> |
| 115 | +</aside> |
0 commit comments