gatsby-starter-ghost
gatsby-starter-ghost copied to clipboard
Global site/config values
Problem description
Throughout the codebase we're using values that either come from the starter specific siteConfig.js, or - via Content API - the Ghost settings (like here for example, where we run a StaticQuery in order to use both sources).
Ideally those would be merged together in one site or config, so it's easily accessible by other components/modules.
The biggest pain point here is, that we need the values from the Ghost settings already in the gatsby-config.js! Because of the unavailability of the Ghost settings in this file, we had to create a workaround and adjust the gatsby-offline-manifest plugin (👉 see PR here https://github.com/TryGhost/gatsby-starter-ghost/pull/15)
This is due to Gatsby's specific lifecycle that allows to run GraphQL queries only after the first schema creation. This means at the point when Gatsby is processing the config file, it simply doesn't know about Ghost settings yet.
Proposal
Create a script, that runs before any Gatsby activities and fetches the data from the settings endpoint via Content API (without gatsby-source-ghost usage) and make those merged values available in gatsby-config (and ofc any other occurrences). This can be a .json file for example that get's replaced with every build.
Todos
- [ ] Finalise idea for this solution. Maybe there are better ways of doing that, then the proposed way?
- [ ] Implement solution
- [ ] Replace all
StaticQueryoccurrences forallGhostSettingsand use new solution - [ ] Revert https://github.com/TryGhost/gatsby-starter-ghost/pull/15 and use default again
Is this enhancement still of interest or did you find a better approach in the meantime?