diff --git a/src/content/config.ts b/src/content.config.ts
similarity index 78%
rename from src/content/config.ts
rename to src/content.config.ts
index 820b6de..82ba513 100644
--- a/src/content/config.ts
+++ b/src/content.config.ts
@@ -1,6 +1,9 @@
-import { z, defineCollection } from "astro:content";
+import { defineCollection } from "astro:content";
+import { glob } from "astro/loaders";
+import { z } from "astro/zod";
const projectsCollection = defineCollection({
+ loader: glob({ pattern: "**/[^_]*.{md,mdx}", base: "./src/content/projects" }),
schema: ({ image }) =>
z.object({
name: z.string(),
@@ -31,6 +34,7 @@ const projectsCollection = defineCollection({
});
const blogPostsCollection = defineCollection({
+ loader: glob({ pattern: "**/[^_]*.{md,mdx}", base: "./src/content/posts" }),
schema: z.object({
title: z.string(),
date: z.date(),
diff --git a/src/content/posts/hello_world.mdx b/src/content/posts/hello_world.mdx
index 898d917..4a18666 100644
--- a/src/content/posts/hello_world.mdx
+++ b/src/content/posts/hello_world.mdx
@@ -92,7 +92,7 @@ const blogEntries = await getCollection("posts");
{i === 0 &&
}
{p.data.date.toLocaleDateString("en-us", {
@@ -104,7 +104,7 @@ const blogEntries = await getCollection("posts");
- {p.data.summary} Read More
+ {p.data.summary} Read More
>
@@ -114,7 +114,7 @@ const blogEntries = await getCollection("posts");
```
Great! I'll probably fiddle with it in the future but it's a good start. Now we need to make a page for each post.
-To make my URLs look nice I'm going to create a subfolder within `blog` called `posts` and then place a `[...slug].astro` in there.
+To make my URLs look nice I'm going to create a subfolder within `blog` called `posts` and then place a `[...id].astro` in there.
This will allow me to use `getStaticPaths()` to define the paths for each post.
```astro
@@ -124,7 +124,7 @@ import { CollectionEntry, getCollection } from "astro:content";
export const getStaticPaths = async () => {
const posts = await getCollection("posts");
return posts.map((entry) => ({
- params: { slug: entry.slug },
+ params: { slug: entry.id },
props: { entry }
}));
};
@@ -171,7 +171,7 @@ Then we need to map those to HTML
{
headings.map((h) => (
- {h.text}
+ {h.text}
))
}
diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro
index 81c38c6..f28d354 100644
--- a/src/pages/blog/[...slug].astro
+++ b/src/pages/blog/[...slug].astro
@@ -1,17 +1,17 @@
---
import CowSay from "@components/blog/CowSay.astro";
import Layout from "@layouts/Layout.astro";
-import { type CollectionEntry, getCollection } from "astro:content";
+import { type CollectionEntry, getCollection, render } from "astro:content";
export const getStaticPaths = async () => {
const posts = await getCollection("posts");
return posts.map((entry) => ({
- params: { slug: entry.slug },
+ params: { slug: entry.id },
props: { entry }
}));
};
const { entry } = Astro.props as { entry: CollectionEntry<"posts"> };
-const { Content, headings } = await entry.render();
+const { Content, headings } = await render(entry);
---
diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro
index 40eea2b..97cee5c 100644
--- a/src/pages/blog/index.astro
+++ b/src/pages/blog/index.astro
@@ -20,11 +20,11 @@ const options: Intl.DateTimeFormatOptions = {
blogEntries.map((p) => (
{p.data.date.toLocaleDateString(undefined, options)}
- {p.data.summary} Read More
+ {p.data.summary} Read More
))
diff --git a/src/pages/feed.xml.ts b/src/pages/feed.xml.ts
index 909c0a6..3c84706 100644
--- a/src/pages/feed.xml.ts
+++ b/src/pages/feed.xml.ts
@@ -17,7 +17,7 @@ export async function GET(context: { site: string | URL }) {
title: post.data.title,
pubDate: post.data.date,
description: post.data.summary,
- link: `/blog/posts/${post.slug}`,
+ link: `/blog/posts/${post.id}`,
content: sanitizeHtml(parser.render(post.body), {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"])
})
diff --git a/src/pages/projects/[...slug].astro b/src/pages/projects/[...slug].astro
index a1d8469..2d10662 100644
--- a/src/pages/projects/[...slug].astro
+++ b/src/pages/projects/[...slug].astro
@@ -1,5 +1,5 @@
---
-import { type CollectionEntry, getCollection } from "astro:content";
+import { type CollectionEntry, getCollection, render } from "astro:content";
import { Image } from "astro:assets";
import Layout from "@layouts/Layout.astro";
import IconLink from "@components/IconLink.astro";
@@ -7,12 +7,12 @@ import { Icon } from "astro-icon/components";
export async function getStaticPaths() {
const renameEntries = await getCollection("projects");
return renameEntries.map((entry) => ({
- params: { slug: entry.slug },
+ params: { slug: entry.id },
props: { entry }
}));
}
const { entry } = Astro.props as { entry: CollectionEntry<"projects"> };
-const { Content } = await entry.render();
+const { Content } = await render(entry);
const firstOtherLink = entry.data.links?.other?.[0];
@@ -75,10 +75,7 @@ const og = {