I'm a newbie web developer working with Gatsby, React, GraphQL and Javascript. I'm working on a simple blog site in which I have some markdown posts whose frontmatter dynamically populate a list of blogposts on a page. I've managed to get this working so far but I wondered how one can work with data obtained from a graphQL query. I'd like to display just the day and month of the post in a stylised way as shown below:
I'm using the following code to pull through the date of the markdown posts:
const data = useStaticQuery(graphql`
query{
allMarkdownRemark{
edges{
node{
frontmatter{
title
date
featuredImage{
childImageSharp{
fluid{
...GatsbyImageSharpFluid
}
}
}
}
fields{
slug
}
}
}
}
}
`)
return(
<div id="blog">
<div class="blog-pad"></div>
<div class="blog-posts">
{data.allMarkdownRemark.edges.map((edge) =>(
<div class="blog-post">
<Img fluid={edge.node.frontmatter.featuredImage.childImageSharp.fluid} />
<div class="meta">
<h3>
{edge.node.frontmatter.date}
</h3>
<div class="title-date">
<h3>
<a href={"/blog/" + edge.node.fields.slug}>{edge.node.frontmatter.title}</a>
</h3>
<p>{edge.node.frontmatter.date}</p>
<p>Author</p>
</div>
</div>
</div>
))}
</div>
<div class="blog-pad"></div>
</div>
)
With a bit of styling added this results in:
How can I extract just the day and month from this {edge.node.frontmatter.date}? I thought to write a javascript function to do some string formatting on it however I'm not quite sure how to go about writing the function nor how it fits into the context of jsx and graphQL. Would this query called const data get passed as a parameter to the function which would then return a string? return <p>3 Dec</p>

