Files
radie-help/src/components/TOC.astro
2026-05-01 10:39:41 -05:00

50 lines
1.4 KiB
Plaintext

---
import { getCollection } from "astro:content";
import { collectionNames } from "../config/content";
const sections = await Promise.all(
collectionNames.map(async (name) => {
const entries = (await getCollection(name)).sort((a, b) =>
a.data.title.localeCompare(b.data.title),
);
const indexEntry = entries.find((entry) => entry.id === "index");
const articles = entries.filter((entry) => entry.id !== "index");
return {
name,
indexEntry,
articles,
};
}),
);
---
<ul class="prose-radium">
{
sections.map((section) => (
<li>
{section.indexEntry ? (
<a href={`/${section.name}`}>
{section.indexEntry.data.title}
</a>
) : (
section.name
)}
{section.articles.length > 0 && (
<ul>
{section.articles.map((entry) => (
<li>
<a href={`/${section.name}/${entry.id}`}>
{entry.data.title}
</a>
</li>
))}
</ul>
)}
</li>
))
}
</ul>