Skip to content
Source
Sign inSign up
TanStack/cli
Open History to see the last commit

content-collections.ts

37 lines1.0 KB

1import { defineCollection, defineConfig } from '@content-collections/core'
2import { compileMarkdown } from '@content-collections/markdown'
3import { compileMDX } from '@content-collections/mdx'
4import remarkGfm from 'remark-gfm'
5import { z } from 'zod'
6​
7const blog = defineCollection({
8 name: 'blog',
9 directory: 'content/blog',
10 include: '**/*.{md,mdx}',
11 schema: z.object({
12 title: z.string(),
13 description: z.string(),
14 pubDate: z.string(),
15 content: z.string(),
16 heroImage: z.string().optional(),
17 }),
18 transform: async (document, context) => {
19 const isMdx = document._meta.filePath.endsWith('.mdx')
20​
21 return {
22 ...document,
23 slug: document._meta.path,
24 pubDate: new Date(document.pubDate).toISOString(),
25 html: isMdx ? null : await compileMarkdown(context, document),
26 mdx: isMdx
27 ? await compileMDX(context, document, {
28 remarkPlugins: [remarkGfm],
29 })
30 : null,
31 }
32 },
33})
34​
35export default defineConfig({
36 collections: [blog],
37})