Skip to content

Commit

Permalink
path normalise
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Oct 18, 2024
1 parent 2eedba1 commit ad8e114
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions scripts/build-post-list.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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')) {
Expand Down

0 comments on commit ad8e114

Please sign in to comment.