Skip to content

Commit 2521483

Browse files
committed
refactor: use content layer api
1 parent 1e9204e commit 2521483

8 files changed

Lines changed: 20 additions & 11 deletions

File tree

src/components/BlogPost.astro

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
22
import type { CollectionEntry } from "astro:content";
33
import { formatDate } from "../utils";
4+
import { render } from "astro:content";
45
56
interface Props {
67
post: CollectionEntry<"blog">;
78
}
89
const { post } = Astro.props;
9-
const { remarkPluginFrontmatter } = await post.render();
10+
const { remarkPluginFrontmatter } = await render(post);
1011
---
1112

1213
<div>
@@ -21,7 +22,7 @@ const { remarkPluginFrontmatter } = await post.render();
2122
{remarkPluginFrontmatter.readingTime}
2223
</h1>
2324
<div
24-
class="prose my-8 max-w-none text-gray-600 dark:prose-invert dark:text-gray-400"
25+
class="prose dark:prose-invert my-8 max-w-none text-gray-600 dark:text-gray-400"
2526
>
2627
<slot />
2728
</div>
@@ -36,7 +37,7 @@ const { remarkPluginFrontmatter } = await post.render();
3637
</ul>
3738
<hr />
3839
<div
39-
class="prose my-8 max-w-none text-gray-600 dark:prose-invert dark:text-gray-400"
40+
class="prose dark:prose-invert my-8 max-w-none text-gray-600 dark:text-gray-400"
4041
>
4142
If you have any questions or comments, or you would like to point out any
4243
errors in any of the blog posts, please reach out to me at <a

src/components/BlogPostCard.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { post } = Astro.props;
1111
<div
1212
class="my-2 flex items-center justify-between text-gray-600 dark:text-gray-400"
1313
>
14-
<a class="hover:underline" href={`/blog/${post.slug}`}>
14+
<a class="hover:underline" href={`/blog/${post.id}`}>
1515
{post.data.title}
1616
</a>
1717
{formatDate(post.data.pubDate)}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { glob } from "astro/loaders";
12
import { defineCollection, z } from "astro:content";
23

34
const blogCollection = defineCollection({
4-
type: "content",
5+
loader: glob({ pattern: "**/[^_]*.{md,mdx}", base: "./src/content/blog" }),
56
schema: z.object({
67
title: z.string().min(1),
78
description: z.string().min(1),
@@ -12,7 +13,10 @@ const blogCollection = defineCollection({
1213
});
1314

1415
const announcementCollection = defineCollection({
15-
type: "content",
16+
loader: glob({
17+
pattern: "**/[^_]*.{md,mdx}",
18+
base: "./src/content/announcements",
19+
}),
1620
schema: z.object({
1721
title: z.string().min(1),
1822
description: z.string().min(1),

src/content/announcements/internships.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: "Internships and entry level positions"
33
description: "Seeking challenging internships and entry-level positions to apply and enhance my coding skills"
44
show: false
5+
slug: internships
56
---
67

78
Hi! My name is Milan, I'm a motivated and ambitious second-year CS student with a strong desire to gain practical experience in the field. Seeking challenging internships and entry-level positions to apply and enhance my coding skills, contribute to real-world projects, and learn from industry professionals. Committed to delivering high-quality work, collaborating effectively in team environments, and continuously expanding my knowledge. If you think I'd be a good fit in your team, contact me at milanherke@protonmail.com!

src/content/blog/introduction-to-big-o.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pubDate: 2023-07-04
44
description: "What do we mean by efficient algorithms? How does the runtime of an algorithm grow as its input size grows?"
55
tags: ["big-o", "complexity-analysis"]
66
draft: false
7+
slug: a-brief-introduction-to-big-o
78
---
89

910
# Table Of Contents

src/pages/announcement/[...slug].astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
---
22
import { getCollection } from "astro:content";
33
import AnnouncementLayout from "../../layouts/AnnouncementLayout.astro";
4+
import { render } from "astro:content";
45
56
export async function getStaticPaths() {
67
const announcements = await getCollection("announcements");
78
return announcements.map((entry) => ({
8-
params: { slug: entry.slug },
9+
params: { slug: entry.id },
910
props: { entry },
1011
}));
1112
}
1213
1314
const { entry } = Astro.props;
14-
const { Content } = await entry.render();
15+
const { Content } = await render(entry);
1516
---
1617

1718
<AnnouncementLayout announcement={entry}>

src/pages/blog/[...slug].astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
---
22
import { getCollection } from "astro:content";
33
import PostLayout from "../../layouts/PostLayout.astro";
4+
import { render } from "astro:content";
45
56
export async function getStaticPaths() {
67
const blogEntries = await getCollection("blog");
78
return blogEntries.map((entry) => ({
8-
params: { slug: entry.slug },
9+
params: { slug: entry.id },
910
props: { entry },
1011
}));
1112
}
1213
1314
const { entry } = Astro.props;
14-
const { Content } = await entry.render();
15+
const { Content } = await render(entry);
1516
---
1617

1718
<PostLayout post={entry}>

src/pages/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const announcements = await getCollection(
2929
announcements.map((announcement) => (
3030
<Popup
3131
text={announcement.data.description}
32-
href={`/announcement/${announcement.slug}`}
32+
href={`/announcement/${announcement.id}`}
3333
/>
3434
))
3535
}

0 commit comments

Comments
 (0)