# mdx-content

> Fully typed MDX content loader

Latest version **0.0.2** (published 2022-11-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install mdx-content
pnpm add mdx-content
yarn add mdx-content
bun add mdx-content
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2022-11-21 |
| First published | 2022-11-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 61 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Maxime Scharwath |
| Maintainers | maxscharwath |
| Keywords | mdx, content, loader, typescript |

## Links

- npm: https://www.npmjs.com/package/mdx-content
- Repository: https://github.com/maxscharwath/mdx-content
- Homepage: https://github.com/maxscharwath/mdx-content#readme
- Issues: https://github.com/maxscharwath/mdx-content/issues
- npm.io page: https://npm.io/package/mdx-content

## Dependencies (4)

- [zod](https://npm.io/package/zod.md) ^3.19.1
- [globby](https://npm.io/package/globby.md) ^13.1.2
- [esbuild](https://npm.io/package/esbuild.md) ^0.15.13
- [mdx-bundler](https://npm.io/package/mdx-bundler.md) ^9.0.1

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 0.0.2 (latest) — 2022-11-21
- 0.0.1 — 2022-11-14

## README

# MDX Content

A super fully typed MDX loader for your project.

## Installation

```bash
$ npm install --save-dev mdx-content

$ yarn add -D mdx-content
```

## Usage

### Create some documents definitions
```ts
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
```ts
export const sources = makeSource({
  documentFolder: 'content',
  documentTypes: [post],
});
```

### Use documents
```tsx
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);
});
```

---
_Source: https://npm.io/package/mdx-content · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
