forked from csesoc/learn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentlayer.config.js
136 lines (131 loc) · 3.5 KB
/
contentlayer.config.js
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
import { defineDocumentType, makeSource } from 'contentlayer/source-files'
import readingTime from 'reading-time'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypeCodeTitles from 'rehype-code-titles'
import rehypeHighlight from 'rehype-highlight'
import rehypeSlug from 'rehype-slug'
import remarkGfm from 'remark-gfm'
import rehypePrismPlus from 'rehype-prism-plus'
const computedFields = {
readingTime: { type: 'json', resolve: (doc) => readingTime(doc.body.raw) },
wordCount: {
type: 'number',
resolve: (doc) => doc.body.raw.split(/\s+/gu).length
},
slug: {
type: 'string',
resolve: (doc) => doc._raw.sourceFileName.replace(/\.mdx$/, '')
}
}
export const ArticleType = defineDocumentType(() => ({
name: 'ArticleType',
filePathPattern: `articles/*.mdx`,
contentType: 'mdx',
fields: {
title: {
type: 'string',
description: 'The title of the article',
required: true
},
desc: {
type: 'string',
description: 'One sentence that summarises the article objective.',
required: true
},
author: {
type: 'string',
description: 'The author of the article',
required: true
},
date: {
type: 'date',
description: 'The date of the article',
required: true
},
coverPhoto: {
type: 'string',
description:
'A cover photo that appears at the top of the article and in meta images',
required: false
},
tags: {
type: 'list',
of: {
type: 'string'
},
description: 'List of tags applied to the article',
required: false
}
},
computedFields
}))
export const CourseRevisionOffering = defineDocumentType(() => ({
name: 'CourseRevisionOffering',
filePathPattern: `course-revision/*.mdx`,
contentType: 'mdx',
fields: {
title: {
type: 'string',
description: 'The title of the exercise set e.g. COMP1511 22T3 Revision Session',
required: true
},
desc: {
type: 'string',
description: 'A brief 1-2 sentence description of what this course revision contains',
required: true
},
course: {
type: 'string',
description: 'The course that the revision set relates to (COMP1511, COMP2521, ...)',
required: true
},
offering: {
type: 'string',
description: 'The offering of the course that the revision set is intended for (22T3, 23T1, ...)',
required: true
}
},
computedFields
}))
export const CourseRevisionExercise = defineDocumentType(() => ({
name: 'CourseRevisionExercise',
filePathPattern: `course-revision/**/*.mdx`,
contentType: 'mdx',
fields: {
title: {
type: 'string',
description: 'The title of the exercise',
required: true
},
desc: {
type: 'string',
description: 'One sentence that summarises the exercise objective.',
required: true
},
class: {
type: 'string',
description: 'The class the exercise relates to (COMP1511, COMP2521, etc)',
required: true
},
difficulty: {
type: 'number',
description: 'The difficulty of the exercise (1=Easy, 2=Medium, 3=Hard)',
required: true
}
},
computedFields
}))
export default makeSource({
contentDirPath: 'data',
documentTypes: [ArticleType, CourseRevisionOffering, CourseRevisionExercise],
mdx: {
remarkPlugins: [remarkGfm],
rehypePlugins: [
rehypeCodeTitles,
rehypeHighlight,
rehypePrismPlus,
rehypeAutolinkHeadings,
rehypeSlug
]
}
})