Add blog index page

This commit is contained in:
Lewis Wynne 2026-01-23 00:11:01 +00:00
parent 0b8b50cf12
commit be88d18dcc

View file

@ -0,0 +1,20 @@
---
import { getCollection } from 'astro:content';
const posts = await getCollection('posts');
const sorted = posts.sort((a, b) => b.data.date.getTime() - a.data.date.getTime());
function formatDate(date: Date): string {
const d = String(date.getDate()).padStart(2, '0');
const m = String(date.getMonth() + 1).padStart(2, '0');
const y = String(date.getFullYear()).slice(-2);
return `${d}/${m}/${y}`;
}
---
<!DOCTYPE html>
<html>
<head><title>Blog</title></head>
<body>
<pre>{sorted.map(post => `<a href="/${post.id}">${formatDate(post.data.date)}</a> ${post.data.title}`).join('\n')}</pre>
</body>
</html>