From 4df20293408cf98a6897fbafdd8fe37d2924fbd6 Mon Sep 17 00:00:00 2001 From: Dilson's Pickles Date: Tue, 12 Sep 2023 16:52:42 +1000 Subject: [PATCH] Implement new blog with placeholder blog card --- src/components/card/NEWBlogPostCard.astro | 23 ++++++++ src/components/homepage/BlogPosts.astro | 66 ++++++++++------------- src/pages/blog.astro | 48 +++++++---------- 3 files changed, 72 insertions(+), 65 deletions(-) create mode 100644 src/components/card/NEWBlogPostCard.astro diff --git a/src/components/card/NEWBlogPostCard.astro b/src/components/card/NEWBlogPostCard.astro new file mode 100644 index 0000000..ce9d371 --- /dev/null +++ b/src/components/card/NEWBlogPostCard.astro @@ -0,0 +1,23 @@ +--- +export interface Props { + title: string; + description: string; + author: string; + href: string; + publishDate: string; + cover: ImageMetadata; + coverAlt: string; +} +const { title, author, href, publishDate, description, cover, coverAlt} = Astro.props; +--- + +
+ {coverAlt} +
+

{title}

{author}

{publishDate} +

+ {description.slice(0, 200)}... +

+ Read more +
+
diff --git a/src/components/homepage/BlogPosts.astro b/src/components/homepage/BlogPosts.astro index 07cbeb1..1cf1de8 100644 --- a/src/components/homepage/BlogPosts.astro +++ b/src/components/homepage/BlogPosts.astro @@ -1,43 +1,35 @@ --- -import BlogListingCard from "../card/BlogListingCard.astro"; +import NEWBlogPostCard from "../../components/card/NEWBlogPostCard.astro"; -interface Frontmatter { - title: string; - slug: string; - thumbnail: string; - date: string; - author: string; - description: string; -} - -const posts = await Astro.glob("../../pages/posts/*.md"); +import { getCollection } from "astro:content"; +const publishedBlogPosts = await getCollection("blog", ({ data }) => { + return data.draft !== true; +}); --- -
-
-

Latest from the blog

-
- { - posts - .slice(0, 3) - .sort( - (a, b) => /* This is reversed because we want the latest post on top */ - Date.parse(b.frontmatter.date) - Date.parse(a.frontmatter.date) - ) - .map((post) => ( - - )) - } -
+
+
+

Blog posts

+
+ +
+ { + publishedBlogPosts.map((post) => { + console.log("hello") + return ( + + ); + }) + }
- - diff --git a/src/pages/blog.astro b/src/pages/blog.astro index 3f5fcab..a637a3d 100644 --- a/src/pages/blog.astro +++ b/src/pages/blog.astro @@ -1,42 +1,34 @@ --- -import BlogPostCard from "../components/card/BlogPostCard.astro"; +import NEWBlogPostCard from "../components/card/NEWBlogPostCard.astro"; import BaseLayout from "../layouts/BaseLayout.astro"; -interface Frontmatter { - title: string; - slug: string; - thumbnail: string; - date: string; - description: string; - author: string; -} - -const posts = await Astro.glob("./posts/*.md"); +import { getCollection } from "astro:content"; +const publishedBlogPosts = await getCollection("blog", ({ data }) => { + return data.draft !== true; +}); --- -
+

Blog posts

-
+
{ - posts - .sort( - (a, b) => /* This is reversed because we want the latest post on top */ - Date.parse(b.frontmatter.date) - Date.parse(a.frontmatter.date) - ) - .map((post) => ( - - )) + publishedBlogPosts.map((post) => ( + + )) }