-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcontentlayer.config.ts
85 lines (80 loc) · 2.01 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
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 Docs = defineDocumentType(() => ({
name: "Docs",
filePathPattern: "docs/**/*.mdx",
contentType: "mdx",
fields,
computedFields: {
...computedFields,
pathname: {
type: "string",
resolve: () => "/docs/[slug]",
},
},
}))
const contentLayerConfig = makeSource({
contentDirPath: "content",
contentDirInclude: [],
documentTypes: [Docs],
mdx: {
remarkPlugins: [remarkGfm, remarkDirective, remarkAdmonition],
rehypePlugins: [
rehypeSlug,
rehypeCodeTitles,
rehypePrism,
[
rehypeAutolinkHeadings,
{
behavior: "wrap",
test: ["h2", "h3", "h4"],
properties: { className: ["title-anchor"] },
},
],
],
},
})
export default contentLayerConfig