Files
radie-help/src/pages/[collection]/[...slug].astro

61 lines
1.4 KiB
Plaintext

---
import { getCollection, render } from "astro:content";
import { collectionNames, isSiteCollection } from "../../config/content";
import Layout from "../../layouts/Layout.astro";
export async function getStaticPaths() {
const paths = [];
for (const collection of collectionNames) {
const entries = await getCollection(collection);
for (const entry of entries) {
paths.push({
params: {
collection,
slug: entry.id === "index" ? undefined : entry.id,
},
props: { collection, entry },
});
}
}
return paths;
}
const { collection } = Astro.params;
if (!collection || !isSiteCollection(collection)) {
throw new Error("Invalid collection");
}
const { entry } = Astro.props;
const entries = await getCollection(collection);
const collectionIndex = entries.find((item) => item.id === "index");
const entryUrl =
entry.id === "index" ? `/${collection}` : `/${collection}/${entry.id}`;
const breadcrumbs = [
{ label: "Help", href: "/" },
{
label: collectionIndex?.data.title ?? collection,
href: entry.id === "index" ? undefined : `/${collection}`,
},
];
if (entry.id !== "index") {
breadcrumbs.push({ label: entry.data.title, href: entryUrl });
}
const { Content } = await render(entry);
---
<Layout
title={entry.data.title}
description={entry.data.description}
breadcrumbs={breadcrumbs}
>
<div class="prose-radium">
<Content class="prose-radium" />
</div>
</Layout>