Skip to content

Commit a7ad8ad

Browse files
authored
Merge pull request #44 from timlrx/fix/windows
fix: windows compatible file path
2 parents 5e36f32 + 3c2720a commit a7ad8ad

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/mdx.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ const tokenClassNames = {
2727
export function getFiles(type) {
2828
const prefixPaths = path.join(root, 'data', type)
2929
const files = getAllFilesRecursively(prefixPaths)
30-
// Only want to return blog/path and ignore root
31-
return files.map((file) => file.slice(prefixPaths.length + 1))
30+
// Only want to return blog/path and ignore root, replace is needed to work on Windows
31+
return files.map((file) => file.slice(prefixPaths.length + 1).replace(/\\/g, '/'))
3232
}
3333

3434
export function formatSlug(slug) {
@@ -97,7 +97,8 @@ export async function getAllFilesFrontMatter(folder) {
9797
const allFrontMatter = []
9898

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

0 commit comments

Comments
 (0)