【问题标题】:Netlify CMS - save data to project root (e.g. `__dirname`)Netlify CMS - 将数据保存到项目根目录(例如 `__dirname`)
【发布时间】:2019-10-28 07:00:22
【问题描述】:

我在 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 develop 将为example-theme-site 运行gatsby develop
  2. 然后用户可以访问http://localhost:8000/admin 并访问 Netlify CMS。登录后,这将使用位于root/themes/gatsby-theme-example/static/admin/config.yml 中的配置文件加载 Netlify CMS

在此之后我想要进行的下一步是:

  • 用户向 Netlify CMS 添加内容
  • 保存/发布后,此新数据将保存在root/sites/example-theme-site/data 目录下。

这是我遇到困难的问题,因为配置文件位于gatsby-theme-example,但我希望将数据保存到example-theme-site。我不确定如何在不对其进行硬编码的情况下使路径相对于根目录。

我看到我可以指定保存数据的位置under file or folder in the config.yml,但是由于config.yml 是一个.yml 文件,我不知道如何使用__dirname 之类的东西来指定正确的目录。我能看到的唯一选择是在开发过程中对文件路径(例如file: "../../sites/example-theme-site/data/content.md")进行硬编码,然后在我将主题发布到 npm 之前将其更改为相对于node_modules

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

【问题讨论】:

  • 过去一周我一直在处理这个问题。你曾经能够解决这个问题吗?我注意到这是一年多前发布的。

标签: yaml gatsby netlify-cms


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-29
    • 2015-08-31
    • 2017-09-14
    相关资源
    最近更新 更多