-
Notifications
You must be signed in to change notification settings - Fork 1
/
contentlayer.config.ts
208 lines (201 loc) · 5.32 KB
/
contentlayer.config.ts
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import { podcastEpisodeImage } from "./src/lib/podcast";
import { createStandardSlug } from "./src/lib/helpers";
import { defineDocumentType, makeSource } from "contentlayer/source-files";
import {
ROUTE_PREFIX_BLOG,
ROUTE_PREFIX_PODCAST,
ROUTE_PREFIX_SNAPSHOT,
} from "./src/lib/const/general";
/**
* Podcast episode schema
*/
export const PodcastEpisode = defineDocumentType(() => ({
name: "PodcastEpisode",
filePathPattern: `podcast/episodes/**/*.md`,
fields: {
title: {
type: "string",
description: "The title of the episode",
required: true,
},
longTitle: {
type: "string",
description: "The longer title of the episode",
required: false,
},
date: {
type: "date",
description: "The public date of the episode",
required: true,
},
draft: {
type: "boolean",
description: "Draft status of the episode",
required: false,
},
featured: {
type: "boolean",
description: "Whether or not this episode is featured",
required: false,
},
description: {
type: "string",
description:
"Brief description of the episode (also used in the SEO metadata)",
required: true,
},
tags: {
type: "string",
// type: "list",
// of: { type: "string" },
description: "Comma separated listing of tags",
required: false,
},
image: {
type: "string",
description: "Social share image",
},
transistorUrl: {
type: "string",
description:
"Brief description of the episode (also used in the SEO metadata)",
required: false,
},
duration: {
type: "string",
description: "Duration of the episode",
required: false,
},
},
computedFields: {
ep: {
description: "Episode number (aka the file name)",
type: "string",
resolve: (record) => createStandardSlug(record._id),
},
draft: {
description: "Draft status of the episode",
type: "boolean",
resolve: (record) =>
record?.draft ?? record._raw.sourceFileName.startsWith("_"),
},
slug: {
description: "Computed slug of the episode",
type: "string",
resolve: (record) => record?.slug ?? createStandardSlug(record._id),
},
href: {
description: "Local url path of the episode",
type: "string",
resolve: (record) =>
`${ROUTE_PREFIX_PODCAST}/${record?.slug ?? createStandardSlug(record._id)}`,
},
image: {
description: "Primary image for the podcast episode",
type: "string",
resolve: (record) => podcastEpisodeImage(record.image),
},
},
}));
/**
* Blog post schema
*/
export const BlogPost = defineDocumentType(() => ({
name: "BlogPost",
filePathPattern: `blog/**/*.md`,
fields: {
category: {
type: "enum",
description: "The type of post",
options: ["blog", "snapshot"],
default: "blog",
required: true,
},
title: {
type: "string",
description: "The title of the post",
required: true,
},
longTitle: {
type: "string",
description: "The longer title of the post",
required: false,
},
date: {
type: "date",
description: "The public date of the post",
required: true,
},
draft: {
type: "boolean",
description: "Draft status of the post",
required: false,
},
featured: {
type: "boolean",
description: "Whether or not this post is featured",
required: false,
},
description: {
type: "string",
description:
"Brief description of the post (also used in the SEO metadata)",
required: true,
},
tags: {
type: "string",
description: "Comma separated listing of tags",
required: false,
},
image: {
type: "string",
description: "Social share image",
},
author: {
required: true,
type: "enum",
options: ["nick", "james", "teague"],
description: "Author of the post",
},
},
computedFields: {
id: {
description: "Newsletter edition number (aka the file name)",
type: "string",
resolve: (record) => createStandardSlug(record._id),
},
draft: {
description: "Draft status of the post",
type: "boolean",
resolve: (record) =>
record?.draft ?? record._raw.sourceFileName.startsWith("_"),
},
slug: {
description: "Computed slug of the post",
type: "string",
resolve: (record) => {
if (record.category == "snapshot") {
return `${record?.slug || createStandardSlug(record.title)}-${createStandardSlug(record._id)}`;
}
return record?.slug ?? createStandardSlug(record._id);
},
},
href: {
description: "Local url route of the post",
type: "string",
resolve: (record) => {
if (record.category == "snapshot") {
return `${ROUTE_PREFIX_SNAPSHOT}/${record?.slug || createStandardSlug(record.title)}-${createStandardSlug(record._id)}`;
}
return `${ROUTE_PREFIX_BLOG}/${record?.slug ?? createStandardSlug(record._id)}`;
},
},
},
}));
export default makeSource({
contentDirPath: "content",
documentTypes: [PodcastEpisode, BlogPost],
onMissingOrIncompatibleData: "fail",
onUnknownDocuments: "fail",
onExtraFieldData: "fail",
});