Merge pull request #44 from timlrx/fix/windows

fix: windows compatible file path
This commit is contained in:
Timothy 2021-05-11 22:50:00 +08:00 committed by GitHub
commit a7ad8ad2c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) {
@ -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) {