Skip to content

Commit ad75be0

Browse files
committed
fix: Windows-rendering of content
1 parent 1a3884a commit ad75be0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

next.dynamic.mjs

Lines changed: 8 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,10 +41,13 @@ const getAllPaths = async () => {
4141
(locale = '') =>
4242
(files = []) =>
4343
sourcePages.map(filename => {
44-
const path = filename.replace(nextConstants.MD_EXTENSION_REGEX, '');
45-
44+
let path = filename.replace(nextConstants.MD_EXTENSION_REGEX, '');
45+
// remove trailing slash for correct Windows pathing of the index files
46+
if (path.length > 1 && path.endsWith(sep)) {
47+
path = path.substring(0, path.length - 1);
48+
}
4649
return {
47-
pathname: path,
50+
pathname: normalize(path),
4851
filename: filename,
4952
localised: files.includes(filename),
5053
routeWithLocale: `${locale}/${path}`,
@@ -99,7 +102,7 @@ export const getMarkdownFile = (
99102
// which prevents any malicious attempts to access non-allowed pages
100103
// or other files that do not belong to the `sourcePages`
101104
if (routes && routes.length) {
102-
const route = routes.find(route => route.pathname === pathname);
105+
const route = routes.find(route => route.pathname === normalize(pathname));
103106

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

0 commit comments

Comments
 (0)