-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentlayer.config.ts
61 lines (59 loc) · 1.76 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
import { defineDocumentType, makeSource } from 'contentlayer/source-files';
import readingTime from 'reading-time';
import remarkGfm from 'remark-gfm';
import rehypeSlug from 'rehype-slug';
import rehypeAutolinkHeadings from 'rehype-autolink-headings'; // 제목에 자동으로 앵커 태그를 추가해주는 라이브러리
import rehypePrettyCode from 'rehype-pretty-code';
import transformImgSrc from './plugins/transform-image.src.mjs';
import { type Pluggable } from 'unified';
export const Post = defineDocumentType(() => ({
name: 'Post',
filePathPattern: `**/*.mdx`,
contentType: 'mdx',
fields: {
title: { type: 'string', required: true },
createdAt: { type: 'date', required: true },
updatedAt: { type: 'date', required: false },
author: { type: 'string', required: true },
tags: { type: 'list', of: { type: 'string' }, required: true },
categories: { type: 'list', of: { type: 'string' }, required: true },
summary: { type: 'string', required: true },
},
computedFields: {
url: {
type: 'string',
resolve: (post) => `/posts/${post._raw.flattenedPath}`,
},
readingMinutes: {
type: 'string',
resolve: (post) => Math.ceil(readingTime(post.body.raw).minutes),
},
},
}));
export default makeSource({
contentDirPath: 'posts',
documentTypes: [Post],
mdx: {
remarkPlugins: [remarkGfm, transformImgSrc],
rehypePlugins: [
rehypeSlug,
[
rehypePrettyCode,
{
theme: 'vitesse-dark',
keepBackground: true,
grid: true,
},
],
[
rehypeAutolinkHeadings,
{
properties: {
className: ['anchor'],
},
behavior: 'wrap',
},
],
] as unknown as Pluggable[],
},
});