I'm using Netlify CMS within a Gatsby Theme. Here is an example of my project structure:
root/
themes/
gatsby-theme-example/
pages/
index.js
static/
admin/
config.yml
gatsby-config.js
package.json
sites/
example-theme-site/
data/
content.md
gatsby-config.js
package.json
package.json
More info:
gatsby-theme-exampleuses gatsby-plugin-netlify-cms, with theconfig.ymlfile located atroot/themes/gatsby-theme-example/static/admin/config.ymlgatsby-theme-exampleandexample-theme-siteare connected via yarn workspaces, however I intend to publishgatsby-theme-exampleto npm once it's fully developed so users can install it as a package.example-theme-siteis only used for development testing purposes.
This means that:
- Running
yarn workspace example-theme-site developwill rungatsby developforexample-theme-site - Users can then visit
http://localhost:8000/adminand access Netlify CMS. Once logged in, this will load Netlify CMS using the config file located withinroot/themes/gatsby-theme-example/static/admin/config.yml
The next step I want to occur after this is:
- Users add content to Netlify CMS
- When saved/published, this new data is saved under the
root/sites/example-theme-site/datadirectory.
This is the issue I'm having difficulty with, as the config file is located in gatsby-theme-example however I want the data to save to example-theme-site. I'm not sure how to make the path relative to the root directory without hard-coding it in.
I see that I can specify the location to save the data under file or folder in the config.yml, however since config.yml is a .yml file, I don't see how I can use something like __dirname to specify the correct directory. The only option I can see would be to hard-code in the file path (e.g. file: "../../sites/example-theme-site/data/content.md") while in development, then change it so it's relative to node_modules just before I publish the theme to npm.
Is there any other more appropriate solution here?