souporserious / mdxts

The Content and Documentation SDK for React

Home Page:https://mdxts.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

validation

souporserious opened this issue · comments

Validating MDX

Content can be typed using a simplified export of zod, in general anything should be able to run through this schema as a function:

import { createMDXTSPlugin } from 'mdxts/next'
import { array, date, string } from 'mdxts/value'

const withMDXTS = createMDXTSPlugin({
  gitSource: 'https://github.com/souporserious/mdxts/tree/main',
  sources: {
    docs: {
      include: 'docs/**/*.(tsx|mdx)',
      schema: {
        title: string(),
        date: date({
          requiredMessage: 'A date is required for all docs.',
          invalidMessage: 'The provided date is invalid.',
        }),
        tags: array().optional()
      }
    },
  },
})

export default withMDXTS({
  experimental: {
    appDir: true,
  },
})
export const title = "How to report errors"
export const date = "2023-02-22"
export const tags = ["react", "css", "animation"]

This is an example of exporting metadata from MDX.

Validating code blocks

Code blocks should also be validated similar to shiki-twoslash.

Related

https://markdoc.dev/docs/validation

https://www.contentlayer.dev/docs/concepts/content-modeling

This is done now using Front Matter.