+ schema: () =>
baseSchema.extend({
- description: z.string(),
- coverImage: z
- .object({
- alt: z.string(),
- src: image(),
- })
- .optional(),
+ description: z.string().optional().nullable(),
draft: z.boolean().default(false),
- ogImage: z.string().optional(),
+ banner: z.string().optional(),
tags: z.array(z.string()).default([]).transform(removeDupsAndLowerCase),
- publishDate: z
- .string()
- .or(z.date())
- .transform((val) => new Date(val)),
- updatedDate: z
- .string()
- .optional()
- .transform((str) => (str ? new Date(str) : undefined)),
+ categories: z.array(z.string()).default([]).transform(removeDupsAndLowerCase),
+ date: z.union([z.string(), z.date()]).transform((val) => new Date(val)),
+ date_modified: z.date().optional(),
}),
});
const note = defineCollection({
loader: glob({ base: "./src/content/note", pattern: "**/*.{md,mdx}" }),
schema: baseSchema.extend({
- description: z.string().optional(),
- publishDate: z
- .string()
- .datetime({ offset: true }) // Ensures ISO 8601 format with offsets allowed (e.g. "2024-01-01T00:00:00Z" and "2024-01-01T00:00:00+02:00")
- .transform((val) => new Date(val)),
+ description: z.string().optional().nullable(),
+ date: z.union([z.string(), z.date()]).transform((val) => new Date(val)),
}),
});
+
export const collections = { post, note };
diff --git a/src/data/post.ts b/src/data/post.ts
index 26ed6ff..ec81eba 100644
--- a/src/data/post.ts
+++ b/src/data/post.ts
@@ -12,7 +12,7 @@ export async function getAllPosts(): Promise[]> {
*/
export function groupPostsByYear(posts: CollectionEntry<"post">[]) {
return posts.reduce[]>>((acc, post) => {
- const year = post.data.publishDate.getFullYear();
+ const year = post.data.date.getFullYear();
if (!acc[year]) {
acc[year] = [];
}
diff --git a/src/layouts/BlogPost.astro b/src/layouts/BlogPost.astro
index 888e7a2..3998bee 100644
--- a/src/layouts/BlogPost.astro
+++ b/src/layouts/BlogPost.astro
@@ -12,7 +12,13 @@ interface Props {
}
const { post } = Astro.props;
-const { ogImage, title, description, updatedDate, publishDate } = post.data;
+const {
+ banner: ogImage,
+ title,
+ description,
+ date_modified: updatedDate,
+ date: publishDate,
+} = post.data;
const socialImage = ogImage ?? `/og-image/${post.id}.png`;
const articleDate = updatedDate?.toISOString() ?? publishDate.toISOString();
const { headings, remarkPluginFrontmatter } = await render(post);
diff --git a/src/pages/notes/[...slug].astro b/src/pages/notes/[...slug].astro
index 2ce847d..21590ef 100644
--- a/src/pages/notes/[...slug].astro
+++ b/src/pages/notes/[...slug].astro
@@ -20,8 +20,7 @@ const { note } = Astro.props;
const meta = {
description:
- note.data.description ||
- `Read about my note posted on: ${note.data.publishDate.toLocaleDateString()}`,
+ note.data.description || `Read about my note posted on: ${note.data.date.toLocaleDateString()}`,
title: note.data.title,
};
---
diff --git a/src/pages/notes/rss.xml.ts b/src/pages/notes/rss.xml.ts
index 0f1f945..9a20315 100644
--- a/src/pages/notes/rss.xml.ts
+++ b/src/pages/notes/rss.xml.ts
@@ -11,7 +11,7 @@ export const GET = async () => {
site: import.meta.env.SITE,
items: notes.map((note) => ({
title: note.data.title,
- pubDate: note.data.publishDate,
+ pubDate: note.data.date,
link: `notes/${note.id}/`,
})),
});
diff --git a/src/pages/og-image/[...slug].png.ts b/src/pages/og-image/[...slug].png.ts
index a4982d8..6c3b5e6 100644
--- a/src/pages/og-image/[...slug].png.ts
+++ b/src/pages/og-image/[...slug].png.ts
@@ -1,5 +1,4 @@
-import RobotoMonoBold from "@/assets/roboto-mono-700.ttf";
-import RobotoMono from "@/assets/roboto-mono-regular.ttf";
+import ZCOOLXiaoWei from "@/assets/ZCOOLXiaoWei-Regular.ttf";
import { getAllPosts } from "@/data/post";
import { siteConfig } from "@/site.config";
import { getFormattedDate } from "@/utils/date";
@@ -12,17 +11,11 @@ const ogOptions: SatoriOptions = {
// debug: true,
fonts: [
{
- data: Buffer.from(RobotoMono),
- name: "Roboto Mono",
+ data: Buffer.from(ZCOOLXiaoWei),
+ name: "ZCOOLXiaoWei",
style: "normal",
weight: 400,
- },
- {
- data: Buffer.from(RobotoMonoBold),
- name: "Roboto Mono",
- style: "normal",
- weight: 700,
- },
+ }
],
height: 630,
width: 1200,
@@ -79,11 +72,11 @@ export async function GET(context: APIContext) {
export async function getStaticPaths() {
const posts = await getAllPosts();
return posts
- .filter(({ data }) => !data.ogImage)
+ .filter(({ data }) => !data.banner)
.map((post) => ({
params: { slug: post.id },
props: {
- pubDate: post.data.updatedDate ?? post.data.publishDate,
+ pubDate: post.data.date ?? post.data.date_modified ,
title: post.data.title,
},
}));
diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts
index 1c305af..36d0ca6 100644
--- a/src/pages/rss.xml.ts
+++ b/src/pages/rss.xml.ts
@@ -11,8 +11,8 @@ export const GET = async () => {
site: import.meta.env.SITE,
items: posts.map((post) => ({
title: post.data.title,
- description: post.data.description,
- pubDate: post.data.publishDate,
+ description: post.data.description ?? "",
+ pubDate: post.data.date,
link: `posts/${post.id}/`,
})),
});
diff --git a/src/utils/date.ts b/src/utils/date.ts
index fb943a5..e757459 100644
--- a/src/utils/date.ts
+++ b/src/utils/date.ts
@@ -19,5 +19,5 @@ export function collectionDateSort(
a: CollectionEntry<"post" | "note">,
b: CollectionEntry<"post" | "note">,
) {
- return b.data.publishDate.getTime() - a.data.publishDate.getTime();
+ return b.data.date.getTime() - a.data.date.getTime();
}