Closed whoisryosuke closed 5 years ago
You need to setup the control / preview as this isn't a builtin widget - https://www.netlifycms.org/docs/custom-widgets/#registerwidget
Thanks, didn't notice that part of the README.
Put in a PR to add Gatsby instructions since the Netlify docs didn't cover the integration: https://github.com/buz-zard/gatsby-mdx/pull/49
I did register the widget in my/src/cmd/cms.js
file but it doesn't work.
I get No preview for widget 'mdx'
and No control for widget 'mdx'
.
Any idea?
import { MdxControl, MdxPreview } from "netlify-cms-widget-mdx
CMS.registerWidget("mdx", MdxControl, MdxPreview)
Thanks in advance!
@Knaackee a full configuration setup would help a little more.
Oh iam sorry. It's working now.
I'm having the same problem. I get both errors:
"No control for widget 'mdx'."
"No preview for widget 'mdx'."
import CMS from "netlify-cms-app"
import { MdxControl, MdxPreview, setupPreview } from "netlify-cms-widget-mdx"
import {shortcodes} from "."
CMS.registerWidget('mdx', MdxControl, setupPreview({
components: shortcodes
}))
module.exports = {
siteMetadata: {
title: `Gatsby Default Starter`,
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
author: `@gatsbyjs`,
},
plugins: [
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `markdown-pages`,
path: `${__dirname}/src/markdown-pages`,
}
},
{
resolve: "gatsby-plugin-page-creator",
options: {
path: `${__dirname}/src/markdown-pages`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `gatsby-starter-default`,
short_name: `starter`,
start_url: `/`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
},
},
{
resolve: `gatsby-plugin-mdx`,
options: {
defaultLayouts: {
default: require.resolve(`./src/page-templates/default-page.template.js`),
},
extensions: [`.mdx`, `.md`]
},
},
{
resolve: `gatsby-plugin-netlify-cms`,
options: {
modulePath: `${__dirname}/src/cms/cms.js`, // for custom preview in the Netlify CMS
},
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// `gatsby-plugin-offline`,
],
}
backend:
name: git-gateway
repo: avorg/audioverse-public-website
branch: gatsby
commit_messages:
create: 'Create {{collection}} “{{slug}}”'
update: 'Update {{collection}} “{{slug}}”'
delete: 'Delete {{collection}} “{{slug}}”'
uploadMedia: '[skip ci] Upload “{{path}}”'
deleteMedia: '[skip ci] Delete “{{path}}”'
media_folder: static/img
public_folder: /img
local_backend: true
collections:
- name: "blog"
label: "Blog"
folder: "src/pages/blog"
create: true
slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
fields:
- {label: "Template Key", name: "templateKey", widget: "hidden", default: "blog-post"}
- {label: "Title", name: "title", widget: "string"}
- {label: "Publish Date", name: "date", widget: "datetime"}
- {label: "Description", name: "description", widget: "text"}
- {label: "Featured Post", name: "featuredpost", widget: "boolean"}
- {label: "Featured Image", name: "featuredimage", widget: image}
- {label: "Body", name: "body", widget: "markdown"}
- {label: "Tags", name: "tags", widget: "list"}
- name: "pages"
label: "Pages"
folder: "src/markdown-pages"
create: true
slug: "{{slug}}"
format: "frontmatter"
fields:
- {label: "Template Key", name: "templateKey", widget: "hidden", default: "page"}
- {label: "Title", name: "title", widget: "string"}
- {label: "Slug", name: "slug", widget: "string"}
- {label: "Publish Date", name: "date", widget: "datetime"}
- {label: "Description", name: "description", widget: "text"}
- {label: "Featured Image", name: "featuredimage", widget: "image"}
- {label: "Body", name: "body", widget: "mdx"}
@narthur well your setup should be fine, though the error the error indicates that the CMS.registerWidget
wasn't even called. I suggest checking if the file get's executed and if the error persists maybe make a repo to test the issue.
@karolis-sh Thanks for taking a look! I'm pretty new to Gatsby. What's the easiest way to ensure cms.js is getting executed?
@narthur I guess just add a console.log statement and check the terminal when starting the Gatsby app - that should indicate that you provided the correct modulePath
value
Yeah, console.log
is not showing up when I reload the gatsby app. I guess I'll work on debugging why the page isn't getting executed.
Just confirmed that the file is getting run. I imported some CSS in cms.js and it was applied to the preview. But the errors persist.
The preview if enabled also displays:
Version
MDX Widget:
^0.4.1
Gatsby:Here's my
config.yml
: