Created
August 14, 2020 11:53
-
-
Save isNan909/7c80c2dba74518907a5b2b944018a57a to your computer and use it in GitHub Desktop.
File inside pages to loop over the posts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react" | |
| import { Link, graphql } from "gatsby" | |
| import Layout from "../components/layout" | |
| import SEO from "../components/seo" | |
| const SitePosts = ({ data }) => { | |
| const ourPosts = data.allContentfulSitePost.edges | |
| // console.log(ourPosts); | |
| return ( | |
| <Layout> | |
| <SEO title="Our Posts" /> | |
| <h1>{"Welcome to our Blog"}</h1> | |
| <div> | |
| {ourPosts.map(({ node: post }) => ( | |
| <div key={post.id}> | |
| <Link to={`/siteposts/${post.slug}`}> | |
| {post.heading} | |
| </Link> | |
| </div> | |
| ))} | |
| <span /> | |
| <Link to="/">Back to the homepage</Link> | |
| </div> | |
| </Layout> | |
| ) | |
| } | |
| export default SitePosts | |
| export const query = graphql` | |
| query SitePostsPageQuery { | |
| allContentfulSitePost(limit: 1000) { | |
| edges { | |
| node { | |
| id | |
| slug | |
| heading | |
| description { | |
| content { | |
| content { | |
| value | |
| } | |
| } | |
| } | |
| subheading | |
| image { | |
| file { | |
| url | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| ` |
Author
Looking at the error you have sent me, there is no description value set. Please check our GraphQL queries for especially
description {
content {
content {
value
}
}
}
Do you have your description printed out in console.log(ourPosts) ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cant fetch the description file in the graphQL query , error thrown - stating content not available within description field