-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentlayer.config.ts
110 lines (102 loc) · 3.15 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
import { ComputedFields, FieldDefs, defineDocumentType, makeSource } from 'contentlayer/source-files';
import path from 'path';
import { remarkCodeTitles, remarkExtractFrontmatter, remarkImgToJsx } from 'pliny/mdx-plugins.js';
import readingTime from 'reading-time';
import { rehypeAccessibleEmojis } from 'rehype-accessible-emojis';
// Rehype packages
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import rehypeCitation from 'rehype-citation';
import rehypePresetMinify from 'rehype-preset-minify';
import rehypePrismPlus from 'rehype-prism-plus';
import rehypeSlug from 'rehype-slug';
// Remark packages
import remarkFootnotes from 'remark-footnotes';
import remarkGfm from 'remark-gfm';
import remarkMath from 'remark-math';
const root = process.cwd();
// ---------------------------------------------------------------------------
// UTILS
// ---------------------------------------------------------------------------
const fields: FieldDefs = { title: { type: 'string', required: true } };
const computedFields: ComputedFields = {
readingTime: { type: 'json', resolve: (doc) => readingTime(doc.body.raw) },
slug: {
type: 'string',
resolve: (doc) => doc._raw.flattenedPath.replace(/^.+?(\/)/, ''),
},
};
// ---------------------------------------------------------------------------
// MODELS
// ---------------------------------------------------------------------------
export const BlogEntry = defineDocumentType(() => ({
name: 'BlogEntry',
filePathPattern: 'blog/**/*.{md,mdx}',
contentType: 'mdx',
fields: {
title: fields.title,
date: { type: 'date', required: true },
summary: { type: 'string', required: true },
language: {
type: 'enum',
options: ['pt', 'en'],
default: 'en',
},
tags: { type: 'list', of: { type: 'string' }, required: true },
lastmod: { type: 'date' },
images: { type: 'list', of: { type: 'string' } },
canonicalUrl: { type: 'string' },
},
computedFields: {
...computedFields,
hero: {
type: 'string',
resolve: (doc) => `/content/${doc._raw.flattenedPath.replace('blog', 'posts')}/hero.png`,
},
},
}));
export const MDXEntry = defineDocumentType(() => ({
name: 'MDXEntry',
filePathPattern: 'misc/**/*.mdx',
contentType: 'mdx',
fields: {
title: fields.title,
color: {
type: 'string',
required: true,
},
},
computedFields: {
hero: {
type: 'string',
resolve: (doc) => `/content/${doc._raw.flattenedPath}.jpg`,
},
slug: computedFields.slug,
},
}));
export default makeSource({
contentDirPath: 'src/content',
documentTypes: [BlogEntry, MDXEntry],
mdx: {
cwd: process.cwd(),
remarkPlugins: [
// @ts-ignore
remarkExtractFrontmatter,
remarkGfm,
remarkCodeTitles,
[remarkFootnotes, { inlineNotes: true }],
remarkMath,
remarkImgToJsx,
],
rehypePlugins: [
rehypeAccessibleEmojis,
rehypeSlug,
rehypeAutolinkHeadings,
// @ts-ignore
[rehypeCitation, { path: path.join(root, 'data') }],
// @ts-ignore
[rehypePrismPlus, { ignoreMissing: true }],
// @ts-ignore
rehypePresetMinify,
],
},
});