Gatsby.js – 导出 sanity.io 数据(可能到 netlify-cms 中的 Markdown 文件)

huangapple go评论90阅读模式
英文:

Gatsby.js - Export sanity.io data ( And maybe to netlify-cms in markdown files)

问题

目标

我想要迁移(或许是转换)旧网站上的数据页面到新网站上。

大纲

  • 我打算重新设计一个现有的 Gatsby 网站,为客户进行品牌改造。
  • 客户已经提供了 Sanity-Studio 和 Gatsby 的源文件。
  • 我已经成功在本地构建了 Sanity-Studio 和 Gatsby 网站。

问题

  • 根据我了解,实际数据仍托管在之前开发者的 sanity.io 帐户上。
  • 我无法访问这些数据,即使在本地也不行。
  • 我无法在本地的 Sanity-Studio 中添加新帐户,除非使用原始帐户登录。
  • 我更倾向于自动化此过程,因为总共有大约 100 个页面。

问题

第一部分

  • 是否有方法可以接收/访问这些数据,并能够将其迁移到我的新(不同的)Gatsby网站上?

第二部分

  • 我计划不使用 Sanity.io,而是使用 Gatsby.js + Netlify-CMS,我是否可以将 Sanity.io 上的所有数据转换为 Markdown 文件,以便可以在 Netlify-CMS 中使用?
英文:

The goal

I want to migrate (maybe convert) the pages data from the old site to the new site.

The outline

  • I'm going to do a rebrand on an existing Gatsby website for a client.
  • The client has provided me with the source files for Sanity-Studio & Gatsby
  • I was able to locally build both the Sanity-Studio & the Gatsby site

The problem

  • The actual data, from what I understand, is still hosted on the sanity.io account of the previous developer.
  • I cannot access this data, not even locally.
  • I cannot add an new account to the local sanity-studio without logging in with the original account.
  • I prefer to do this automated, since there are about 100 pages in total.

The question

Part 1

  • Is there a way to receive/access this data and to be able to migrate (or export / import) it to my new (different) Gatsby site?

Part 2

  • I was planning of leaving Sanity.io out of it and use Gatsby.js + Netlify-CMS -> Can I convert all the data from Sanity.io to Markdown files, so that I can use it with Netlify-CMS?

答案1

得分: 2

首先,请随时在我们的开发者社区hello@sanity.io上与我们联系,看看我们是否能够解决有关获取客户内容并让您继续使用当前技术栈进行构建的问题。

我仍然会在这里尝试为您提供一些答案。

第一部分

您可以在导出端点获取数据集的公共部分的完整导出:curl https://<projectId>.api.sanity.io/v1/data/export/<dataset>/ > backup.ndjson。资产文档将包含要单独下载的资产二进制文件的URL。查看我们在导出模块中如何处理它。我注意到如果该模块允许您在不需要令牌的情况下导出公共数据将会很有帮助。

另一种方法是使用Gatsby,查询所需的数据,并从页面模板中以您需要的方式输出为markdown/JSON结构。

第二部分

如果您想将Sanity中的数据转换为Markdown,这是完全可能的。查看Codesandbox上的此演示以了解如何操作。

英文:

First of all, feel free to contact us in our developer community or on hello@sanity.io to see if we can figure something out when it comes to getting to your client’s content and letting you continue building with the current stack without hitches.

I'll still try to give you some answers here.

Part 1

You can get a full export of the public part of the dataset at the export endpoint: curl https://&lt;projectId&gt;.api.sanity.io/v1/data/export/&lt;dataset&gt;/ &gt; backup.ndjson. The asset documents will contain the URLs to the asset binaries that you have to download separately. Check out how we deal with it in our export-module. I note that it would be helpful if the module would let you export public data without requiring a token.

Another approach is to use Gatsby, query the data you need and output it as markdown/JSON structured in the way you need it from a page template.

Part 2

If you want to convert data from Sanity into Markdown that's totally possible. Check out this demo on Codesandbox for how to go about it.

huangapple
  • 本文由 发表于 2020年1月3日 17:57:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576452.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定