|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -import { join } from 'node:path'; |
| 3 | +import { join, normalize, sep } from 'node:path'; |
4 | 4 | import { readFileSync } from 'node:fs'; |
5 | 5 | import { VFile } from 'vfile'; |
6 | 6 | import remarkGfm from 'remark-gfm'; |
@@ -41,10 +41,13 @@ const getAllPaths = async () => { |
41 | 41 | (locale = '') => |
42 | 42 | (files = []) => |
43 | 43 | 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 | + } |
46 | 49 | return { |
47 | | - pathname: path, |
| 50 | + pathname: normalize(path), |
48 | 51 | filename: filename, |
49 | 52 | localised: files.includes(filename), |
50 | 53 | routeWithLocale: `${locale}/${path}`, |
@@ -99,7 +102,7 @@ export const getMarkdownFile = ( |
99 | 102 | // which prevents any malicious attempts to access non-allowed pages |
100 | 103 | // or other files that do not belong to the `sourcePages` |
101 | 104 | if (routes && routes.length) { |
102 | | - const route = routes.find(route => route.pathname === pathname); |
| 105 | + const route = routes.find(route => route.pathname === normalize(pathname)); |
103 | 106 |
|
104 | 107 | if (route && route.filename) { |
105 | 108 | // this determines if we should be using the fallback rendering to the default locale |
|
0 commit comments