How to get the "siteMetadata" from gatsby.config on Netlify CMS

Hello,

I am currently trying to build a “Settings” collection, where I would like to have an item “Site Settings”. Here I want to show some common fields like, “site title”, “site description”, “email”, “facebook”, “instagram”, etc.

I have this info on the siteMetadata: {} from the gatsby.config file.
Some one knows how I can get this data from the file and show it on the Netlify CMS? How do I have to build the my /admin/config.yml file?

  - name: "settings"
    label: "Settings"
    delete: false # Prevent users from deleting documents in this collection
    editor:
      preview: false
    files:
      - file: "content/settings/global.yml"
        label: "Global Settings"
        name: "global-settings"

I have to change the file: “content/settings/global.yml”, but don’t know if it is possible.

Thank you

Hi @ositaka, how is the global.yml file structured? Can you give an example of its content?
You should be able to define fields matching its content, then use GraphQL in Gatsby to query the data.

Hi @erez, I would like to get the info from the gatsby.config file, like:

module.exports = {
	siteMetadata: {
		title: 'David Alioth',
		description: 'Photography',
		email: 'info@davidalioth.com',
		facebook: '#',
		instagram: 'https://www.instagram.com/the_davidalioth/'
	},

But I see now, from the Docs, we can just get info from files or folders, not really from the gatsby.config. I will create a file called global.yml.

Thank you for the reply, all the best!

Thanks for sharing the solution you decided on, @ositaka. If there are other questions we’re here and we’ll do our best to answer.

Thanks for sharing, there is actually another way to do it. You could extract that part into a separate JS/JSON file and use CMS manual initialization:

Then you should be able to import that data both to Gatsby config and the CMS config.

Manual init is also supported by the Gatsby plugin gatsby-plugin-netlify-cms | Gatsby