Add TOC and Layout components; update pages

This commit is contained in:
mido
2026-04-15 11:23:10 -05:00
parent 57f672386a
commit 56ea450e7b
6 changed files with 101 additions and 43 deletions

49
src/components/TOC.astro Normal file
View File

@@ -0,0 +1,49 @@
---
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>
{
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>