The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | /** |
| 2 | * The docs tab bar (primary navigation). |
| 3 | * |
| 4 | * Each tab owns a URL prefix and a sidebar: the tab bar renders in the docs |
| 5 | * header (see `components/starlight/DocsTabs.astro`) and the route middleware |
| 6 | * (`docs-tabs-sidebar.ts`) swaps in the sidebar group whose label matches the |
| 7 | * active tab. The `label` here MUST match the top-level group label in |
| 8 | * `astro.config.ts`'s `sidebar` array. |
| 9 | * |
| 10 | * Placement (`slot`): |
| 11 | * - "start" — always-visible tabs on the left: Alchemy itself (Core, CLI, |
| 12 | * Domain), not third-party providers. |
| 13 | * - "hub" — provider hubs, grouped by `category`. Desktop renders one |
| 14 | * hover dropdown per category (single-hub categories share a |
| 15 | * "More" dropdown); the mobile drawer renders the same groups as |
| 16 | * headings. Adding a provider means adding one entry here. |
| 17 | * - "end" — meta sections pinned to the right (Reference, Blog, Compare). |
| 18 | */ |
| 19 | export interface DocsTab { |
| 20 | label: string; |
| 21 | href: string; |
| 22 | /** URL path prefixes this tab owns (matched on segment boundaries). */ |
| 23 | prefixes: string[]; |
| 24 | slot: "start" | "hub" | "end"; |
| 25 | /** Dropdown category (required for slot: "hub"). */ |
| 26 | category?: DocsCategory; |
| 27 | /** One-line scope hint shown in the dropdown. */ |
| 28 | hint?: string; |
| 29 | } |
| 30 | |
| 31 | /** Hub categories, in header order. */ |
| 32 | export const DOCS_CATEGORIES = [ |
| 33 | "Clouds", |
| 34 | "Containers", |
| 35 | "Databases", |
| 36 | "Auth", |
| 37 | "Payments", |
| 38 | "Observability", |
| 39 | "Source & CI", |
| 40 | "Certificates", |
| 41 | ] as const; |
| 42 | export type DocsCategory = (typeof DOCS_CATEGORIES)[number]; |
| 43 | |
| 44 | const hub = ( |
| 45 | label: string, |
| 46 | slug: string, |
| 47 | category: DocsCategory, |
| 48 | hint: string, |
| 49 | extraPrefixes: string[] = [], |
| 50 | ): DocsTab => ({ |
| 51 | label, |
| 52 | href: `/${slug}`, |
| 53 | prefixes: [`/${slug}`, ...extraPrefixes], |
| 54 | slot: "hub", |
| 55 | category, |
| 56 | hint, |
| 57 | }); |
| 58 | |
| 59 | export const DOCS_TABS: DocsTab[] = [ |
| 60 | { label: "Core", href: "/getting-started", prefixes: [], slot: "start" }, |
| 61 | { label: "CLI", href: "/cli", prefixes: ["/cli"], slot: "start" }, |
| 62 | { |
| 63 | label: "Domain", |
| 64 | href: "/domain", |
| 65 | prefixes: ["/domain", "/providers/domain"], |
| 66 | slot: "start", |
| 67 | }, |
| 68 | |
| 69 | hub("Cloudflare", "cloudflare", "Clouds", "workers · durable objects · R2 · D1", [ |
| 70 | "/providers/cloudflare", |
| 71 | ]), |
| 72 | hub("AWS", "aws", "Clouds", "lambda · ECS · S3 · DynamoDB", ["/providers/aws"]), |
| 73 | hub("GCP", "gcp", "Clouds", "cloud run · storage · pub/sub", ["/providers/gcp"]), |
| 74 | hub("Hetzner", "hetzner", "Clouds", "servers · networks · volumes", ["/providers/hetzner"]), |
| 75 | hub("Fly", "fly", "Clouds", "apps · machines · volumes", ["/providers/fly"]), |
| 76 | hub("Railway", "railway", "Clouds", "services · environments · volumes", ["/providers/railway"]), |
| 77 | |
| 78 | hub("PlanetScale", "planetscale", "Databases", "MySQL · Postgres · branches", [ |
| 79 | "/providers/planetscale", |
| 80 | ]), |
| 81 | hub("Neon", "neon", "Databases", "serverless Postgres · branches", ["/providers/neon"]), |
| 82 | hub("Turso", "turso", "Databases", "libSQL · groups · tokens", ["/providers/turso"]), |
| 83 | hub("Prisma", "prisma", "Databases", "Prisma Postgres · client", ["/providers/prisma"]), |
| 84 | hub("SQL", "sql", "Databases", "effect-sql · drizzle · migrations", [ |
| 85 | "/drizzle", |
| 86 | "/providers/drizzle", |
| 87 | "/providers/sql", |
| 88 | ]), |
| 89 | |
| 90 | hub("Better Auth", "better-auth", "Auth", "sessions · plugins · database layers", [ |
| 91 | "/providers/betterauth", |
| 92 | ]), |
| 93 | hub("Stripe", "stripe", "Payments", "products · prices · webhooks", ["/providers/stripe"]), |
| 94 | hub("Axiom", "axiom", "Observability", "logs · traces · alerts", ["/providers/axiom"]), |
| 95 | hub("GitHub", "github", "Source & CI", "repos · secrets · events", ["/providers/github"]), |
| 96 | hub("ACME", "acme", "Certificates", "accounts · DNS-01 · certificate issuance", [ |
| 97 | "/providers/acme", |
| 98 | ]), |
| 99 | |
| 100 | hub("Docker", "docker", "Containers", "images · containers · networks", ["/providers/docker"]), |
| 101 | hub("Kubernetes", "kubernetes", "Containers", "deployments · jobs · manifests · helm", [ |
| 102 | "/providers/kubernetes", |
| 103 | ]), |
| 104 | hub("Git", "git", "Source & CI", "self-hosted git · clone · push · pull requests", [ |
| 105 | "/providers/git", |
| 106 | ]), |
| 107 | hub("Command", "command", "Source & CI", "build · dev · exec", ["/providers/command"]), |
| 108 | |
| 109 | // A provider's reference pages belong to its hub tab (the prefixes |
| 110 | // above claim /providers/{provider} first) — the Reference tab owns |
| 111 | // only the directory landing plus providers without a hub. |
| 112 | { |
| 113 | label: "Reference", |
| 114 | href: "/providers", |
| 115 | prefixes: ["/providers"], |
| 116 | slot: "end", |
| 117 | }, |
| 118 | { label: "Blog", href: "/blog", prefixes: ["/blog"], slot: "end" }, |
| 119 | // A marketing page, so it never becomes the active tab. |
| 120 | { label: "Compare", href: "/compare", prefixes: ["/compare"], slot: "end" }, |
| 121 | ]; |
| 122 | |
| 123 | export interface DocsTabSection { |
| 124 | /** Sub-heading inside a dropdown (only set inside "More"). */ |
| 125 | heading?: DocsCategory; |
| 126 | tabs: DocsTab[]; |
| 127 | } |
| 128 | |
| 129 | export interface DocsTabGroup { |
| 130 | label: DocsCategory | "More"; |
| 131 | sections: DocsTabSection[]; |
| 132 | } |
| 133 | |
| 134 | const alphabetically = (a: string, b: string) => a.localeCompare(b, "en", { sensitivity: "base" }); |
| 135 | |
| 136 | /** |
| 137 | * Hub tabs grouped into header dropdowns, in header order. A category with |
| 138 | * a single hub doesn't earn its own dropdown: it folds into a trailing |
| 139 | * "More" (under its category sub-heading) until a second hub joins it. |
| 140 | * Hubs within a dropdown sort alphabetically, and so do the single-hub |
| 141 | * sections inside "More" (by hub name); `DOCS_TABS` keeps its order for |
| 142 | * prefix matching. |
| 143 | */ |
| 144 | export const DOCS_TAB_GROUPS: DocsTabGroup[] = (() => { |
| 145 | const sections = DOCS_CATEGORIES.map((category) => ({ |
| 146 | heading: category, |
| 147 | tabs: DOCS_TABS.filter((tab) => tab.category === category).sort((a, b) => |
| 148 | alphabetically(a.label, b.label), |
| 149 | ), |
| 150 | })).filter((section) => section.tabs.length > 0); |
| 151 | const own = sections.filter((section) => section.tabs.length > 1); |
| 152 | const more = sections |
| 153 | .filter((section) => section.tabs.length === 1) |
| 154 | .sort((a, b) => alphabetically(a.tabs[0]!.label, b.tabs[0]!.label)); |
| 155 | return [ |
| 156 | ...own.map(({ heading, tabs }) => ({ label: heading, sections: [{ tabs }] })), |
| 157 | ...(more.length > 0 ? [{ label: "More" as const, sections: more }] : []), |
| 158 | ]; |
| 159 | })(); |
| 160 | |
| 161 | /** Every hub tab in a group, across its sections. */ |
| 162 | export const groupTabs = (group: DocsTabGroup): DocsTab[] => |
| 163 | group.sections.flatMap((section) => section.tabs); |
| 164 | |
| 165 | const matches = (pathname: string, prefix: string) => |
| 166 | pathname === prefix || pathname.startsWith(`${prefix}/`); |
| 167 | |
| 168 | /** |
| 169 | * Resolve the active tab for a pathname. Core (the platform tab) is the |
| 170 | * fallback for every docs page that no provider/reference/blog prefix claims |
| 171 | * (what-is-alchemy, getting-started, concepts, guides). |
| 172 | */ |
| 173 | export function activeTab(pathname: string): DocsTab { |
| 174 | const normalized = pathname.replace(/\/$/, "") || "/"; |
| 175 | for (const tab of DOCS_TABS) { |
| 176 | if (tab.prefixes.some((p) => matches(normalized, p))) return tab; |
| 177 | } |
| 178 | return DOCS_TABS[0]; |
| 179 | } |