- + - {frontmatter.title} - {frontmatter.pubDate.slice(0, 10)} + {title} + + + @@ -46,7 +42,7 @@ const { frontmatter } = Astro.props; padding-bottom: 0.5rem; } - time { + .date { color: var(--text-color-light); } diff --git a/src/pages/blog.astro b/src/pages/blog.astro deleted file mode 100644 index 0572949..0000000 --- a/src/pages/blog.astro +++ /dev/null @@ -1,27 +0,0 @@ ---- -import type { BlogPost } from "../types/BlogPost.ts"; -import PostCard from "@components/PostCard.astro"; -import Layout from "@layouts/BaseLayout.astro"; -import backgroundImage from "@assets/blog-bg.jpg"; - -const posts = Object.values( - import.meta.glob("../pages/posts/*.md", { eager: true }), -); ---- - - - - {posts.map((post) => )} - - - - diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro new file mode 100644 index 0000000..b61d002 --- /dev/null +++ b/src/pages/blog/[...slug].astro @@ -0,0 +1,25 @@ +--- +import { type CollectionEntry, getCollection } from "astro:content"; +import PostLayout from "../../layouts/PostLayout.astro"; +import { render } from "astro:content"; + +type Props = CollectionEntry<"Blog">; +type Post = CollectionEntry<"Blog">; + +export async function getStaticPaths() { + const posts = await getCollection("blog"); + + return posts.map((post: Post) => ({ + params: { slug: post.id }, + props: post, + })); +} + +const post = Astro.props; + +const { Content } = await render(post); +--- + + + + diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro new file mode 100644 index 0000000..414c113 --- /dev/null +++ b/src/pages/blog/index.astro @@ -0,0 +1,66 @@ +--- +import Layout from "@layouts/BaseLayout.astro"; +import backgroundImage from "@assets/blog-bg.jpg"; +import { type CollectionEntry, getCollection } from "astro:content"; +import FormattedDate from "@components/FormattedDate.astro"; + +type PostEntry = CollectionEntry<"Blog">; + +const posts: PostEntry[] = await getCollection("blog"); + +const sortedPosts = posts.sort( + (a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf(), +); +--- + + + + { + sortedPosts.map((post) => ( + + + + + + + {post.data.title} + + + + )) + } + + + + diff --git a/src/types/BlogPost.ts b/src/types/BlogPost.ts deleted file mode 100644 index 15d3c34..0000000 --- a/src/types/BlogPost.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { MarkdownInstance } from "astro"; - -export interface Image { - url: string; - alt?: string; -} - -export interface Frontmatter { - title: string; - pubDate: string; - image?: Image; -} - -export type BlogPost = MarkdownInstance;