48 lines
1.2 KiB
TypeScript
Executable File
48 lines
1.2 KiB
TypeScript
Executable File
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],
|
|
});
|