Files
ghall.space/src/pages/index.astro
T
2022-12-07 22:12:24 -05:00

27 lines
793 B
Plaintext

---
import { format } from 'date-fns';
import { Markup } from 'astro-remote';
import Layout from '../layouts/Layout.astro';
const response = await fetch(`https://api.cosmicjs.com/v2/buckets/${import.meta.env.BUCKET_SLUG}/objects?pretty=true&query=%7B%22type%22%3A%22blog-posts%22%7D&read_key=${import.meta.env.BUCKET_READ_KEY}&limit=10`)
const posts = await response.json();
---
<Layout title="Blog">
<div>
{posts.objects.map(post => (
<article>
<div style={{display: 'flex', justifyContent: 'space-between'}}>
<h4>{post.title}</h4>
<h5>{`🗓️ ${format(new Date(post.published_at), 'MMM do, y')}`}</h5>
</div>
<Markup content={`<p>${post.content.split('</p>')[0]}`} />
<a href={`/posts/${post.slug}`}>Read More</a>
</article>
))}
</div>
</Layout>