-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentlayer.config.ts
181 lines (177 loc) · 4.88 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
import { defineDocumentType, makeSource } from "contentlayer/source-files";
import rehypeRaw from "rehype-raw";
import rehypeSlug from "rehype-slug";
import remarkFrontmatter from "remark-frontmatter";
import remarkGfm from "remark-gfm";
import remarkToc from "remark-toc";
import { OWNER_NAME, SITE_OG_IMAGE, SITE_URL } from "./src/config";
import { rehypeImgSize } from "./src/lib/components/MDX/plugins";
import { remarkShiki } from "./src/lib/domains/shiki";
export const BlogPost = defineDocumentType(() => ({
name: "BlogPost",
filePathPattern: `**/blog/[slug]/**/*.mdx`,
contentType: "mdx",
fields: {
title: { type: "string", required: true },
seo_title: {
type: "string",
required: false,
description: "Title shown in search results",
},
description: { type: "string", required: true },
published_at: { type: "date", required: true },
updated_at: { type: "date", required: false },
published: { type: "boolean", required: true },
url: { type: "string", required: false },
image: { type: "string", required: false },
use_client: {
type: "boolean",
description: "If MDX has client components",
required: false,
default: false,
},
},
computedFields: {
page_path: {
type: "string",
description: "URL pathname for post",
resolve: (post) => {
const flattend_path = post._raw.flattenedPath;
const cleaned_path = flattend_path.replace(
"(main)/blog/[slug]/",
"blog/",
);
return `/${cleaned_path}`;
},
},
page_slug: {
type: "string",
description: "slug used in the URL of the page",
resolve: (post) => {
const flattend_path = post._raw.flattenedPath;
const cleaned_slug = flattend_path.split("/").at(-1);
return cleaned_slug;
},
},
structuredData: {
type: "json",
resolve: (post) => {
const cleaned_path = `/${post._raw.flattenedPath.replace("(main)/blog/[slug]/", "blog/")}`;
return {
"@context": "https://schema.org",
"@type": "BlogPosting",
headline: post.title,
datePublished: post.published_at,
dateModified: post.updated_at,
description: post.description,
image: post.image
? `${SITE_URL}${post.image}`
: `${SITE_URL}${SITE_OG_IMAGE}`,
url: `${SITE_URL}${post?.url ?? cleaned_path}`,
author: {
"@type": "Person",
name: OWNER_NAME,
},
};
},
},
},
}));
export const Page = defineDocumentType(() => ({
name: "Page",
filePathPattern: `**/[mdxPageSlug]/*.mdx`,
contentType: "mdx",
fields: {
title: { type: "string", required: true },
seo_title: {
type: "string",
required: false,
description: "Title shown in search results",
},
description: { type: "string", required: true },
published_at: { type: "date", required: true },
updated_at: { type: "date", required: false },
published: { type: "boolean", required: true },
skip_page: {
type: "boolean",
required: false,
default: false,
description: "To skip a page from being an explicit route segment",
},
},
computedFields: {
page_path: {
type: "string",
description: "URL pathename for post",
resolve: (post) => {
const flattend_path = post._raw.flattenedPath;
const cleaned_path = flattend_path.replace("(main)/[mdxPageSlug]/", "");
return `/${cleaned_path}`;
},
},
page_slug: {
type: "string",
description: "slug used in the URL of the page",
resolve: (post) => {
const flattend_path = post._raw.flattenedPath;
const cleaned_slug = flattend_path.split("/").at(-1);
return cleaned_slug;
},
},
},
}));
export default makeSource({
contentDirPath: "src/app",
contentDirExclude: [
"node_modules",
".git",
".yarn",
".cache",
".next",
".contentlayer",
"package.json",
"tsconfig.json",
"*.ts",
"*/**/*.ts",
"*.tsx",
"*/**/*.tsx",
"*.css",
"*/**/*.css",
"*.png",
"*/**/*.png",
],
documentTypes: [BlogPost, Page],
mdx: {
resolveCwd: "relative",
remarkPlugins: [
remarkFrontmatter,
remarkShiki,
remarkGfm,
[remarkToc, { tight: true }],
],
rehypePlugins: [
[
// @ts-expect-error TS shush
rehypeRaw,
{
passThrough: [
"mdxFlowExpression",
"mdxJsxFlowElement",
"mdxJsxTextElement",
"mdxTextExpression",
"mdxjsEsm",
],
},
],
rehypeSlug,
[rehypeImgSize, { dir: "public" }],
],
esbuildOptions(options) {
options.platform = "node";
options.define = {
"process.env": JSON.stringify(process.env),
};
return options;
},
},
});