pr_01m47d15m3e54sn21z27rpy5n9/apps/web/app/routes/docs.tsx
| 1 | import { NavLink, data } from "react-router"; |
| 2 | |
| 3 | import type { Route } from "./+types/docs"; |
| 4 | import { Markdown } from "../components/markdown"; |
| 5 | |
| 6 | const sources = import.meta.glob<string>("../docs/*.md", { |
| 7 | query: "?raw", |
| 8 | import: "default", |
| 9 | eager: true, |
| 10 | }); |
| 11 | |
| 12 | const PAGES: { slug: string; title: string }[] = [ |
| 13 | { slug: "", title: "Getting started" }, |
| 14 | { slug: "concepts", title: "Concepts" }, |
| 15 | { slug: "git", title: "Git" }, |
| 16 | { slug: "agents", title: "Connect an agent" }, |
| 17 | { slug: "api", title: "API" }, |
| 18 | ]; |
| 19 | |
| 20 | export function meta({ loaderData }: Route.MetaArgs) { |
| 21 | return [{ title: `${loaderData?.title ?? "Docs"} · g1t docs` }]; |
| 22 | } |
| 23 | |
| 24 | export function loader({ params }: Route.LoaderArgs) { |
| 25 | const slug = params.page ?? ""; |
| 26 | const page = PAGES.find((candidate) => candidate.slug === slug); |
| 27 | const source = sources[`../docs/${slug || "index"}.md`]; |
| 28 | if (!page || !source) throw data(null, { status: 404 }); |
| 29 | return { title: page.title, source }; |
| 30 | } |
| 31 | |
| 32 | export default function Docs({ loaderData }: Route.ComponentProps) { |
| 33 | return ( |
| 34 | <div className="mx-auto grid max-w-6xl gap-10 px-4 py-10 md:grid-cols-[13rem_1fr]"> |
| 35 | <nav aria-label="Documentation" className="md:sticky md:top-24 md:self-start"> |
| 36 | <p className="px-3 text-xs font-medium tracking-wide text-faint uppercase"> |
| 37 | Documentation |
| 38 | </p> |
| 39 | <ul className="mt-3 space-y-0.5"> |
| 40 | {PAGES.map((page) => ( |
| 41 | <li key={page.slug}> |
| 42 | <NavLink |
| 43 | to={page.slug ? `/docs/${page.slug}` : "/docs"} |
| 44 | end |
| 45 | className={({ isActive }) => |
| 46 | `block rounded-md px-3 py-1.5 text-sm transition-colors ${ |
| 47 | isActive |
| 48 | ? "bg-raised font-medium text-fg" |
| 49 | : "text-muted hover:text-fg" |
| 50 | }` |
| 51 | } |
| 52 | > |
| 53 | {page.title} |
| 54 | </NavLink> |
| 55 | </li> |
| 56 | ))} |
| 57 | </ul> |
| 58 | </nav> |
| 59 | <article className="max-w-3xl min-w-0"> |
| 60 | <Markdown source={loaderData.source} /> |
| 61 | </article> |
| 62 | </div> |
| 63 | ); |
| 64 | } |