astro-netlify-cms icon indicating copy to clipboard operation
astro-netlify-cms copied to clipboard

How to extend netlifyCMS with CMS.registerWidget?

Open preetamslot opened this issue 2 years ago • 4 comments

Hi, Where is the place to add custom widgets for netlify CMS to extend the cms? thanks

preetamslot avatar Jun 24 '22 19:06 preetamslot

Hi @preetamslot!

It's currently not supported. My plan is to offer config options that the integration would read and then call registerWidget for you, but haven't had a chance to do that yet.

So the config would look something like:

NetlifyCMS({
  config: { ... },
  widgets: [
    {
      name: 'my-widget',
      control: <PATH TO REACT COMPONENT>,
    }
  ],
})

delucis avatar Jun 24 '22 23:06 delucis

Reopening this to keep as a reminder that we do want to support this!

delucis avatar Jul 04 '22 08:07 delucis

It would also be cool to support CMS.registerMediaLibrary(), probably with the same pattern as widget

codelastnight avatar Oct 18 '22 05:10 codelastnight

Hi there, regarding the mdx support, I did some testing and made somehow to register the mdx widget inside the editor editing these files: vite-plugin-admin-dashboard.ts:

return `${imports.join('\n')}
    import * as NCMS from 'netlify-cms-app';
    import { MdxControl, MdxPreview } from 'netlify-cms-widget-mdx';
    NCMS.registerWidget('mdx', MdxControl, MdxPreview);

    ${identityWidget}
    export default {
      cms: NCMS,
      config: JSON.parse('${JSON.stringify(config)}'),
      previewStyles: [${styles.join(',')}],
    }`

and inside the collection of the posts in the NetlifyCMS config I added: `extension: 'mdx', format: 'frontmatter', fields:

This setup allows you to edit a mdx file, but I've found two problems:

  • the preview panel displays an error when I try to add mdx content: Invalid MDX: ReferenceError: process is not defined

  • I'm not able to visualize the mdx content created into astro (i.e. trying to view the blog post created)

Hope this can help to further understand and implement mdx in netlify cms!

tomashco avatar Mar 29 '23 22:03 tomashco