我在 Gatsby 主题中使用 Netlify CMS。这是我的项目结构的示例:
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
更多信息:
gatsby-theme-example
使用gatsby-plugin-netlify-cms,config.yml
文件位于root/themes/gatsby-theme-example/static/admin/config.yml
gatsby-theme-example
并example-theme-site
通过yarn workspaces连接,但是我打算在gatsby-theme-example
它完全开发后发布到 npm,以便用户可以将其作为包安装。example-theme-site
仅用于开发测试目的。
这意味着:
- 运行
yarn workspace example-theme-site develop
将gatsby develop
运行example-theme-site
- 然后用户可以访问
http://localhost:8000/admin
和访问 Netlify CMS。登录后,这将使用位于其中的配置文件加载 Netlify CMSroot/themes/gatsby-theme-example/static/admin/config.yml
我想在此之后发生的下一步是:
- 用户向 Netlify CMS 添加内容
- 保存/发布时,此新数据将保存在
root/sites/example-theme-site/data
目录下。
这是我遇到困难的问题,因为配置文件位于gatsby-theme-example
但我希望数据保存到example-theme-site
. 我不确定如何在不对其进行硬编码的情况下使路径相对于根目录。
我看到我可以指定在. file
folder
config.yml
我能看到的唯一选择是在开发时在文件路径(例如)中硬编码,然后更改它,使其与我将主题发布到 npm 之前相关。config.yml
__dirname
file: "../../sites/example-theme-site/data/content.md"
node_modules
这里还有其他更合适的解决方案吗?