decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.83k stars 3.04k forks source link

Support for the .mdx format #7158

Open Juniors017 opened 6 months ago

Juniors017 commented 6 months ago

I'm using DecapCMS with Docusaurus, and like many other applications, Docusaurus utilizes .mdx files. I really wish that DecapCMS could support .mdx extensions.

mmkal commented 6 months ago

Proper .mdx support would be good, but for now you could use a custom formatter: https://decapcms.org/docs/custom-formatters

Juniors017 commented 6 months ago

hi For now, I'm using this in my collections:

collections:
- name: docs
  label: Documentations
  label_singular: 'Documentation'
  folder: docs
  extension: "mdx" 
  format: "frontmatter"

It's functional.

Could you tell me more about the custom formatter? I'm not quite sure what it will bring to me. Maybe just for the preview? How do I create one for the .mdx format?

it's this code with gray-matter for exemple :

`const matter = require('gray-matter');
const { CMS } = require('mycollection'); 

CMS.registerCustomFormat('mdx', 'mdx', {
  fromFile: text => {
    const { data, content } = matter(text);
    return { frontmatter: data, content };
  },
  toFile: value => {
    const { frontmatter, content } = value;
    return matter.stringify(content, frontmatter);
  },
});`
Juniors017 commented 5 months ago

?