mdx-content
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

MDX Content

A super fully typed MDX loader for your project.

Installation

$ npm install --save-dev mdx-content

$ yarn add -D mdx-content

Usage

Create some documents definitions

import { defineDocumentType, InferDocument } from 'mdx-content'

export const post = defineDocumentType({
  name: 'post',
  filePathPattern: 'posts/**/*.mdx',
  fields: {
    title: z => z.string().transform(v => v.toUpperCase()),
    publishedAt: z => z.date(),
    status: z => z.enum(['draft', 'published']),
  },
  computedFields: {
    slug(source) {
      return source.file.filename.replace(/\.mdx$/, '')
    },
  },
});

Load documents

export const sources = makeSource({
  documentFolder: 'content',
  documentTypes: [post],
});

Use documents

import { useDocument } from 'mdx-content'
const { posts } = sources;

(await posts).forEach(post => {
  console.log(post.title);
  console.log(post.slug);
  console.log(post.publishedAt);

  const PostComponent = useDocument(post);
});

/mdx-content/

    Package Sidebar

    Install

    npm i mdx-content

    Weekly Downloads

    2

    Version

    0.0.2

    License

    MIT

    Unpacked Size

    62.4 kB

    Total Files

    14

    Last publish

    Collaborators

    • maxscharwath