refactor: use a content collection for blog posts
This commit is contained in:
parent
7b97ad3af2
commit
58061a8e59
177 changed files with 1248 additions and 18 deletions
|
@ -1,25 +1,25 @@
|
|||
---
|
||||
import ListingPage from "~/components/ListingPage.astro";
|
||||
import PageLayout from "~/layouts/PageLayout.astro";
|
||||
import { getSlugFromFile } from "~/utils.ts";
|
||||
import { getCollection } from 'astro:content';
|
||||
|
||||
const posts = await Astro.glob("../../posts/*.md");
|
||||
const posts = await getCollection('blog');
|
||||
|
||||
// TODO: show all posts when running locally.
|
||||
const filteredPosts = posts
|
||||
.filter((post) => !post.frontmatter.draft)
|
||||
.filter((post) => post.frontmatter.date);
|
||||
.filter((post) => !post.data.draft)
|
||||
.filter((post) => post.data.date);
|
||||
|
||||
const sortedPosts = filteredPosts
|
||||
.map((post) => {
|
||||
const slug = `/blog/${getSlugFromFile(post.file)}`;
|
||||
const slug = `/blog/${post.slug}`;
|
||||
|
||||
return { item: post, slug };
|
||||
})
|
||||
.sort(
|
||||
(a, b) =>
|
||||
new Date(b.item.frontmatter.date).valueOf() -
|
||||
new Date(a.item.frontmatter.date).valueOf()
|
||||
new Date(b.item.data.date).valueOf() -
|
||||
new Date(a.item.data.date).valueOf()
|
||||
);
|
||||
---
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue