blob: caa75df966e038696d11e7481cc7f48658c9e2e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
---
import { getCollection } from 'astro:content';
import { Card, CardContent, CardDescription, CardHeader } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import BlogPostCard from "@/components/BlogPostCard.astro";
// Fetch all blog posts from the content collection
const posts = await getCollection('blog');
// Sort posts by date (newest first)
const sortedPosts = posts.sort((a, b) =>
new Date(b.data.publishDate).getTime() - new Date(a.data.publishDate).getTime()
);
const dateFormatter = new Intl.DateTimeFormat('en-GB', {
day: '2-digit',
month: 'long',
year: 'numeric',
});
---
<div class="w-full max-w-2xl mx-auto p-4">
<h1 class="text-3xl font-bold mb-8">Blog Posts</h1>
<div class="space-y-4 max-h-96 overflow-y-auto">
{sortedPosts.map((post) => (
<a href={`/posts/${post.id}`} class="block hover:opacity-80 transition-opacity" data-astro-prefetch>
<BlogPostCard
title={post.data.title}
slug={post.id}
description={post.data.description}
author={post.data.author}
publishDate={post.data.publishDate}
/>
</a>
))}
</div>
</div>
|