-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent-collections.ts
38 lines (36 loc) · 986 Bytes
/
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
import { extractMetadata } from '@/lib/extract-metadata'
import { defineCollection, defineConfig } from '@content-collections/core'
import { compileMDX } from '@content-collections/mdx'
import { remarkPlugins } from '@prose-ui/core'
const pages = defineCollection({
name: 'pages',
directory: 'content/docs',
include: '**/*.mdx',
schema: (z) => ({
title: z.optional(z.string()),
}),
transform: async (page, ctx) => {
const { toc, title } = await extractMetadata(page.content)
const content = await compileMDX(ctx, page, {
remarkPlugins: remarkPlugins(),
})
let path
if (page._meta.path === 'index') {
path = ''
} else if (page._meta.path.endsWith('/index')) {
path = page._meta.path.slice(0, -6)
} else {
path = page._meta.path
}
return {
...page,
path: `/${path}`,
toc,
title: page.title ?? title,
content,
}
},
})
export default defineConfig({
collections: [pages],
})