Add blog index page
This commit is contained in:
parent
0b8b50cf12
commit
be88d18dcc
1 changed files with 20 additions and 0 deletions
20
apps/blog/src/pages/index.astro
Normal file
20
apps/blog/src/pages/index.astro
Normal 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>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue