From ad8e1148ade2fc126e802ba9de4e473673dff65e Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Fri, 18 Oct 2024 14:10:25 +0530 Subject: [PATCH] path normalise --- scripts/build-post-list.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/build-post-list.js b/scripts/build-post-list.js index 84fe1caebec1..f0383090550e 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 { resolve, basename } = require('path') +const { resolve, basename, join, sep } = require('path') const frontMatter = require('gray-matter') const toc = require('markdown-toc') const { slugify } = require('markdown-toc/lib/utils') @@ -52,10 +52,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, sep).replace(/\//g, sep)}`), '').replace(/\\/g, '/'); // Normalize slugs to use `/` 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 @@ -94,7 +95,7 @@ function walkDirectories(directories, result, basePath, sectionWeight = 0, secti details.sectionId = sectionId details.rootSectionId = rootSectionId details.id = fileName - details.isIndex = fileName.endsWith('/index.mdx') + details.isIndex = fileName.endsWith(join(sep, 'index.mdx')) // Platform-independent index check details.slug = details.isIndex ? sectionSlug : slug.replace(/\.mdx$/, '') if (details.slug.includes('/reference/specification/') && !details.title) { const fileBaseName = basename(data.slug) // ex. v2.0.0 | v2.1.0-next-spec.1 @@ -113,7 +114,6 @@ function walkDirectories(directories, result, basePath, sectionWeight = 0, secti if (fileBaseName.includes('next-spec') || fileBaseName.includes('next-major-spec')) { details.isPrerelease = true - // this need to be separate because the `-` in "Pre-release" will get removed by `capitalize()` function details.title += " (Pre-release)" } if (fileBaseName.includes('explorer')) {