From cce6e08770e53493b9c3a62316fca7fec2098b29 Mon Sep 17 00:00:00 2001 From: Stephan Ringel Date: Fri, 15 Jan 2021 02:48:21 +0100 Subject: [PATCH] fix: No md files found on Windows (closes #7) (#8) --- gatsby-node.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index 5e4fcf3..4ac0fc9 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -30,6 +30,7 @@ exports.createSchemaCustomization = ({ actions }) => { } exports.sourceNodes = async ({ actions, createNodeId, createContentDigest }, options = {}) => { + const cwd = process.cwd() const root = options.root ? options.root : '' const { paths: pages = ['src/pages'], extensions = ['md', 'mdx'] } = options.pages ? options.pages : {} const { token, owner, name, branch = 'main', default_branch = 'main' } = options.repo ? options.repo : {} @@ -38,7 +39,9 @@ exports.sourceNodes = async ({ actions, createNodeId, createContentDigest }, opt console.warn('To get Github Contributors, a Github token is required (GITHUB_TOKEN environment variable)') } - const paths = await globby(pages.map(page => path.resolve(process.cwd(), page)), { + // Support Windows + const regExp = /\\/g + const paths = await globby(pages.map(page => path.resolve(cwd, page).replace(regExp, '//')), { expandDirectories: { extensions } @@ -59,7 +62,7 @@ exports.sourceNodes = async ({ actions, createNodeId, createContentDigest }, opt }) for (const _path of paths) { - let githubPath = path.join(root, _path.replace(process.cwd(), '')) + let githubPath = path.join(root, _path.replace(cwd, '')) if (githubPath.charAt(0) === path.sep) githubPath = githubPath.substr(1) let contributors = []