diff --git a/scripts/build-post-list.js b/scripts/build-post-list.js index e9a95a6c448..0f54ecea005 100644 --- a/scripts/build-post-list.js +++ b/scripts/build-post-list.js @@ -1,5 +1,5 @@ const { readdirSync, statSync, existsSync, readFileSync, writeFileSync } = require('fs') -const { basename } = require('path') +const { basename, join } = require('path') const frontMatter = require('gray-matter') const toc = require('markdown-toc') const { slugify } = require('markdown-toc/lib/utils') @@ -60,10 +60,11 @@ function walkDirectories(directories, result, basePath, sectionWeight = 0, secti for (let file of files) { let details - const fileName = [directory, file].join('/') - const fileNameWithSection = [fileName, '_section.mdx'].join('/') - const slug = fileName.replace(new RegExp(`^${basePath}`), '') + const fileName = join(directory, file); + const fileNameWithSection = join(fileName, '_section.mdx'); + const slug = fileName.replace(new RegExp(`^${basePath}`), '').replace(/\\/g, '/'); const slugElements = slug.split('/'); + if (isDirectory(fileName)) { if (existsSync(fileNameWithSection)) { // Passing a second argument to frontMatter disables cache. See https://github.com/asyncapi/website/issues/1057 @@ -161,7 +162,7 @@ function slugifyToC(str) { } function isDirectory(dir) { - return statSync(dir).isDirectory() + return statSync(dir).isDirectory() } function capitalize(text) {