-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontentlayer.config.ts
More file actions
83 lines (78 loc) · 2.29 KB
/
contentlayer.config.ts
File metadata and controls
83 lines (78 loc) · 2.29 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
import { defineDocumentType, makeSource } from 'contentlayer/source-files'
import readingTime from 'reading-time'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypeKatex from 'rehype-katex'
import rehypePresetMinify from 'rehype-preset-minify'
import rehypePrettyCode from 'rehype-pretty-code'
import rehypeSlug from 'rehype-slug'
import remarkGfm from 'remark-gfm'
import remarkMath from 'remark-math'
/** @type {import('rehype-pretty-code'.Options} */
const rehypePrettyOptions = {
theme: 'dracula-soft',
keepBackground: true,
}
const computedFields: any = {
readingTime: {
type: 'json',
resolve: (post: any) => readingTime(post.body.raw),
},
slug: {
type: 'string',
resolve: (post) => {
const parts = post._raw.flattenedPath.split('/')
return parts[parts.length - 1]
},
},
url: {
type: 'string',
resolve: (post) => {
const parts = post._raw.flattenedPath.split('/')
const slug = parts[parts.length - 1]
return `/blog/${slug}`
},
},
}
export const Post = defineDocumentType(() => ({
name: 'Post',
filePathPattern: `posts/*.mdx`,
contentType: 'mdx',
fields: {
title: { type: 'string', required: true },
date: { type: 'string', required: true },
summary: { type: 'string', required: true },
draft: { type: 'boolean', required: true },
banner: { type: 'string', required: false },
tags: {
type: 'list',
of: { type: 'string' },
required: false,
default: [],
},
},
computedFields,
}))
export default makeSource({
contentDirPath: 'content',
contentDirExclude: ['project.json'],
documentTypes: [Post],
mdx: {
rehypePlugins: [
[rehypeKatex, { output: 'mathml' }],
//@ts-ignore
[rehypePrettyCode, rehypePrettyOptions],
rehypeSlug,
[
rehypeAutolinkHeadings,
{
properties: {
className: ['anchor'],
},
},
],
// @ts-ignore
rehypePresetMinify,
],
remarkPlugins: [remarkGfm, remarkMath],
},
})