2

我在 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-cmsconfig.yml文件位于root/themes/gatsby-theme-example/static/admin/config.yml
  • gatsby-theme-exampleexample-theme-site通过yarn workspaces连接,但是我打算在gatsby-theme-example它完全开发后发布到 npm,以便用户可以将其作为包安装。example-theme-site仅用于开发测试目的。

这意味着:

  1. 运行yarn workspace example-theme-site developgatsby develop运行example-theme-site
  2. 然后用户可以访问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. 我不确定如何在不对其进行硬编码的情况下使路径相对于根目录。

我看到我可以指定在. filefolderconfig.yml我能看到的唯一选择是在开发时在文件路径(例如)中硬编码,然后更改它,使其与我将主题发布到 npm 之前相关。config.yml__dirnamefile: "../../sites/example-theme-site/data/content.md"node_modules

这里还有其他更合适的解决方案吗?

4

1 回答 1

0

配置文件在您的仓库中的位置无关紧要 - 配置文件在浏览器中处理。配置中的所有路径始终相对于 repo 根目录。

于 2019-11-04T16:57:51.733 回答