-
Notifications
You must be signed in to change notification settings - Fork 303
Expand file tree
/
Copy pathcontent-collections.ts
More file actions
128 lines (120 loc) · 3.18 KB
/
content-collections.ts
File metadata and controls
128 lines (120 loc) · 3.18 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { defineCollection, defineConfig } from "@content-collections/core";
import { compileMDX } from "@content-collections/mdx";
import { z } from "zod";
import readingTime from "reading-time";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypePrettyCode from "rehype-pretty-code";
import rehypeSlug from "rehype-slug";
import { getAuthorByKey } from "./src/data/authors";
const blog = defineCollection({
name: "blog",
directory: "content/blog",
include: "**/*.mdx",
schema: z.object({
title: z.string(),
description: z.string(),
publishedAt: z.string(),
summary: z.string().optional(),
image: z.string().optional(),
author: z.string().optional(), // Simple author key (e.g., "christerhagen")
tags: z.array(z.string()).optional(),
related: z.array(z.string()).optional(),
}),
transform: async (document, context) => {
const mdx = await compileMDX(context, document, {
rehypePlugins: [
rehypeSlug,
[
rehypePrettyCode,
{
theme: {
dark: "github-dark",
light: "github-light",
},
keepBackground: false,
},
],
[
rehypeAutolinkHeadings,
{
properties: {
className: ["subheading-anchor"],
ariaLabel: "Link to section",
},
},
],
],
});
const readingTimeStats = readingTime(document.content);
// Resolve author information
let authorData = null;
if (document.author) {
const author = getAuthorByKey(document.author);
if (author) {
authorData = {
...author,
displayTitle: author.defaultTitle,
};
}
}
return {
...document,
mdx,
readingTime: readingTimeStats.text,
wordCount: readingTimeStats.words,
slug: document._meta.path,
authorData, // Resolved author information
};
},
});
const help = defineCollection({
name: "help",
directory: "content/help",
include: "**/*.mdx",
schema: z.object({
title: z.string(),
description: z.string(),
publishedAt: z.string(),
updatedAt: z.string().optional(),
summary: z.string().optional(),
tags: z.array(z.string()).optional(),
related: z.array(z.string()).optional(),
}),
transform: async (document, context) => {
const mdx = await compileMDX(context, document, {
rehypePlugins: [
rehypeSlug,
[
rehypePrettyCode,
{
theme: {
dark: "github-dark",
light: "github-light",
},
keepBackground: false,
},
],
[
rehypeAutolinkHeadings,
{
properties: {
className: ["subheading-anchor"],
ariaLabel: "Link to section",
},
},
],
],
});
const readingTimeStats = readingTime(document.content);
return {
...document,
mdx,
readingTime: readingTimeStats.text,
wordCount: readingTimeStats.words,
slug: document._meta.path,
};
},
});
export default defineConfig({
collections: [blog, help],
});