Skip to content

Commit 3dc21d3

Browse files
solve all the various path prefix issues (this should be investigated more, a better solution might be possible)
1 parent f96715a commit 3dc21d3

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

apps/site/.cloudflare/node/fs.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ export function readdir(params, cb) {
66
}
77

88
export function exists(path, cb) {
9-
console.log('fs#exists', path, files.includes(path));
10-
cb(files.includes(path));
9+
const result = files.includes(path) || files.includes(path.replace(/^\//, ''));
10+
console.log('fs#exists', path, result);
11+
cb(result);
1112
}
1213

1314
// export function createReadStream(path) {

apps/site/next.dynamic.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ const getDynamicRouter = async () => {
104104

105105
// This verifies if the given pathname actually exists on our Map
106106
// meaning that the route exists on the website and can be rendered
107-
if (pathnameToFilename.has(normalizedPathname)) {
108-
const filename = pathnameToFilename.get(normalizedPathname);
107+
if (pathnameToFilename.has(normalizedPathname) || pathnameToFilename.has(`pages/${locale}/` + normalizedPathname)) {
108+
const filename = (pathnameToFilename.get(normalizedPathname) ?? pathnameToFilename.get(`pages/${locale}/` + normalizedPathname)).replace(
109+
new RegExp(`^pages/${locale}/`), ''
110+
);
109111

110112
let filePath = join(process.cwd(), 'pages');
111113

@@ -120,8 +122,9 @@ const getDynamicRouter = async () => {
120122
return { source: fileContent, filename };
121123
}
122124

123-
const existsPromise = path =>
124-
new Promise(resolve => exists(path, resolve));
125+
const existsPromise = path => {
126+
return new Promise(resolve => exists(path, resolve));
127+
}
125128

126129
// No cache hit exists, so we check if the localized file actually
127130
// exists within our file system and if it does we set it on the cache

apps/site/next.helpers.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ export const getMarkdownFiles = async (root, cwd, ignore = []) => {
4040
const cacheKey = `${root}${cwd}${ignore.join('')}`;
4141

4242
if (!globCacheByPath.has(cacheKey)) {
43+
const keyFiles = files
44+
.filter(file => file.startsWith(cwd) || file.startsWith(cwd.replace(/^\//, '')))
45+
.map(file => file.replace(`${cwd}/`, '/'));
46+
4347
//globCacheByPath.set(cacheKey, glob('**/*.{md,mdx}', { root, cwd, ignore }));
4448
globCacheByPath.set(
4549
cacheKey,
4650
Promise.resolve(
47-
files
48-
.filter(file => file.startsWith(cwd))
49-
.map(file => file.replace(`${cwd}/`, '/'))
51+
keyFiles
5052
)
5153
);
5254
}

apps/site/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"scripts:release-post": "cross-env NODE_NO_WARNINGS=1 node scripts/release-post/index.mjs",
2020
"dev": "cross-env NODE_NO_WARNINGS=1 next dev --turbo",
2121
"serve": "npm run dev",
22+
"predev": "node scripts/prebuild.generator.mjs",
2223
"prebuild": "node scripts/prebuild.generator.mjs",
2324
"build": "cross-env NODE_NO_WARNINGS=1 next build",
2425
"start": "cross-env NODE_NO_WARNINGS=1 next start",

0 commit comments

Comments
 (0)