import { defineDocumentType, makeSource } from 'contentlayer2/source-files'

export const Post = defineDocumentType(() => ({
    name: 'Post',
    filePathPattern: `blog/**/*.mdx`,
    contentType: 'mdx',
    fields: {
        title: { type: 'string', required: true },
        date: { type: 'string', required: true },
        description: { type: 'string', required: true },
        tags: { type: 'list', of: { type: 'string' }, required: true },
    },
    computedFields: {
        slug: {
            type: 'string',
            resolve: (doc) => doc._raw.sourceFileName.replace(/\.mdx$/, ''),
        },
        url: {
            type: 'string',
            resolve: (post) => `/blog/${post._raw.sourceFileName.replace(/\.mdx$/, '')}`,
        },
    },
}))

export default makeSource({
    contentDirPath: 'content',
    documentTypes: [Post],
})
