-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvelite.config.js
80 lines (76 loc) · 2.43 KB
/
velite.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
import rehypeAutolinkHeadings from "rehype-autolink-headings"
import rehypePrettyCode from "rehype-pretty-code"
import rehypeSlug from "rehype-slug"
import remarkGfm from "remark-gfm"
import { defineCollection, defineConfig, s } from "velite"
// `s` is extended from Zod with some custom schemas,
// you can also import re-exported `z` from `velite` if you don't need these extension schemas.
const authors = defineCollection({
name: "Author",
pattern: "authors/*.mdx",
schema: s
.object({
name: s.string(),
description: s.string().optional(),
avatar: s.string(),
twitter: s.string(),
})
.transform((data) => ({ ...data, permalink: `/authors/${data.name}` })),
})
const posts = defineCollection({
name: "Post", // collection type name
pattern: "blog/*.mdx", // content files glob pattern
schema: s
.object({
title: s.string(), // Zod primitive type
description: s.string().optional(),
slug: s.slug("posts"), // validate format, unique in posts collection
date: s.isodate(), // input Date-like string, output ISO Date string.
image: s.string(), // input image as string, not process it.
published: s.boolean().default(true),
metadata: s.metadata(), // extract markdown reading-time, word-count, etc.
content: s.mdx(), // transform mdx to html
authors: s.array(s.string()), // array of strings
})
// more additional fields (computed fields)
.transform((data) => ({ ...data, permalink: `/blog/${data.slug}` })),
})
export default defineConfig({
collections: {
posts,
authors,
},
mdx: {
rehypePlugins: [
rehypeSlug,
[
rehypePrettyCode,
{
theme: "github-dark",
onVisitLine(node) {
// 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) {
node.properties.className.push("line--highlighted")
},
onVisitHighlightedWord(node) {
node.properties.className = ["word--highlighted"]
},
},
],
[
rehypeAutolinkHeadings,
{
properties: {
className: ["subheading-anchor"],
ariaLabel: "Link to section",
},
},
],
],
},
})