-
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
Accessing siteMetadata (gatsby-config.js) #1781
Comments
Hi @kbariotis – just ran into this myself and came here to find an answer. 😃 After poking around I've realized that it can be queried like this:
A corresponding
A little more info here: |
Thank you @danoc ! Is there a working example? |
Search the example sites. We query siteMetadata a number of times. |
I have searched the example sites and don't understand how siteMetadata is used. For example, in the starter site it looks to me like src/layouts/index.js has a hardcoded title. I am working around this like so:
That feels like it's not what is intended. I also read the migration guide and attempted to export a query as a constant. I get errors that props is not defined. |
What is the benefit of using graphql for this? I'm also importing like @luketeaford as it's clear and simple, though I'm not sure on the consequences of doing so. |
If you want to import a metadata module, I'd suggest using a different file from gatsby-config.js e.g. |
Got to say I find the docs for this very confusing - in the tutorial you hard-code the title direct from the metadata, but what is really needed is a way to define different metadata for different pages. Last time I checked, using the same title and description across multiple pages is an SEO disaster. Obviously Helmet provides a nice solution for updating meta on the fly but it would make sense to me to offer a mechanism for defining all meta in a separate metadata.json or similar. At the moment I'm adding a It seems to me that something that is as fundamental a metadata would benefit from having a simple api included. This kind of standardisation makes moving between projects much easier. Rather than the site metadata query resolving to an object taken from within
|
Closing out older issues — please open a new issue if you need more help! |
I have added a property
siteUrl
ingatsby-config.js
and I am trying to access it in two places.layouts/index.js
: where I need to set OG tags, etc..templates/blog-post.js
: where I need to set share urlsWhat's the preferred way to access it in these places?
Thank you! Great work btw! 😎
The text was updated successfully, but these errors were encountered: