-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontentlayer.config.ts
More file actions
90 lines (84 loc) · 2.77 KB
/
contentlayer.config.ts
File metadata and controls
90 lines (84 loc) · 2.77 KB
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
import { Tutorial } from "./app/contentlayer/schema/tutorial";
import { BlogPost } from "./app/contentlayer/schema/blog-post";
import { DocsPage } from "./app/contentlayer/schema/docs-page";
import { makeSource } from "contentlayer/source-files";
import remarkGfm from "remark-gfm";
import type { Options as RehypePrettyCodeOptions } from "rehype-pretty-code";
import rehypePrettyCode from "rehype-pretty-code";
import rehypeShiki from '@shikijs/rehype'
import rehypeRaw from "rehype-raw";
import { nodeTypes } from "@mdx-js/mdx";
import codeImport from "remark-code-import";
import rehypeMdxCodeProps from 'rehype-mdx-code-props'
import rehypeSlug from "rehype-slug";
import rehypeMermaid from "./lib/rehypeMermaid";
import remarkExampleCompiler, { parseCompileMetaString } from "./lib/compileExample";
import { transformerNotationHighlight, transformerNotationWordHighlight, transformerMetaHighlight } from '@shikijs/transformers'
export const CODE_BLOCK_FILENAME_REGEX = /fileName="([^"]+)"/;
const DEFAULT_REHYPE_PRETTY_CODE_OPTIONS: RehypePrettyCodeOptions = {
onVisitLine(node: any) {
// Prevent lines from collapsing in `display: grid` mode, and
// allow empty lines to be copy/pasted
if (node.children.length === 0) {
node.children = [{ type: "text", value: " " }];
}
},
onVisitHighlightedLine(node: any) {
if (!node.properties.className) node.properties.className = [];
node.properties.className.push("highlighted");
},
onVisitHighlightedChars(node: any) {
node.properties.className = ["highlighted"];
},
filterMetaString: (meta: string) =>
meta.replace(CODE_BLOCK_FILENAME_REGEX, ""),
};
export default makeSource({
contentDirPath: "content",
documentTypes: [DocsPage, BlogPost, Tutorial],
mdx: {
remarkPlugins: [
[remarkExampleCompiler, {}],
[codeImport as any, { rootDir: process.cwd() + "/content" }],
remarkGfm,
],
rehypePlugins: [
[
rehypeShiki,
{
themes: {
light: "github-light",
dark: "github-dark"
},
transformers: [
transformerNotationHighlight(),
transformerNotationWordHighlight(),
transformerMetaHighlight()
],
langs: ["rust"],
defaultColor: 'dark',
parseMetaString: parseCompileMetaString,
},
],
[
rehypeMermaid,
{
background: "transparent",
className: "mermaid-diagram",
},
],
[rehypeRaw, { passThrough: nodeTypes }],
[
rehypePrettyCode,
{
...DEFAULT_REHYPE_PRETTY_CODE_OPTIONS, theme: {
light: "github-light",
dark: "github-dark"
},
},
] as any,
[rehypeSlug],
[rehypeMdxCodeProps],
],
},
});