Skip to content

Instantly share code, notes, and snippets.

@isNan909
Created August 14, 2020 11:53
Show Gist options
  • Select an option

  • Save isNan909/7c80c2dba74518907a5b2b944018a57a to your computer and use it in GitHub Desktop.

Select an option

Save isNan909/7c80c2dba74518907a5b2b944018a57a to your computer and use it in GitHub Desktop.
File inside pages to loop over the posts
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
}
}
}
}
}
}
`
@karthik2872
Copy link

Cant fetch the description file in the graphQL query , error thrown - stating content not available within description field

@isNan909
Copy link
Author

isNan909 commented Jul 9, 2021

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