From a2f6500da4353caeb48854a3453202b9dcf75533 Mon Sep 17 00:00:00 2001 From: stefkn Date: Wed, 12 Jun 2024 17:19:57 +0100 Subject: [PATCH] add the ability to mark a post as featured in the frontmatter --- src/content/config.ts | 3 ++- .../posts/lessons-from-flask-in-production.md | 1 + src/pages/posts.astro | 20 +++++++++---------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/content/config.ts b/src/content/config.ts index f6a9199..44e330c 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -12,7 +12,8 @@ const postsCollection = defineCollection({ message: "Cover image must be at least 1080 pixels wide!", }), imageAlt: z.string(), - tags: z.array(z.string()) + tags: z.array(z.string()), + featured: z.boolean() }) }); const journalsCollection = defineCollection({ diff --git a/src/content/posts/lessons-from-flask-in-production.md b/src/content/posts/lessons-from-flask-in-production.md index 47e4514..a2dbfd5 100644 --- a/src/content/posts/lessons-from-flask-in-production.md +++ b/src/content/posts/lessons-from-flask-in-production.md @@ -6,6 +6,7 @@ author: 'Stefan Nowak' image: '../../assets/post_images/gradient_bg.jpg' imageAlt: 'photo by Sean Sinclair on Unsplash' tags: ["web", "python", "flask"] +featured: true --- diff --git a/src/pages/posts.astro b/src/pages/posts.astro index b158f47..9a74b7b 100644 --- a/src/pages/posts.astro +++ b/src/pages/posts.astro @@ -3,7 +3,7 @@ import Layout from "../layouts/Layout.astro"; import { Image } from "astro:assets"; import { getCollection } from "astro:content"; const allPosts = await getCollection("posts"); -const firstPost = allPosts[0]; +const featuredPost = allPosts.find((post) => post.data.featured); const pageTitle = "Blog posts"; --- @@ -13,25 +13,25 @@ const pageTitle = "Blog posts";
{ - firstPost && ( + featuredPost && (
- - {firstPost.data.title} + + {featuredPost.data.title} -

{firstPost.data.description}

+

{featuredPost.data.description}

- + {firstPost.data.imageAlt} @@ -42,7 +42,7 @@ const pageTitle = "Blog posts"; } { - allPosts && allPosts.slice(1).map((post) => ( + allPosts && allPosts.filter((post) => {return post !== featuredPost}).map((post) => (
{post.data.title}