---
/**
* `` — a provider hub's map of its docs, one card per sidebar
* section, drawn from the sidebar itself so it never drifts from it.
*
* Place it on a hub page (`/index.mdx`). It finds the sidebar group
* that holds the current page and lists that group's sections, skipping the
* tutorial (the hub links it in "Where to start") and the API reference.
*/
import type { StarlightRouteData } from "@astrojs/starlight/route-data";
import { sidebarGroupIcon } from "../docs-icons";
type Entry = StarlightRouteData["sidebar"][number];
type Group = Extract;
type Link = Extract;
const SKIP = new Set(["Tutorial", "API Reference", "Resources"]);
const { sidebar } = Astro.locals.starlightRoute;
const holdsCurrent = (entries: Entry[]): boolean =>
entries.some((e) => (e.type === "link" ? e.isCurrent : holdsCurrent(e.entries)));
const links = (entries: Entry[]): Link[] =>
entries.flatMap((e) => (e.type === "link" ? [e] : links(e.entries)));
// The hub's own group: the innermost group whose direct links include this page.
const findHub = (entries: Entry[]): Entry[] | undefined => {
for (const e of entries) {
if (e.type !== "group" || !holdsCurrent(e.entries)) continue;
return findHub(e.entries) ?? e.entries;
}
return entries.some((e) => e.type === "link" && e.isCurrent) ? entries : undefined;
};
const sections = (findHub(sidebar) ?? []).filter(
(e): e is Group => e.type === "group" && !SKIP.has(e.label),
);
---