generated from manuelernestog/astrofy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update blog posts to support content collections from astro 2.0
- Loading branch information
Showing
10 changed files
with
83 additions
and
37 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
import { z, defineCollection } from "astro:content"; | ||
|
||
const blogSchema = z.object({ | ||
title: z.string(), | ||
description: z.string(), | ||
pubDate: z.coerce.date(), | ||
updatedDate : z.string().optional(), | ||
heroImage: z.string().optional(), | ||
}); | ||
const testSchema = z.object({ | ||
nome: z.string(), | ||
lista: z.array(z.string()), | ||
data: z.string().transform(str => new Date(str)), | ||
}); | ||
}); | ||
|
||
export type SchemaTest = z.infer<typeof testSchema>; | ||
export type BlogSchema = z.infer<typeof blogSchema>; | ||
|
||
const testCollection = defineCollection( { schema : testSchema } ) ; | ||
const blogCollection = defineCollection( { schema : blogSchema } ) ; | ||
|
||
export const collections = { | ||
'blog' : blogCollection, | ||
'test' : testCollection, | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
import { CollectionEntry, getCollection } from 'astro:content'; | ||
import { BlogSchema } from '../../content/config'; | ||
import PostLayout from '../../layouts/PostLayout.astro'; | ||
export async function getStaticPaths() { | ||
const postEntries = await getCollection('blog'); | ||
return postEntries.map(entry => ( { | ||
params: { slug: entry.slug }, props: { entry }, | ||
} )); | ||
} | ||
interface Props { | ||
entry: CollectionEntry<"blog">; | ||
} | ||
const { entry } = Astro.props; | ||
const post : BlogSchema = entry.data; | ||
const { Content } = await entry.render(); | ||
--- | ||
|
||
<PostLayout title={post.title} description={post.description} pubDate={post.pubDate} heroImage={post.heroImage} updatedDate={post.updatedDate}> | ||
<Content/> | ||
</PostLayout> |
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