Code Monkey home page Code Monkey logo

Comments (11)

karolis-sh avatar karolis-sh commented on May 26, 2024

You need to setup the control / preview as this isn't a builtin widget - https://www.netlifycms.org/docs/custom-widgets/#registerwidget

from gatsby-mdx.

whoisryosuke avatar whoisryosuke commented on May 26, 2024

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:
#49

from gatsby-mdx.

Knaackee avatar Knaackee commented on May 26, 2024

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!

from gatsby-mdx.

karolis-sh avatar karolis-sh commented on May 26, 2024

@Knaackee a full configuration setup would help a little more.

from gatsby-mdx.

Knaackee avatar Knaackee commented on May 26, 2024

Oh iam sorry. It's working now.

from gatsby-mdx.

narthur avatar narthur commented on May 26, 2024

I'm having the same problem. I get both errors:

"No control for widget 'mdx'."

"No preview for widget 'mdx'."

cms.js

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
}))

gatsby-config.js

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`,
    ],
}

config.yml

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"}

from gatsby-mdx.

karolis-sh avatar karolis-sh commented on May 26, 2024

@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.

from gatsby-mdx.

narthur avatar narthur commented on May 26, 2024

@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?

from gatsby-mdx.

karolis-sh avatar karolis-sh commented on May 26, 2024

@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

from gatsby-mdx.

narthur avatar narthur commented on May 26, 2024

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.

from gatsby-mdx.

narthur avatar narthur commented on May 26, 2024

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.

from gatsby-mdx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.