This commit is contained in:
47
content-collections.ts
Executable file
47
content-collections.ts
Executable file
@@ -0,0 +1,47 @@
|
||||
import { defineCollection, defineConfig } from "@content-collections/core";
|
||||
import { z } from "zod";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import remarkParse from 'remark-parse'
|
||||
import rehypePrettyCode from "rehype-pretty-code";
|
||||
import remarkRehype from 'remark-rehype'
|
||||
import rehypeStringify from 'rehype-stringify'
|
||||
import { unified } from 'unified'
|
||||
|
||||
const parser = unified()
|
||||
.use(remarkParse)
|
||||
.use(remarkGfm)
|
||||
.use(remarkRehype)
|
||||
.use(rehypeStringify)
|
||||
.use(rehypePrettyCode, {
|
||||
theme: "catppuccin-macchiato"
|
||||
});
|
||||
|
||||
const posts = defineCollection({
|
||||
name: "posts",
|
||||
directory: "src/content/blog",
|
||||
include: "**/*.md",
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
description: z.string(),
|
||||
dateCreated: z.coerce.date(),
|
||||
dateUpdated: z.coerce.date().optional(),
|
||||
draft: z.boolean().optional(),
|
||||
html: z.string().optional(),
|
||||
slug: z.string().optional()
|
||||
}),
|
||||
transform: async (doc) => {
|
||||
if (doc.content) {
|
||||
const processed = await parser.process(doc.content);
|
||||
return {
|
||||
...doc,
|
||||
html: String(processed),
|
||||
slug: doc._meta.fileName.slice(0, -3),
|
||||
};
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
});
|
||||
|
||||
export default defineConfig({
|
||||
collections: [posts],
|
||||
});
|
||||
Reference in New Issue
Block a user