如何从 Gatsby 的远程 git 存储库检索 markdown?

Lak*_*n S 5 git gatsby

我正在开发的 Gatsby 网站在该content/posts目录中包含其博客文章。我曾经gatsby-source-filesystem访问这些文件并将它们变成页面。

//gatsby-config.js
{
  resolve: `gatsby-source-filesystem`,
  options: {
    path: `${post_dir}/content/posts/`,
    name: "posts"
  }
},
Run Code Online (Sandbox Code Playgroud)

这是我的 gatsby-node.js。

//gatsby-node.js
exports.onCreateNode = ({ node, getNode, boundActionCreators }) => {
  const { createNodeField } = boundActionCreators;
  if (node.internal.type === `MarkdownRemark`) {
    const slug = createFilePath({ node, getNode, basePath: `pages` });

    const separtorIndex = ~slug.indexOf("--") ? slug.indexOf("--") : 0;
    const shortSlugStart = separtorIndex ? separtorIndex + 2 : 0;

    createNodeField({
      node,
      name: `slug`,
      value: `${separtorIndex ? "/" : ""}${slug.substring(shortSlugStart)}`
    });

    createNodeField({
      node,
      name: `prefix`,
      value: separtorIndex ? slug.substring(1, separtorIndex) : ""
    });
  }
};
Run Code Online (Sandbox Code Playgroud)

我在这个项目中使用gatsby-starter-personal-blog starter。

现在我想将该content/posts目录移动到一个单独的存储库中,我可以将其公开,以便其他人可以编辑它们并发送拉取请求。

根据gatsby-source-filesystem文档,我认为 createRemoteFileNode可以使用方法来实现这一点。我尝试使用它,但需要将几个参数传递到函数中才能使用createRemoteFileNode. 我正在努力在我的上下文中使用它。我很新,Gatsby有人能帮我解决这个问题吗?先感谢您。

cyb*_*bat 1

我刚刚在gatsby-source-git上取得了巨大的成功。尝试过gatsby-source-github但在它工作时我遇到了一些晦涩的错误。如果我没记错的话,后者将从私人仓库中提取。