Created
July 11, 2023 19:39
-
-
Save jhilker98/f09fe6519df5fa7fd51f23637be9f43e to your computer and use it in GitHub Desktop.
broken blog layout setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
import { getCollection, CollectionEntry } from "astro:content"; | |
import Layout from "../../layouts/Layout.astro"; | |
export async function getStaticPaths() { | |
const posts = await getCollection('blog'); | |
return posts.map((post) => { | |
const year = post.data.date.getFullYear(); | |
post.slug = `/${year}/${post.slug}`; | |
return { | |
params: { | |
slug: post.slug, | |
}, | |
props: { | |
post, | |
}, | |
}; | |
}); | |
} | |
interface Props { | |
post: CollectionEntry<'blog'>; | |
} | |
const { post } = Astro.props; | |
const { Content } = await post.render(); | |
--- | |
<Layout title={post.data.title}> | |
<header> | |
<h1>{post.data.title}</h1> | |
<a href={post.slug}>Read More</a> | |
</header> | |
<Content /> | |
</Layout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment