Skip to content

Commit a360981

Browse files
fix: Windows-rendering of content (#5476)
Co-authored-by: Claudio Wunder <[email protected]>
1 parent 9129bbf commit a360981

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

next.dynamic.mjs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
import { join } from 'node:path';
3+
import { join, normalize, sep } from 'node:path';
44
import { readFileSync } from 'node:fs';
55
import { VFile } from 'vfile';
66
import remarkGfm from 'remark-gfm';
@@ -41,13 +41,18 @@ const getAllPaths = async () => {
4141
(locale = '') =>
4242
(files = []) =>
4343
sourcePages.map(filename => {
44-
const path = filename.replace(nextConstants.MD_EXTENSION_REGEX, '');
44+
// remove the index.md(x) suffix from a pathname
45+
let pathname = filename.replace(nextConstants.MD_EXTENSION_REGEX, '');
46+
// remove trailing slash for correct Windows pathing of the index files
47+
if (pathname.length > 1 && pathname.endsWith(sep)) {
48+
pathname = pathname.substring(0, pathname.length - 1);
49+
}
4550

4651
return {
47-
pathname: path,
52+
pathname: normalize(pathname),
4853
filename: filename,
4954
localised: files.includes(filename),
50-
routeWithLocale: `${locale}/${path}`,
55+
routeWithLocale: `${locale}/${pathname}`,
5156
};
5257
});
5358

@@ -99,7 +104,7 @@ export const getMarkdownFile = (
99104
// which prevents any malicious attempts to access non-allowed pages
100105
// or other files that do not belong to the `sourcePages`
101106
if (routes && routes.length) {
102-
const route = routes.find(route => route.pathname === pathname);
107+
const route = routes.find(route => route.pathname === normalize(pathname));
103108

104109
if (route && route.filename) {
105110
// this determines if we should be using the fallback rendering to the default locale

0 commit comments

Comments
 (0)