-
Notifications
You must be signed in to change notification settings - Fork 0
/
content-collections.ts
72 lines (66 loc) · 2.38 KB
/
content-collections.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
import { defineCollection, defineConfig } from '@content-collections/core';
import { compileMDX } from '@content-collections/mdx';
import rehypeShikiFromHighlighter from '@shikijs/rehype/core';
import remarkGfm from 'remark-gfm';
import { createHighlighter } from 'shiki';
import { createCssVariablesTheme } from 'shiki/core';
// Shiki stuff
const cssVars = createCssVariablesTheme({
name: 'css-variables',
variablePrefix: '--shiki-',
variableDefaults: {},
fontStyle: true,
});
const highlighter = await createHighlighter({
themes: [cssVars],
langs: ['html', 'js', 'json', 'jsx', 'md', 'mdx', 'ts', 'tsx'],
});
const doc = defineCollection({
name: 'Doc',
directory: 'data',
include: '**/*.md?(x)',
schema: z => ({
/** Title of this page. */
title: z.optional(z.string()),
/** ID of the category this page belongs to. */
category: z.optional(z.string()),
/** Whether or not to show the page's title at its top. */
showTitle: z.boolean().default(true),
/** Whether or not to show the sidebar when this page is viewed. */
showSidebar: z.boolean().default(true),
/** Whether or not to include this page as an item in the sidebar. */
includeInSidebar: z.boolean().default(true),
}),
transform: async (doc, ctx) => {
const slugs = doc._meta.path === 'index' ? [] : doc._meta.path.split('/');
const url = `/${slugs
.map(slug => {
const parts = slug.split('-');
return (isNaN(Number(parts[0])) ? parts : parts.slice(1)).join('-');
})
.join('/')}`;
const code = await compileMDX(ctx, doc, {
remarkPlugins: [remarkGfm],
rehypePlugins: [
[rehypeShikiFromHighlighter, highlighter, { theme: cssVars.name }],
],
});
return { ...doc, _id: doc._meta.filePath, url, body: { code } };
},
});
const siteConfig = defineCollection({
name: 'Config',
directory: 'data',
include: 'config.json',
parser: 'json',
schema: z => ({
/** Site title, appearing by default as the home page's `<title>`, as well
* as in the Nav's header. */
title: z.string().default('Docs'),
/** Template for the `<title>` of pages. */
titleTemplate: z.string().default('%s – Docs'),
/** Object where keys are category IDs and values are display names. */
categories: z.record(z.string(), z.string()).default({}),
}),
});
export default defineConfig({ collections: [doc, siteConfig] });