Skip to content

Commit

Permalink
Merge pull request #44 from timlrx/fix/windows
Browse files Browse the repository at this point in the history
fix: windows compatible file path
  • Loading branch information
timlrx authored May 11, 2021
2 parents 5e36f32 + 3c2720a commit a7ad8ad
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/mdx.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const tokenClassNames = {
export function getFiles(type) {
const prefixPaths = path.join(root, 'data', type)
const files = getAllFilesRecursively(prefixPaths)
// Only want to return blog/path and ignore root
return files.map((file) => file.slice(prefixPaths.length + 1))
// Only want to return blog/path and ignore root, replace is needed to work on Windows
return files.map((file) => file.slice(prefixPaths.length + 1).replace(/\\/g, '/'))
}

export function formatSlug(slug) {
Expand Down Expand Up @@ -97,7 +97,8 @@ export async function getAllFilesFrontMatter(folder) {
const allFrontMatter = []

files.forEach((file) => {
const fileName = file.slice(prefixPaths.length + 1)
// Replace is needed to work on Windows
const fileName = file.slice(prefixPaths.length + 1).replace(/\\/g, '/')
const source = fs.readFileSync(file, 'utf8')
const { data } = matter(source)
if (data.draft !== true) {
Expand Down

1 comment on commit a7ad8ad

@vercel
Copy link

@vercel vercel bot commented on a7ad8ad May 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.