diff --git a/scripts/build-post-list.js b/scripts/build-post-list.js index f0383090550e..3159c6e32a6b 100644 --- a/scripts/build-post-list.js +++ b/scripts/build-post-list.js @@ -1,11 +1,12 @@ const { readdirSync, statSync, existsSync, readFileSync, writeFileSync } = require('fs') -const { resolve, basename, join, sep } = require('path') +const { basename, join, sep } = require('path') const frontMatter = require('gray-matter') const toc = require('markdown-toc') const { slugify } = require('markdown-toc/lib/utils') const readingTime = require('reading-time') const { markdownToTxt } = require('markdown-to-txt') const { buildNavTree, addDocButtons } = require('./build-docs') +const path = require('path'); let specWeight = 100 const result = { @@ -54,7 +55,7 @@ function walkDirectories(directories, result, basePath, sectionWeight = 0, secti let details 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 slug = fileName.replace(new RegExp(`^${basePath.replace(/\\/g, sep).replace(/\//g, sep)}`), '').split(sep).join('/'); // Normalize slugs using posix-style paths const slugElements = slug.split('/'); if (isDirectory(fileName)) { @@ -96,7 +97,7 @@ function walkDirectories(directories, result, basePath, sectionWeight = 0, secti details.rootSectionId = rootSectionId details.id = fileName details.isIndex = fileName.endsWith(join(sep, 'index.mdx')) // Platform-independent index check - details.slug = details.isIndex ? sectionSlug : slug.replace(/\.mdx$/, '') + details.slug = details.isIndex ? sectionSlug : path.posix.join(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 const fileName = fileBaseName.split('-')[0] // v2.0.0 | v2.1.0