1

I cloned this gatsby netlify cms starter blog and am trying to add custom previews. I have followed all the instructions, but it is still not working. This is my config.yml:


...
collections:
  - name: "blog"
    label: "Blog"
    folder: "content/blog"
    create: true
    fields:
      - { name: path, label: Path }
      - { name: date, label: Date, widget: date }
      - { name: title, label: Title }
      - { name: description, label: Description }
      - { name: body, label: Body, widget: markdown }

I added the gatsby-plugin-netlify-cms like this:

plugins: [
    {
      resolve: 'gatsby-plugin-netlify-cms',
      options: {
        modulePath: `${__dirname}/src/cms/cms.js`,
      },
    },

In my cms.js, I have:

import CMS from 'netlify-cms-app'

import BlogPostPreview from './preview-templates/BlogPostPreview'

CMS.registerPreviewTemplate('blog', BlogPostPreview)

And my BlogPostPreview is just rendering the BlogPostTemplate:

import React from 'react'
import { BlogPostTemplate } from '../../templates/blog-post'

const BlogPostPreview = ({ entry, widgetFor }) => {

  return (
    <BlogPostTemplate
      body={widgetFor('body')}
      title={entry.getIn(['data', 'title'])}
      date={new Date()}
    />
  )
}

export default BlogPostPreview

Am I missing anything? I don't think so. I compared my config with the official starter repo, and could not find any differences. When I go to the new blog post on the admin portal, I just see the default plain html. Any help would really be appreciated.

You can view my repo here

I_A
  • 331
  • 2
  • 14

1 Answers1

2

You say

import { BlogPostTemplate } from '../../templates/blog-post'

but I can't see a file of that name in that folder?

That is a different between your repo and the official starter one, it should be

import { PostTemplate } from '../../templates/post-template'
Luke Storry
  • 6,032
  • 1
  • 9
  • 22
  • Thanks, this question is outdated now. I fixed the problem, it seems that the actual problem was with my hosting not updating after changes. – I_A Jul 24 '20 at 15:48