Astro · Routing and content
Query a collection
Fetch the entries of a collection, filtered and sorted.
---
import { getCollection } from "astro:content";
const posts = (await getCollection("blog", ({ data }) => !data.draft))
.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());
---
<ul>
{posts.map((post) => <li><a href={`/blog/${post.id}`}>{post.data.title}</a></li>)}
</ul>