Skip to content

Commit

Permalink
Convert blog posts to content collections
Browse files Browse the repository at this point in the history
It *probably* works but the site doesn't build yet
  • Loading branch information
Southpaw1496 committed Dec 3, 2023
1 parent df0c20d commit aaeae5f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
13 changes: 8 additions & 5 deletions src/components/atoms/PostInfo.astro
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
import { localizeList } from "@util/Util";
import { t } from "i18next";
const { post } = Astro.props;
const { authors = [], date } = post.frontmatter;
interface Props {
authors: string[]
date: Date
}
const { authors } = Astro.props;
const { date } = Astro.props;
---

<div class="media">
<div class="media-content">
{authors.length > 0 && <p class="title is-5">{localizeList(authors)}</p>}
{authors.length > 0 && <p class="title is-5">{authors.join(", ")}</p>}

{
date && (
<p class="subtitle is-6">{t("post-date", { date: new Date(date) })}</p>
<p class="subtitle is-6">{date.toLocaleDateString()}</p>
)
}
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ const page = defineCollection({
title: z.string(),
description: z.string()
})
})
})

export const collections = {
"blog": blogPost
}
34 changes: 34 additions & 0 deletions src/pages/en/blog/[...slug].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
import PostInfo from "@atoms/PostInfo.astro";
import Default from "@layouts/Default.astro";
import { getCollection, type CollectionEntry } from "astro:content";
import type { BaseProps } from "@layouts/Base.astro";
import Post from "@layouts/Post.astro";
interface Props {
blogPost: CollectionEntry<"blog">
}
export async function getStaticPaths() {
const blogPosts = await getCollection("blog");
return blogPosts.map((blogPost) => ({
params: { slug: blogPost.slug },
props: { blogPost },
}));
}
const { blogPost } = Astro.props;
const { Content } = await blogPost.render();
const contentProps: BaseProps = {
title: blogPost.data.title,
date: blogPost.data.date.toUTCString()
}
---

<Default content={contentProps}>
<div class="blog-post">
<h1>{blogPost.data.title}</h1>
<PostInfo authors={blogPost.data.authors} date={blogPost.data.date} />

<Content />
</div>
</Default>
17 changes: 0 additions & 17 deletions src/pages/en/blog/[page].astro

This file was deleted.

0 comments on commit aaeae5f

Please sign in to comment.