-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcontentlayer.config.ts
120 lines (112 loc) · 2.74 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
import {
ComputedFields,
defineDocumentType,
FieldDefs,
makeSource,
} from "contentlayer/source-files"
import rehypeAutolinkHeadings from "rehype-autolink-headings"
import rehypeCodeTitles from "rehype-code-titles"
import rehypePrism from "rehype-prism-plus"
import rehypeSlug from "rehype-slug"
import remarkGfm from "remark-gfm"
import remarkDirective from "remark-directive"
import toc from "markdown-toc"
import siteConfig from "./site.config"
import { remarkAdmonition } from "./lib/remark-utils"
const fields: FieldDefs = {
title: { type: "string" },
description: { type: "string" },
package: { type: "string" },
}
const computedFields: ComputedFields = {
slug: {
type: "string",
resolve: (doc) => doc._raw.sourceFileName.replace(/\.mdx$/, ""),
},
editUrl: {
type: "string",
resolve: (doc) => `${siteConfig.repo.editUrl}/${doc._id}`,
},
params: {
type: "list",
resolve: (doc) => doc._raw.flattenedPath.split("/"),
},
frontmatter: {
type: "json",
resolve: (doc) => ({
title: doc.title,
description: doc.description,
tags: doc.tags,
author: doc.author,
slug: `/${doc._raw.flattenedPath}`,
toc: toc(doc.body.raw, { maxdepth: 3 }).json.filter((t) => t.lvl !== 1),
}),
},
}
const Overview = defineDocumentType(() => ({
name: "Overview",
filePathPattern: "overview/**/*.mdx",
contentType: "mdx",
fields,
computedFields: {
...computedFields,
pathname: {
type: "string",
resolve: () => "/overview/[slug]",
},
},
}))
const Guide = defineDocumentType(() => ({
name: "Guide",
filePathPattern: "guides/**/*.mdx",
contentType: "mdx",
fields,
computedFields,
}))
const Component = defineDocumentType(() => ({
name: "Component",
filePathPattern: "components/**/*.mdx",
contentType: "mdx",
fields,
computedFields: {
...computedFields,
pathname: {
type: "string",
resolve: () => "/components/[...slug]",
},
},
}))
const Snippet = defineDocumentType(() => ({
name: "Snippet",
filePathPattern: "snippets/**/*.mdx",
contentType: "mdx",
fields,
computedFields: {
...computedFields,
framework: {
type: "string",
resolve: (doc) => doc._raw.sourceFilePath.split("/")[1],
},
},
}))
const contentLayerConfig = makeSource({
contentDirPath: "data",
documentTypes: [Overview, Guide, Snippet, Component],
mdx: {
remarkPlugins: [remarkGfm, remarkDirective, remarkAdmonition],
rehypePlugins: [
rehypeSlug,
rehypeCodeTitles,
rehypePrism,
[
rehypeAutolinkHeadings,
{
behavior: "append",
test: ["h2", "h3", "h4"],
properties: { className: ["anchor"] },
},
],
],
},
})
export default contentLayerConfig