-
Notifications
You must be signed in to change notification settings - Fork 1
/
contentlayer.config.ts
129 lines (117 loc) · 3.27 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
128
129
import remarkGfm from 'remark-gfm';
import rehypeSlug from 'rehype-slug';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import rehypeExternalLinks from 'rehype-external-links';
import {
defineDocumentType,
defineNestedType,
makeSource,
} from 'contentlayer/source-files';
/**
* GENERIC TYPES
*/
const Image = defineNestedType(() => ({
name: 'Image',
fields: {
src: { type: 'string', required: true },
alt: { type: 'string', required: true },
caption: { type: 'markdown' },
},
}));
const Externals = defineNestedType(() => ({
name: 'Externals',
fields: {
Medium: { type: 'string' },
ProductHunt: { type: 'string' },
Website: { type: 'string' },
},
}));
/**
* BLOG POSTS
*/
const POSTS_DIR_NAME = 'posts';
const Categories = ['Engineering', 'Product', 'Careers'] as const;
export const Post = defineDocumentType(() => ({
name: 'Post',
filePathPattern: `./${POSTS_DIR_NAME}/*.mdx`,
contentType: 'mdx',
fields: {
title: { type: 'string', required: true },
publishedAt: { type: 'date', required: true },
summary: { type: 'string' },
cover: { type: 'nested', of: Image },
externals: { type: 'nested', of: Externals },
category: { type: 'enum', options: Categories },
tags: { type: 'list', of: { type: 'string' } },
},
computedFields: {
slug: {
type: 'string',
resolve: post => {
const name = post._raw.flattenedPath.split(`${POSTS_DIR_NAME}/`).pop();
const slug = name?.replace(/^(\d{3})-/, '');
if (!slug) throw new Error(`Invalid file name: ${name}`);
return slug;
},
},
},
}));
/**
* PROJECTS
*/
const PROJECTS_DIR_NAME = 'projects';
const Review = defineNestedType(() => ({
name: 'Review',
fields: {
biography: { type: 'string' },
summary: { type: 'markdown' },
avatar: { type: 'nested', of: Image },
},
}));
export const Project = defineDocumentType(() => ({
name: 'Project',
filePathPattern: `./${PROJECTS_DIR_NAME}/*.mdx`,
contentType: 'mdx',
fields: {
title: { type: 'string', required: true },
period: { type: 'string' },
subtitle: { type: 'string' },
cover: { type: 'nested', of: Image },
role: { type: 'string' },
space: { type: 'string' },
tags: { type: 'list', of: { type: 'string' } },
stack: { type: 'list', of: { type: 'string' } },
externals: { type: 'nested', of: Externals },
background: { type: 'markdown' },
carousel: { type: 'list', of: Image },
responsibilities: { type: 'list', of: { type: 'markdown' } },
achievements: { type: 'list', of: { type: 'markdown' } },
review: { type: 'nested', of: Review },
},
computedFields: {
slug: {
type: 'string',
resolve: post => {
const n = post._raw.flattenedPath.split(`${PROJECTS_DIR_NAME}/`).pop();
const slug = n?.replace(/^(\d{3})-/, '');
if (!slug) throw new Error(`Invalid file name: ${name}`);
return slug;
},
},
},
}));
export default makeSource({
contentDirPath: 'content',
documentTypes: [Post, Project],
mdx: {
remarkPlugins: [remarkGfm],
rehypePlugins: [
[
rehypeExternalLinks,
{ target: '_blank', rel: ['noopener', 'noreferrer', 'nofollow'] },
],
rehypeSlug,
rehypeAutolinkHeadings,
],
},
});