-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontentlayer.config.ts
127 lines (120 loc) · 3.55 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
import remarkGfm from 'remark-gfm'
import remarkUnwrapImages from 'remark-unwrap-images'
import rehypePrism from 'rehype-prism-plus'
import {
type ComputedFields,
defineDocumentType,
makeSource,
} from 'contentlayer/source-files'
import { generateBase64Image } from './src/lib/server/utils'
import { Hardware, Skill, Social, Software } from './src/types/content'
// Common computed fields
const computedFields: ComputedFields = {
thumbnailPlaceholder: {
type: 'string',
resolve: async (doc) => await generateBase64Image(doc.thumbnail),
},
}
// Document types
const About = defineDocumentType(() => ({
name: 'About',
filePathPattern: `data/about.json`,
contentType: 'data',
fields: {
avatar: { type: 'string', required: true },
name: { type: 'string', required: true },
username: { type: 'string', required: true },
summary: { type: 'string', required: true },
description: { type: 'list', of: { type: 'string' }, required: true },
skills: { type: 'list', of: Skill, required: true },
social: { type: 'nested', of: Social, required: true },
},
computedFields: {
avatarPlaceholder: {
type: 'string',
resolve: async (doc) => await generateBase64Image(doc.avatar),
},
},
}))
const Equipment = defineDocumentType(() => ({
name: 'Equipment',
filePathPattern: `data/equipment.json`,
contentType: 'data',
fields: {
software: { type: 'nested', of: Software, required: true },
hardware: { type: 'nested', of: Hardware, required: true },
},
}))
const Post = defineDocumentType(() => ({
name: 'Post',
filePathPattern: `blog/**/*.mdx`,
contentType: 'mdx',
fields: {
title: { type: 'string', required: true },
thumbnail: { type: 'string', required: true },
thumbnailCredit: { type: 'string', required: true },
summary: { type: 'string', required: true },
tags: { type: 'list', of: { type: 'string' }, required: true },
author: { type: 'string', required: true },
createdAt: { type: 'string', required: true },
updatedAt: { type: 'string', required: true },
},
computedFields: {
...computedFields,
slug: {
type: 'string',
resolve: (doc) => doc._raw.sourceFileName.replace(/\.mdx/, ''),
},
readTime: {
type: 'number',
resolve: (doc) => Math.ceil(doc.body.raw.split(' ').length / 183),
},
createdAt: { type: 'string', resolve: (doc) => doc.createdAt.trim() },
updatedAt: { type: 'string', resolve: (doc) => doc.updatedAt.trim() },
},
}))
const Project = defineDocumentType(() => ({
name: 'Project',
filePathPattern: `project/**/*.mdx`,
contentType: 'mdx',
fields: {
title: { type: 'string', required: true },
thumbnail: { type: 'string', required: true },
description: { type: 'string', required: true },
github: { type: 'string' },
demo: { type: 'string' },
},
computedFields: {
...computedFields,
// 01-foo-bar.mdx -> 1
position: {
type: 'number',
resolve: (doc) =>
Number(
doc._raw.sourceFileName
.replace(/\.mdx/, '')
.split('-')
.slice(0, 1)
.toString(),
),
},
// 01-foo-bar.mdx -> foo-bar
slug: {
type: 'string',
resolve: (doc) =>
doc._raw.sourceFileName
.replace(/\.mdx/, '')
.split('-')
.slice(1)
.join('-'),
},
},
}))
export default makeSource({
contentDirPath: 'src/_content',
documentTypes: [About, Equipment, Post, Project],
mdx: {
remarkPlugins: [remarkGfm, remarkUnwrapImages],
rehypePlugins: [rehypePrism],
},
})