-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to filter siteMetadata? #13989
Comments
@karanrajpal14 i've been testing this out all afternoon and i can confirm that the issue is present. Now upon some digging i'm inclined to believe that the issue you're experiencing is related to this and the subsequent feature request i might be wrong about it but it seems that this is the case. Now if you can elaborate on this matter, do you really need the two sources of truth? Do you really need to replicate both structures in both places? Based on the information at hand you could probably achieve what you want to achieve with only the json data in the file. But again this is based on the information you supplied, like i said if you can share more context we can probably offer a simpler solution for what you're trying to achieve. |
Thanks for the response @jonniebigodes. Okay I'll provide some context first. As you can tell, I'm trying to have my site's navigation links as a JSON just to make it easier to change. I then use this JSON in my header and footer components. My initial attempt led me to creating a separate JSON file and then use the Additionally, I filter the nav links in and use it in my main page as a prefix to the slugs for navigation. It might be a tad overkill but it makes things a bit easier for me to change, if I need to. Is there any other way to filter the nav array within the metadata? I could just go on and use I do not need two sources of truth. I'm trying to migrate from the |
@karanrajpal14 if you don't mind a third option. You can import the JSON file directly to where you want and it will be processed by Gatsby and the underlying bundler webpack. With that you eliminate the plugin in question, solely based on the fact that you're using one file and also remove the extra content in |
Hey @jonniebigodes, thank you for the sample. That does work for my current use case and I'll probably do it this way as I can shave off the dependency at least. I still am curious though, filtering the siteMetadata should work, correct? Is this a bug? Or is the current behaviour working as intended? |
@karanrajpal14 to the best of my knowledge, technically not a bug, but a feature that is still not implemented, as you can see in the links i posted in my earlier comment. No need to thank, glad that i was able to offer you a alternative and see that the work you're doing will continue to progress. |
If that's the case then maybe @KyleAMathews or @jlengstorf can look into this and change the label accordingly as this a (low-priority) feature that I'd like to see, eventually. Thank you once again, @jonniebigodes! |
@karanrajpal14 like i said before, no need to thank, just glad i was able to help you out |
To clarify, One way to solve this problem is to filter in your JS: const nav = data.site.siteMetadata.nav;
nav.filter(navItem => /* whatever filter you need */); Sub-filtering on field nodes probably won't get added as a default feature, but you can add this on your own using schema customization APIs. Hope that helps! I'm going to mark this as closed, but please hit us up if you have additional questions! |
Summary
I seem to be unable to filter siteMetadata nodes. I've got a separate JSON file that has the content but I'm able to use filters on the allNavJson query.
Relevant information
Here's the JSON file:
src/content/nav.json
The same JSON is present in
gatsby-config.js
as well like so:Here is the query I'm trying to run
And here is the output of the query
As you can see, the filter works just fine for the allNavJson query but doesn't work at all for the allSite query. Am I doing something wrong here? Any help would be appreciated. Thank you!
Environment (if relevant)
File contents (if changed)
gatsby-config.js
:package.json
: N/Agatsby-node.js
: N/Agatsby-browser.js
: N/Agatsby-ssr.js
: N/AThe text was updated successfully, but these errors were encountered: