forked from joshwcomeau/beatmapper
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathvelite.config.ts
More file actions
51 lines (45 loc) · 2.12 KB
/
velite.config.ts
File metadata and controls
51 lines (45 loc) · 2.12 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
import { join } from "node:path";
import { cwd } from "node:process";
import { type RehypeExpressiveCodeOptions, default as rehypeExpressiveCode } from "rehype-expressive-code";
import { type IOptions, rehypeGithubAlerts } from "rehype-github-alerts";
import { default as rehypeSlug } from "rehype-slug";
import { default as remarkGfm } from "remark-gfm";
import { defineCollection, defineConfig, s } from "velite";
const mdx = s.mdx({
remarkPlugins: [[remarkGfm]],
rehypePlugins: [
[rehypeSlug],
[rehypeGithubAlerts, { build: (alert, children) => ({ type: "element", tagName: "blockquote", properties: { className: [`alert-${alert.keyword.toLowerCase()}`] }, children: [...children] }) } as Partial<IOptions>],
[rehypeExpressiveCode, { themes: ["github-light-default", "github-dark-default"], styleOverrides: { frames: { shadowColor: "transparent" } }, themeCssSelector: (theme) => `.${theme.type}` } as RehypeExpressiveCodeOptions],
],
});
function resolveId(path: string, collection: string) {
const [...splat] = path.replace(join(cwd(), `src/content/${collection}`), "").split("\\");
return splat.join("/").replace("/index", "").replace(".local", "").replace(".mdx", "").slice(1);
}
const docs = defineCollection({
name: "Doc",
pattern: "docs/**/*.mdx",
schema: s.object({ title: s.string(), subtitle: s.string().optional(), category: s.nullable(s.string()).default(null), order: s.number().default(0), prev: s.string().optional(), next: s.string().optional(), code: mdx, tableOfContents: s.toc() }).transform((data, ctx) => {
if (!ctx.meta.path || typeof ctx.meta.path !== "string") return { id: "", ...data };
return { id: resolveId(ctx.meta.path, "docs"), ...data };
}),
});
const prompts = defineCollection({
name: "Prompt",
pattern: "prompts/**/*.mdx",
schema: s.object({ title: s.string(), code: mdx }).transform((data, ctx) => {
if (!ctx.meta.path || typeof ctx.meta.path !== "string") return { id: "", ...data };
return { id: resolveId(ctx.meta.path, "prompts"), ...data };
}),
});
export default defineConfig({
root: "src/content",
output: {
clean: true,
},
collections: {
docs: docs,
prompts: prompts,
},
});