-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontentlayer.config.ts
112 lines (107 loc) · 3.46 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
import {
ComputedFields,
defineDocumentType,
makeSource,
} from 'contentlayer/source-files';
import remarkEmoji from 'remark-emoji';
import remarkGfm from 'remark-gfm';
import remarkSlug from 'remark-slug';
import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';
import rehypePresetMinify from 'rehype-preset-minify';
import siteConfig from './configs/site-config';
import { getTableOfContents } from './utils/mdx-utils';
import { rehypeMdxCodeMeta } from './utils/rehype-code-meta';
const computedFields: ComputedFields = {
slug: {
type: 'string',
//resolve: doc => `/${doc._raw.flattenedPath}`,
resolve: doc => doc._raw.flattenedPath.replace(/^.+?(\/)/, ''),
},
blobUrl: {
type: 'string',
resolve: doc =>
`${siteConfig.repo.blobUrl}/${doc._raw.flattenedPath.replace(
/^.+?(\/)/,
'',
)}`,
},
};
const Blog = defineDocumentType(() => ({
name: 'Blog',
filePathPattern: 'blog/**/*.mdx',
contentType: 'mdx',
fields: {
title: { type: 'string', required: true },
tags: { type: 'list', of: { type: 'string' }, required: true },
categories: { type: 'list', of: { type: 'string' } },
authors: { type: 'list', of: { type: 'string' } },
date: { type: 'string' },
description: { type: 'string' },
referenceHref: { type: 'list', of: { type: 'string' } }, // 参考连接
reprintedHref: { type: 'string' }, // 转载
},
computedFields: {
...computedFields,
frontMatter: {
type: 'json',
resolve: doc => ({
date: doc.date,
authors: doc.authors,
title: doc.title,
tags: doc.tags,
categories: doc.categories,
description: doc.description,
slug: doc._raw.flattenedPath.replace(/^.+?(\/)/, ''),
path: `/${doc._raw.flattenedPath}`,
headings: getTableOfContents(doc.body.raw), // 生成的内容目录
referenceHref: doc.referenceHref, // 参考连接
reprintedHref: doc.reprintedHref, // 转载连接
}),
},
},
}));
const CbecNote = defineDocumentType(() => ({
name: 'CbecNote',
filePathPattern: 'cbec-note/**/*.mdx',
contentType: 'mdx',
fields: {
title: { type: 'string', required: true },
tags: { type: 'list', of: { type: 'string' }, required: true },
categories: { type: 'list', of: { type: 'string' } },
authors: { type: 'list', of: { type: 'string' } },
date: { type: 'string' },
description: { type: 'string' },
referenceHref: { type: 'list', of: { type: 'string' } }, // 参考连接
reprintedHref: { type: 'string' }, // 转载
},
computedFields: {
...computedFields,
frontMatter: {
type: 'json',
resolve: doc => ({
date: doc.date,
authors: doc.authors,
title: doc.title,
tags: doc.tags,
categories: doc.categories,
description: doc.description,
slug: doc._raw.flattenedPath.replace(/^.+?(\/)/, ''),
path: `/${doc._raw.flattenedPath}`,
headings: getTableOfContents(doc.body.raw), // 生成的内容目录
referenceHref: doc.referenceHref, // 参考连接
reprintedHref: doc.reprintedHref, // 转载连接
}),
},
},
}));
const contentLayerConfig = makeSource({
contentDirPath: 'data',
documentTypes: [Blog, CbecNote],
mdx: {
cwd: process.cwd(),
rehypePlugins: [rehypeMdxCodeMeta, rehypeKatex, rehypePresetMinify],
remarkPlugins: [remarkSlug, remarkGfm, remarkEmoji, remarkMath],
},
});
export default contentLayerConfig;