feat: custom pages support

This commit is contained in:
grassblock 2025-05-04 11:42:46 +08:00
parent 7e5f8ce06f
commit 9411ec22c1
3 changed files with 33 additions and 0 deletions

View file

@ -0,0 +1,7 @@
import { z } from 'astro:content';
export const pages = z.object({
title: z.string(),
description: z.string(),
heroImage: z.string().optional()
});

View file

@ -0,0 +1,5 @@
---
title: 'Test Page'
description: 'This is a test page'
---
testestestest

21
src/pages/[...slug].astro Normal file
View file

@ -0,0 +1,21 @@
---
import Layout from '../layouts/Layout.astro';
import { getCollection } from "astro:content";
export async function getStaticPaths() {
const pageEntries = await getCollection('pages');
return pageEntries.map(entry => ({
params: { slug: entry.slug }, props: { entry },
}));
}
const { entry } = Astro.props;
const { Content } = await entry.render();
---
<Layout title={`${entry.data.title} | Terminal Blog`} path={`/var/log/${entry.slug}`}>
<h1 class="post-title">{entry.data.title}</h1>
<div class="post-content">
<Content/>
</div>
</Layout>