Closed ragunaru closed 5 years ago
Hi Ragnar
With this plugin I decided it was neater to only deal with the files and paths themselves, not their contents (so I could avoid crossing streams with complex plugins like gatsby-transformer-remark
).
If you want to do a query on the frontmatter it's best to query the MarkdownRemark
nodes (using allMarkdownRemark
)
Then if you want to use properties of the Templated
node (e.g. slug) remember that because the Templated
node is the parent of the MarkdownRemark
node you can crawl up the nodes and get it that way instead (rather than querying the Templated
and going down through childMarkdownRemark
).
The following GraphQL query achieves that:
{
allMarkdownRemark(filter: { frontmatter: { title: { eq: "My Page" } } }){
edges {
node {
id
frontmatter {
title
}
parent {
id
... on Templated {
slug
absolutePath
}
}
}
}
}
}
That's fantastic, @dhoulb, thanks so much! 🙏
Hi there Dave and firstly, thanks so much for creating this plugin – it's fantastic.
There is however a small feature request that I have. I would like to filter on the properties of frontmatter, which are available on
allMarkdownRemark
but notallTemplated
. I could easily queryallMarkdownRemark
but then I lose theslug
field which is onallTemplated
. This is basically so that I could filter my content based on a specific property.As an example: I have content in two categories and I want to query the different categories in different template files. I am very new to graphql and I don't really see a way of doing that with
allTempalted
right now. I have tried for 2 hours and haven't found a way yet.Any help super appreciated!
Thanks, Ragnar