Gatsby + Netlify CMS: Any ways to enable featured images for each entry in src/pages/index.js?












1














is there any solution for enabling featured images in TOP/HOME page from the template https://github.com/netlify-templates/gatsby-starter-netlify-cms ?



I meant to say I want the TOP/HOME page (src/pages.index.js) to display those images as well.



I've tried to do that in 2 ways but it fails.



Way 1:



From config.yml like that in below.



  - name: "pages"
label: "Pages"
files:
- file: "src/pages/index.md"
label: "Homepage"
name: "homepage"


Then created a src/pages/index.md markdown file and move the js file src/pages/index.js to a directory src/template.
Added that markdown file as an entry in my pages collection.
But I got an Gatsby related error like this.



Your site's "gatsby-node.js" created a page with a component that doesn't exist

{ path: '/',
tags: null,
component: '/Users/class/gatsby-netlify-blog/src/templates/null.js',
context: { id: 'bb87bb60-04a6-51ea-8524-c7b2332a2fdb' } }
error See the documentation for createPage https://www.gatsbyjs.org/docs/bound-action-creators/#createPage


Way 2:



Tried the same way in src/pages/index.js from the templae, gatsby-starter-netlify-cms wrote in blog-post.js, using Content component.



import React from 'react'
import PropTypes from 'prop-types'
import { Link, graphql } from 'gatsby'
import Layout from '../components/Layout'
import Content, { HTMLContent } from '../components/Content'

export default class IndexPage extends React.Component {
render() {
const { data } = this.props
const { edges: posts } = data.allMarkdownRemark
const FeaturedImg = {
content,
contentComponent,
}
const PostContent = contentComponent || Content

return (
<Layout>
<FeaturedImg
content={post.html}
contentComponent={HTMLContent}
/>
<section className="section">
<div className="container">
<div className="content">
<h1 className="has-text-weight-bold is-size-2">Latest Stories</h1>
</div>
{posts
.map(({ node: post }) => (
<div
className="content"
style={{ border: '1px solid #eaecee', padding: '2em 4em' }}
key={post.id}
>
<p>
<Link className="has-text-primary" to={post.fields.slug}>
{post.frontmatter.title}
</Link>
<span> &nbsp; </span>
<small>{post.frontmatter.date}</small>
</p>
<PostContent content={content} />
<p>
{post.excerpt}
<br />
<br />
<Link className="button is-small" to={post.fields.slug}>
Keep Reading →
</Link>
</p>
</div>
))}
</div>
</section>
</Layout>
)
}
}

IndexPage.propTypes = {
content: PropTypes.node.isRequired,
contentComponent: PropTypes.func,
data: PropTypes.shape({
allMarkdownRemark: PropTypes.shape({
edges: PropTypes.array,
}),
}),
}

export const pageQuery = graphql`
query IndexQuery {
allMarkdownRemark(
sort: { order: DESC, fields: [frontmatter___date] },
filter: { frontmatter: { templateKey: { eq: "blog-post" } }}
) {
edges {
node {
excerpt(pruneLength: 400)
id
fields {
slug
}
frontmatter {
title
templateKey
date(formatString: "MMMM DD, YYYY")
}
}
}
}
}
`


But again, I got errors like this in below.



ERROR  Failed to compile with 1 errors                                                                                                                                                                    11:23:51

error in ./src/pages/index.js

Module Error (from ./node_modules/eslint-loader/index.js):

/Users/class/gatsby-netlify-blog/src/pages/index.js
12:7 error 'content' is not defined no-undef
13:7 error 'contentComponent' is not defined no-undef
15:25 error 'contentComponent' is not defined no-undef
20:20 error 'post' is not defined no-undef
42:41 error 'content' is not defined no-undef

✖ 5 problems (5 errors, 0 warnings)


@ ./.cache/sync-requires.js 19:50-112
@ ./.cache/app.js
@ multi ./node_modules/react-hot-loader/patch.js (webpack)-hot-middleware/client.js?path=http://localhost:8000/__webpack_hmr&reload=true&overlay=false ./.cache/app


*I've already asked Gitter, issue in gatsby-starter-netlify-cms and Gatsby's Spectrum Chat but couldn't get the right path.










share|improve this question



























    1














    is there any solution for enabling featured images in TOP/HOME page from the template https://github.com/netlify-templates/gatsby-starter-netlify-cms ?



    I meant to say I want the TOP/HOME page (src/pages.index.js) to display those images as well.



    I've tried to do that in 2 ways but it fails.



    Way 1:



    From config.yml like that in below.



      - name: "pages"
    label: "Pages"
    files:
    - file: "src/pages/index.md"
    label: "Homepage"
    name: "homepage"


    Then created a src/pages/index.md markdown file and move the js file src/pages/index.js to a directory src/template.
    Added that markdown file as an entry in my pages collection.
    But I got an Gatsby related error like this.



    Your site's "gatsby-node.js" created a page with a component that doesn't exist

    { path: '/',
    tags: null,
    component: '/Users/class/gatsby-netlify-blog/src/templates/null.js',
    context: { id: 'bb87bb60-04a6-51ea-8524-c7b2332a2fdb' } }
    error See the documentation for createPage https://www.gatsbyjs.org/docs/bound-action-creators/#createPage


    Way 2:



    Tried the same way in src/pages/index.js from the templae, gatsby-starter-netlify-cms wrote in blog-post.js, using Content component.



    import React from 'react'
    import PropTypes from 'prop-types'
    import { Link, graphql } from 'gatsby'
    import Layout from '../components/Layout'
    import Content, { HTMLContent } from '../components/Content'

    export default class IndexPage extends React.Component {
    render() {
    const { data } = this.props
    const { edges: posts } = data.allMarkdownRemark
    const FeaturedImg = {
    content,
    contentComponent,
    }
    const PostContent = contentComponent || Content

    return (
    <Layout>
    <FeaturedImg
    content={post.html}
    contentComponent={HTMLContent}
    />
    <section className="section">
    <div className="container">
    <div className="content">
    <h1 className="has-text-weight-bold is-size-2">Latest Stories</h1>
    </div>
    {posts
    .map(({ node: post }) => (
    <div
    className="content"
    style={{ border: '1px solid #eaecee', padding: '2em 4em' }}
    key={post.id}
    >
    <p>
    <Link className="has-text-primary" to={post.fields.slug}>
    {post.frontmatter.title}
    </Link>
    <span> &nbsp; </span>
    <small>{post.frontmatter.date}</small>
    </p>
    <PostContent content={content} />
    <p>
    {post.excerpt}
    <br />
    <br />
    <Link className="button is-small" to={post.fields.slug}>
    Keep Reading →
    </Link>
    </p>
    </div>
    ))}
    </div>
    </section>
    </Layout>
    )
    }
    }

    IndexPage.propTypes = {
    content: PropTypes.node.isRequired,
    contentComponent: PropTypes.func,
    data: PropTypes.shape({
    allMarkdownRemark: PropTypes.shape({
    edges: PropTypes.array,
    }),
    }),
    }

    export const pageQuery = graphql`
    query IndexQuery {
    allMarkdownRemark(
    sort: { order: DESC, fields: [frontmatter___date] },
    filter: { frontmatter: { templateKey: { eq: "blog-post" } }}
    ) {
    edges {
    node {
    excerpt(pruneLength: 400)
    id
    fields {
    slug
    }
    frontmatter {
    title
    templateKey
    date(formatString: "MMMM DD, YYYY")
    }
    }
    }
    }
    }
    `


    But again, I got errors like this in below.



    ERROR  Failed to compile with 1 errors                                                                                                                                                                    11:23:51

    error in ./src/pages/index.js

    Module Error (from ./node_modules/eslint-loader/index.js):

    /Users/class/gatsby-netlify-blog/src/pages/index.js
    12:7 error 'content' is not defined no-undef
    13:7 error 'contentComponent' is not defined no-undef
    15:25 error 'contentComponent' is not defined no-undef
    20:20 error 'post' is not defined no-undef
    42:41 error 'content' is not defined no-undef

    ✖ 5 problems (5 errors, 0 warnings)


    @ ./.cache/sync-requires.js 19:50-112
    @ ./.cache/app.js
    @ multi ./node_modules/react-hot-loader/patch.js (webpack)-hot-middleware/client.js?path=http://localhost:8000/__webpack_hmr&reload=true&overlay=false ./.cache/app


    *I've already asked Gitter, issue in gatsby-starter-netlify-cms and Gatsby's Spectrum Chat but couldn't get the right path.










    share|improve this question

























      1












      1








      1







      is there any solution for enabling featured images in TOP/HOME page from the template https://github.com/netlify-templates/gatsby-starter-netlify-cms ?



      I meant to say I want the TOP/HOME page (src/pages.index.js) to display those images as well.



      I've tried to do that in 2 ways but it fails.



      Way 1:



      From config.yml like that in below.



        - name: "pages"
      label: "Pages"
      files:
      - file: "src/pages/index.md"
      label: "Homepage"
      name: "homepage"


      Then created a src/pages/index.md markdown file and move the js file src/pages/index.js to a directory src/template.
      Added that markdown file as an entry in my pages collection.
      But I got an Gatsby related error like this.



      Your site's "gatsby-node.js" created a page with a component that doesn't exist

      { path: '/',
      tags: null,
      component: '/Users/class/gatsby-netlify-blog/src/templates/null.js',
      context: { id: 'bb87bb60-04a6-51ea-8524-c7b2332a2fdb' } }
      error See the documentation for createPage https://www.gatsbyjs.org/docs/bound-action-creators/#createPage


      Way 2:



      Tried the same way in src/pages/index.js from the templae, gatsby-starter-netlify-cms wrote in blog-post.js, using Content component.



      import React from 'react'
      import PropTypes from 'prop-types'
      import { Link, graphql } from 'gatsby'
      import Layout from '../components/Layout'
      import Content, { HTMLContent } from '../components/Content'

      export default class IndexPage extends React.Component {
      render() {
      const { data } = this.props
      const { edges: posts } = data.allMarkdownRemark
      const FeaturedImg = {
      content,
      contentComponent,
      }
      const PostContent = contentComponent || Content

      return (
      <Layout>
      <FeaturedImg
      content={post.html}
      contentComponent={HTMLContent}
      />
      <section className="section">
      <div className="container">
      <div className="content">
      <h1 className="has-text-weight-bold is-size-2">Latest Stories</h1>
      </div>
      {posts
      .map(({ node: post }) => (
      <div
      className="content"
      style={{ border: '1px solid #eaecee', padding: '2em 4em' }}
      key={post.id}
      >
      <p>
      <Link className="has-text-primary" to={post.fields.slug}>
      {post.frontmatter.title}
      </Link>
      <span> &nbsp; </span>
      <small>{post.frontmatter.date}</small>
      </p>
      <PostContent content={content} />
      <p>
      {post.excerpt}
      <br />
      <br />
      <Link className="button is-small" to={post.fields.slug}>
      Keep Reading →
      </Link>
      </p>
      </div>
      ))}
      </div>
      </section>
      </Layout>
      )
      }
      }

      IndexPage.propTypes = {
      content: PropTypes.node.isRequired,
      contentComponent: PropTypes.func,
      data: PropTypes.shape({
      allMarkdownRemark: PropTypes.shape({
      edges: PropTypes.array,
      }),
      }),
      }

      export const pageQuery = graphql`
      query IndexQuery {
      allMarkdownRemark(
      sort: { order: DESC, fields: [frontmatter___date] },
      filter: { frontmatter: { templateKey: { eq: "blog-post" } }}
      ) {
      edges {
      node {
      excerpt(pruneLength: 400)
      id
      fields {
      slug
      }
      frontmatter {
      title
      templateKey
      date(formatString: "MMMM DD, YYYY")
      }
      }
      }
      }
      }
      `


      But again, I got errors like this in below.



      ERROR  Failed to compile with 1 errors                                                                                                                                                                    11:23:51

      error in ./src/pages/index.js

      Module Error (from ./node_modules/eslint-loader/index.js):

      /Users/class/gatsby-netlify-blog/src/pages/index.js
      12:7 error 'content' is not defined no-undef
      13:7 error 'contentComponent' is not defined no-undef
      15:25 error 'contentComponent' is not defined no-undef
      20:20 error 'post' is not defined no-undef
      42:41 error 'content' is not defined no-undef

      ✖ 5 problems (5 errors, 0 warnings)


      @ ./.cache/sync-requires.js 19:50-112
      @ ./.cache/app.js
      @ multi ./node_modules/react-hot-loader/patch.js (webpack)-hot-middleware/client.js?path=http://localhost:8000/__webpack_hmr&reload=true&overlay=false ./.cache/app


      *I've already asked Gitter, issue in gatsby-starter-netlify-cms and Gatsby's Spectrum Chat but couldn't get the right path.










      share|improve this question













      is there any solution for enabling featured images in TOP/HOME page from the template https://github.com/netlify-templates/gatsby-starter-netlify-cms ?



      I meant to say I want the TOP/HOME page (src/pages.index.js) to display those images as well.



      I've tried to do that in 2 ways but it fails.



      Way 1:



      From config.yml like that in below.



        - name: "pages"
      label: "Pages"
      files:
      - file: "src/pages/index.md"
      label: "Homepage"
      name: "homepage"


      Then created a src/pages/index.md markdown file and move the js file src/pages/index.js to a directory src/template.
      Added that markdown file as an entry in my pages collection.
      But I got an Gatsby related error like this.



      Your site's "gatsby-node.js" created a page with a component that doesn't exist

      { path: '/',
      tags: null,
      component: '/Users/class/gatsby-netlify-blog/src/templates/null.js',
      context: { id: 'bb87bb60-04a6-51ea-8524-c7b2332a2fdb' } }
      error See the documentation for createPage https://www.gatsbyjs.org/docs/bound-action-creators/#createPage


      Way 2:



      Tried the same way in src/pages/index.js from the templae, gatsby-starter-netlify-cms wrote in blog-post.js, using Content component.



      import React from 'react'
      import PropTypes from 'prop-types'
      import { Link, graphql } from 'gatsby'
      import Layout from '../components/Layout'
      import Content, { HTMLContent } from '../components/Content'

      export default class IndexPage extends React.Component {
      render() {
      const { data } = this.props
      const { edges: posts } = data.allMarkdownRemark
      const FeaturedImg = {
      content,
      contentComponent,
      }
      const PostContent = contentComponent || Content

      return (
      <Layout>
      <FeaturedImg
      content={post.html}
      contentComponent={HTMLContent}
      />
      <section className="section">
      <div className="container">
      <div className="content">
      <h1 className="has-text-weight-bold is-size-2">Latest Stories</h1>
      </div>
      {posts
      .map(({ node: post }) => (
      <div
      className="content"
      style={{ border: '1px solid #eaecee', padding: '2em 4em' }}
      key={post.id}
      >
      <p>
      <Link className="has-text-primary" to={post.fields.slug}>
      {post.frontmatter.title}
      </Link>
      <span> &nbsp; </span>
      <small>{post.frontmatter.date}</small>
      </p>
      <PostContent content={content} />
      <p>
      {post.excerpt}
      <br />
      <br />
      <Link className="button is-small" to={post.fields.slug}>
      Keep Reading →
      </Link>
      </p>
      </div>
      ))}
      </div>
      </section>
      </Layout>
      )
      }
      }

      IndexPage.propTypes = {
      content: PropTypes.node.isRequired,
      contentComponent: PropTypes.func,
      data: PropTypes.shape({
      allMarkdownRemark: PropTypes.shape({
      edges: PropTypes.array,
      }),
      }),
      }

      export const pageQuery = graphql`
      query IndexQuery {
      allMarkdownRemark(
      sort: { order: DESC, fields: [frontmatter___date] },
      filter: { frontmatter: { templateKey: { eq: "blog-post" } }}
      ) {
      edges {
      node {
      excerpt(pruneLength: 400)
      id
      fields {
      slug
      }
      frontmatter {
      title
      templateKey
      date(formatString: "MMMM DD, YYYY")
      }
      }
      }
      }
      }
      `


      But again, I got errors like this in below.



      ERROR  Failed to compile with 1 errors                                                                                                                                                                    11:23:51

      error in ./src/pages/index.js

      Module Error (from ./node_modules/eslint-loader/index.js):

      /Users/class/gatsby-netlify-blog/src/pages/index.js
      12:7 error 'content' is not defined no-undef
      13:7 error 'contentComponent' is not defined no-undef
      15:25 error 'contentComponent' is not defined no-undef
      20:20 error 'post' is not defined no-undef
      42:41 error 'content' is not defined no-undef

      ✖ 5 problems (5 errors, 0 warnings)


      @ ./.cache/sync-requires.js 19:50-112
      @ ./.cache/app.js
      @ multi ./node_modules/react-hot-loader/patch.js (webpack)-hot-middleware/client.js?path=http://localhost:8000/__webpack_hmr&reload=true&overlay=false ./.cache/app


      *I've already asked Gitter, issue in gatsby-starter-netlify-cms and Gatsby's Spectrum Chat but couldn't get the right path.







      reactjs gatsby netlify netlify-cms jamstack






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 '18 at 21:08









      shabibishabibi

      184




      184
























          1 Answer
          1






          active

          oldest

          votes


















          0














          For #1 your markdown file needs a template key to tell gatsby where to find the js file to use to render your markdown.



          For #2 those variables are not defined in the scope they are being used, your linter is catching it and they would fail at runtime. Should those be imported from somewhere?






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270131%2fgatsby-netlify-cms-any-ways-to-enable-featured-images-for-each-entry-in-src-p%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            For #1 your markdown file needs a template key to tell gatsby where to find the js file to use to render your markdown.



            For #2 those variables are not defined in the scope they are being used, your linter is catching it and they would fail at runtime. Should those be imported from somewhere?






            share|improve this answer


























              0














              For #1 your markdown file needs a template key to tell gatsby where to find the js file to use to render your markdown.



              For #2 those variables are not defined in the scope they are being used, your linter is catching it and they would fail at runtime. Should those be imported from somewhere?






              share|improve this answer
























                0












                0








                0






                For #1 your markdown file needs a template key to tell gatsby where to find the js file to use to render your markdown.



                For #2 those variables are not defined in the scope they are being used, your linter is catching it and they would fail at runtime. Should those be imported from somewhere?






                share|improve this answer












                For #1 your markdown file needs a template key to tell gatsby where to find the js file to use to render your markdown.



                For #2 those variables are not defined in the scope they are being used, your linter is catching it and they would fail at runtime. Should those be imported from somewhere?







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 '18 at 16:44









                Peter LazzarinoPeter Lazzarino

                22125




                22125






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270131%2fgatsby-netlify-cms-any-ways-to-enable-featured-images-for-each-entry-in-src-p%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Lugert, Oklahoma