1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-06-25 18:56:25 +02:00
blog/src/pages/[...slug].astro
Matthias Kretschmann 3b25ae2282
Location fetching (#843)
* location component

* fetching with @nanostores/query

* layouts reorg

* typescript plugins cleanup

* location component unit test cases

* fetch only when visible
2023-10-04 14:45:54 +01:00

34 lines
803 B
Plaintext

---
import LayoutPost from '@layouts/Post/index.astro'
import { getAllPosts } from '@lib/astro'
import type { InferGetStaticPropsType } from 'astro'
export async function getStaticPaths() {
const allPosts = await getAllPosts()
return allPosts.map((entry) => {
if (!entry?.slug) {
throw new Error('Missing `slug` field in entry', entry)
}
return {
params: { slug: entry.slug },
props: { entry }
}
})
}
type Props = InferGetStaticPropsType<typeof getStaticPaths>
const { entry } = Astro.props
const { Content, remarkPluginFrontmatter } = await entry.render()
---
<LayoutPost
{...entry}
lead={remarkPluginFrontmatter.lead}
leadRaw={remarkPluginFrontmatter.leadRaw}
tableOfContents={remarkPluginFrontmatter.tableOfContents}
>
<Content />
</LayoutPost>