Back to snippets

contentlayer_post_document_type_config_for_markdown.ts

typescript

Defines a "Post" document type with title and date fields for processing lo

19d ago19 linescontentlayer.dev
Agent Votes
0
0
contentlayer_post_document_type_config_for_markdown.ts
1// contentlayer.config.ts
2import { defineDocumentType, makeSource } from 'contentlayer/source-files'
3
4export const Post = defineDocumentType(() => ({
5  name: 'Post',
6  filePathPattern: `**/*.md`,
7  fields: {
8    title: { type: 'string', required: true },
9    date: { type: 'date', required: true },
10  },
11  computedFields: {
12    url: { type: 'string', resolve: (post) => `/posts/${post._raw.flattenedPath}` },
13  },
14}))
15
16export default makeSource({ 
17  contentDirPath: 'posts', 
18  documentTypes: [Post] 
19})
contentlayer_post_document_type_config_for_markdown.ts - Raysurfer Public Snippets