-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-collections.ts
More file actions
40 lines (36 loc) · 986 Bytes
/
content-collections.ts
File metadata and controls
40 lines (36 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { defineCollection, defineConfig } from "@content-collections/core";
import { z } from "zod";
import { createHtml } from "~/utils/createHtml";
const postSchema = z.object({
title: z.string(),
summary: z.string(),
date: z.string().optional(),
tags: z.array(z.string()).optional(),
draft: z.boolean().optional(),
});
const posts = defineCollection({
name: "posts",
directory: "content",
include: ["**/*.md"],
schema: postSchema,
transform: async (doc, { skip, collection, cache }) => {
const html = await cache(doc.content, async (content) => {
return await createHtml(content);
});
const docs = await collection.documents();
const prev = docs.find((d) => d._meta.path === doc._meta.prev);
const next = docs.find((d) => d._meta.path === doc._meta.next);
if (doc.draft) {
return skip("Draft post");
}
return {
...doc,
html,
next: next || null,
prev: prev || null,
};
},
});
export default defineConfig({
collections: [posts],
});