forked from life-itself/second-renaissance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentlayer.config.js
221 lines (209 loc) · 6.56 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import { defineDocumentType, defineNestedType, makeSource } from 'contentlayer/source-files';
import codeExtra from 'remark-code-extra';
import { h } from 'hastscript';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import rehypeMathjax from 'rehype-mathjax';
import rehypePrismPlus from 'rehype-prism-plus';
import rehypeSlug from 'rehype-slug';
import remarkGfm from 'remark-gfm';
import remarkMath from 'remark-math';
import remarkToc from 'remark-toc';
import wikiLinkPlugin from 'remark-wiki-link-plus';
import siteConfig from './config/siteConfig';
import smartypants from 'remark-smartypants';
const sharedFields = {
title: { type: 'string' },
description: { type: 'string' },
image: { type: 'string' },
layout: { type: 'string', default: 'docs' },
editLink: { type: 'boolean' },
};
const computedFields = {
url_path: {
type: 'string',
resolve: (post) => post._raw.flattenedPath,
},
};
const Page = defineDocumentType(() => ({
name: 'Page',
filePathPattern: '!*(profiles|topics)/**/*.md*',
contentType: 'mdx',
fields: {
...sharedFields,
},
computedFields,
}));
const blogFields = {
date: { type: 'date' },
layout: { type: 'string', default: 'blog' },
authors: {
type: 'list',
of: { type: 'string' },
},
};
const Blog = defineDocumentType(() => ({
name: 'Blog',
contentType: 'mdx',
fields: {
...sharedFields,
...blogFields,
},
computedFields,
}));
const NestedUrl = defineNestedType(() => ({
name: "NestedUrl",
fields: {
url: { type: "string" },
cached: { type: "string" },
cached_new: { type: "string" },
}
}))
const SocialChangeFields = defineNestedType(() => ({
name: "SocialChange",
fields: {
inner: { type: "string" },
cultural: { type: "string" },
systems: { type: "string" }
}
}))
const resolveArrays = ["topic", "activity", "people", "locations"].reduce((el, key) =>
({ ...el,[key]: {
type: "json",
resolve: (doc) => doc[key] == 0 ? [] : doc[key]
}}), {}
)
const Profile = defineDocumentType(() => ({
name: "Profile",
filePathPattern: "profiles/**/*.md*",
contentType: "mdx",
fields: {
...sharedFields,
layout: { type: "string", default: "profile" },
id: { type: "string" },
url: { type: "string" },
tagline: { type: "string" },
activity: { type: "json" },
topic: { type: "json" },
regions: { type: "string" },
locations: { type: "json" },
started: { type: "number" },
ended: { type: "string" },
active: { type: "string" },
people: { type: "json" },
notes_data_entry: { type: "string" },
facebook: { type: "string" },
twitter: { type: "string" },
instagram: { type: "string" },
linkedin: { type: "string" },
youtube: { type: "string" },
blog: { type: "string" },
logo: { type: "nested", of: NestedUrl },
image: { type: "nested", of: NestedUrl },
curation_status: { type: "string" },
social_change: { type: "nested", of: SocialChangeFields}
},
computedFields: {
...computedFields,
...resolveArrays
}
}))
const Topic = defineDocumentType(() => ({
name: "Topic",
filePathPattern: "topics/**/*.md*",
contentType: "mdx",
fields: {
...sharedFields,
id: { type: "string" },
image: { type: "string" },
emoji: { type: "json" },
super_topic: { type: "string" },
},
computedFields
}))
const contentLayerExcludeDefaults = ['node_modules', '.git', '.yarn', '.cache', '.next', '.contentlayer', 'package.json', 'tsconfig.json'];
export default makeSource({
contentDirPath: siteConfig.content,
contentDirExclude: contentLayerExcludeDefaults.concat(['.flowershow', '.obsidian']),
documentTypes: [Blog, Page, Profile, Topic],
mdx: {
remarkPlugins: [
remarkGfm,
[smartypants, {quotes: false, dashes: 'oldschool'}],
remarkMath,
[wikiLinkPlugin, { markdownFolder: siteConfig.content }],
/** Using the code extra plugin from https://github.com/s0/remark-code-extra
* to create new mermaid pre tags to use with mdx-mermaid.
* rehypePrismPlus plugin modifies the pre tags and due to this mdx-mermaid
* component cannot receive the values in the required format.
* Refer issue https://github.com/flowershow/flowershow/issues/12 for more info.
*/
[codeExtra, {
transform: (node) => {
if (node.type == 'code' && node.lang == 'mermaid') {
// reset values else rehype-prism-plus throws error
node.type = '';
node.lang = '';
return ({
// create new pre tag element here for mermaid
after: [{
type: 'element',
tagName: 'pre',
properties: {
className: 'code-mermaid',
},
children: [{
type: 'text',
value: node.value,
}],
}],
// remove the pre tag element created by rehype-prism-plus
// otherwise both will be displayed
transform: (n) => {
const preElem = n.data.hChildren.find((el) => el.tagName === 'pre');
const index = n.data.hChildren.indexOf(preElem);
n.data.hChildren.splice(index, 1);
},
});
}
return null;
},
}],
[remarkToc, {
heading: 'Table of contents',
// maxDepth: "3",
tight: true,
}],
],
rehypePlugins: [
rehypeSlug,
[rehypeAutolinkHeadings, {
test(element) {
return ['h2', 'h3', 'h4', 'h5', 'h6'].includes(element.tagName)
&& element.properties?.id !== 'table-of-contents';
},
content(node) {
return [
h(
'svg',
{
xmlns: 'http://www.w3.org/2000/svg',
fill: '#ab2b65',
viewBox: '0 0 20 20',
className: 'w-5 h-5',
},
[
h('path', {
fillRule: 'evenodd',
clipRule: 'evenodd',
d: 'M9.493 2.853a.75.75 0 00-1.486-.205L7.545 6H4.198a.75.75 0 000 1.5h3.14l-.69 5H3.302a.75.75 0 000 1.5h3.14l-.435 3.148a.75.75 0 001.486.205L7.955 14h2.986l-.434 3.148a.75.75 0 001.486.205L12.456 14h3.346a.75.75 0 000-1.5h-3.14l.69-5h3.346a.75.75 0 000-1.5h-3.14l.435-3.147a.75.75 0 00-1.486-.205L12.045 6H9.059l.434-3.147zM8.852 7.5l-.69 5h2.986l.69-5H8.852z',
}),
],
),
];
},
}],
rehypeMathjax,
[rehypePrismPlus, { ignoreMissing: true }],
],
},
});