init repository
This commit is contained in:
35
src/pages/[collection]/[...slug].astro
Normal file
35
src/pages/[collection]/[...slug].astro
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
import { getCollection, render } from "astro:content";
|
||||
import { collectionNames, isSiteCollection } from "../../config/content";
|
||||
|
||||
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 { Content } = await render(entry);
|
||||
---
|
||||
|
||||
<Content />
|
||||
Reference in New Issue
Block a user