|
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,13 +41,18 @@ const getAllPaths = async () => { |
41 | 41 | (locale = '') => |
42 | 42 | (files = []) => |
43 | 43 | 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 | + } |
45 | 50 |
|
46 | 51 | return { |
47 | | - pathname: path, |
| 52 | + pathname: normalize(pathname), |
48 | 53 | filename: filename, |
49 | 54 | localised: files.includes(filename), |
50 | | - routeWithLocale: `${locale}/${path}`, |
| 55 | + routeWithLocale: `${locale}/${pathname}`, |
51 | 56 | }; |
52 | 57 | }); |
53 | 58 |
|
@@ -99,7 +104,7 @@ export const getMarkdownFile = ( |
99 | 104 | // which prevents any malicious attempts to access non-allowed pages |
100 | 105 | // or other files that do not belong to the `sourcePages` |
101 | 106 | if (routes && routes.length) { |
102 | | - const route = routes.find(route => route.pathname === pathname); |
| 107 | + const route = routes.find(route => route.pathname === normalize(pathname)); |
103 | 108 |
|
104 | 109 | if (route && route.filename) { |
105 | 110 | // this determines if we should be using the fallback rendering to the default locale |
|
0 commit comments