Skip to content

Commit 0c1e079

Browse files
committed
fix: attempt to use platform-specific separator
1 parent 6cf4383 commit 0c1e079

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

next.constants.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ export const DEFAULT_LOCALE_CODE = defaultLocale.code;
9191
*/
9292
export const LEGACY_JAVASCRIPT_FILE = `${BASE_PATH}/static/js/legacyMain.js`;
9393

94+
/**
95+
* This is the current Node.js Working directory. We usually use it to resolve pathnames
96+
* relative to the content of the Node.js Website.
97+
*/
98+
export const CURRENT_WORKING_DIRECTORY = process.cwd();
99+
94100
/**
95101
* This is a list of all static routes or pages from the Website that we do not
96102
* want to allow to be statically built on our Static Export Build.

next.dynamic.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ import rehypeSlug from 'rehype-slug';
1010
import { serialize } from 'next-mdx-remote/serialize';
1111
import { availableLocales } from './next.locales.mjs';
1212
import { getMarkdownFiles } from './next.helpers.mjs';
13-
import { DEFAULT_LOCALE_CODE, MD_EXTENSION_REGEX } from './next.constants.mjs';
13+
import {
14+
DEFAULT_LOCALE_CODE,
15+
MD_EXTENSION_REGEX,
16+
CURRENT_WORKING_DIRECTORY,
17+
} from './next.constants.mjs';
1418

1519
// allows us to run a glob to get markdown files based on a language folder
1620
const getPathsByLanguage = async (locale = DEFAULT_LOCALE_CODE, ignored = []) =>
17-
getMarkdownFiles(process.cwd(), `pages/${locale}`, ignored);
21+
getMarkdownFiles(CURRENT_WORKING_DIRECTORY, `pages/${locale}`, ignored);
1822

1923
/**
2024
* This method is responsible for generating a Collection of all available paths that
@@ -41,6 +45,7 @@ const getAllPaths = async () => {
4145
sourcePages.map(filename => {
4246
// remove the index.md(x) suffix from a pathname
4347
let pathname = filename.replace(MD_EXTENSION_REGEX, '');
48+
4449
// remove trailing slash for correct Windows pathing of the index files
4550
if (pathname.length > 1 && pathname.endsWith(sep)) {
4651
pathname = pathname.substring(0, pathname.length - 1);
@@ -110,7 +115,7 @@ export const getMarkdownFile = (
110115

111116
// gets the full pathname for the file (absolute path)
112117
metadata.filename = join(
113-
process.cwd(),
118+
CURRENT_WORKING_DIRECTORY,
114119
'pages',
115120
localeToUse,
116121
route.filename

pages/[...path].tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { sep } from 'node:path';
12
import Theme from '@/theme';
23
import * as nextDynamic from '@/next.dynamic.mjs';
34
import * as nextConstants from '@/next.constants.mjs';
@@ -28,7 +29,9 @@ const getRouteWrite = (pathname: string) =>
2829

2930
// This maps a pathname into an actual route object that can be used
3031
const mapPathnameToRoute = (pathname: string) => ({
31-
params: { path: pathname.split('/') },
32+
// we use a platform-specific separator to split the pathname
33+
// since we're using filepaths here and not URL paths
34+
params: { path: pathname.split(sep) },
3235
});
3336

3437
// This method receives the props from `getStaticProps` and renders/builds the Markdown

0 commit comments

Comments
 (0)