@docusaurus/core 4.0.0-canary-7110 → 4.0.0-canary-7130

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -92,6 +92,9 @@ function createServeRequestHandler({ outDir, baseUrl: configBaseUrl, trailingSla
92
92
  ],
93
93
  },
94
94
  ],
95
+ }, {
96
+ // serve-handler only calls it for 404 errors
97
+ sendError: (absolutePath) => sendNotFoundPage(res, outDir, absolutePath),
95
98
  });
96
99
  };
97
100
  }
@@ -230,6 +233,33 @@ function getCleanPathname(pathname, baseUrl) {
230
233
  // Like serve-handler, /index redirects to /
231
234
  return cleanPathname === baseUrl.slice(0, -1) ? baseUrl : cleanPathname;
232
235
  }
236
+ // Serves the nearest 404.html, like Cloudflare Pages: "/fr/missing" gets the
237
+ // 404 page of the "fr" locale build, "fr/404.html"
238
+ // See https://developers.cloudflare.com/pages/configuration/serving-pages/#not-found-behavior
239
+ async function sendNotFoundPage(res, outDir, absolutePath) {
240
+ const page = await readNearestNotFoundPage(outDir, absolutePath);
241
+ if (page === undefined) {
242
+ res.writeHead(404);
243
+ res.end('Not Found');
244
+ return;
245
+ }
246
+ res.writeHead(404, { 'Content-Type': 'text/html; charset=utf-8' });
247
+ res.end(page);
248
+ }
249
+ async function readNearestNotFoundPage(outDir, absolutePath) {
250
+ const folders = node_path_1.default
251
+ .relative(outDir, absolutePath)
252
+ .split(node_path_1.default.sep)
253
+ .slice(0, -1);
254
+ for (let depth = folders.length; depth >= 0; depth -= 1) {
255
+ const pagePath = node_path_1.default.join(outDir, ...folders.slice(0, depth), '404.html');
256
+ const page = await fs_1.fs.readFile(pagePath).catch(() => undefined);
257
+ if (page !== undefined) {
258
+ return page;
259
+ }
260
+ }
261
+ return undefined;
262
+ }
233
263
  function redirect(res, statusCode, location) {
234
264
  res.writeHead(statusCode, {
235
265
  Location: location,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docusaurus/core",
3
3
  "description": "Easy to Maintain Open Source Documentation Websites",
4
- "version": "4.0.0-canary-7110",
4
+ "version": "4.0.0-canary-7130",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -27,15 +27,15 @@
27
27
  "url": "https://github.com/meta/docusaurus/issues"
28
28
  },
29
29
  "dependencies": {
30
- "@docusaurus/babel": "4.0.0-canary-7110",
31
- "@docusaurus/bundler": "4.0.0-canary-7110",
32
- "@docusaurus/fs": "4.0.0-canary-7110",
33
- "@docusaurus/glob": "4.0.0-canary-7110",
34
- "@docusaurus/logger": "4.0.0-canary-7110",
35
- "@docusaurus/mdx-loader": "4.0.0-canary-7110",
36
- "@docusaurus/utils": "4.0.0-canary-7110",
37
- "@docusaurus/utils-common": "4.0.0-canary-7110",
38
- "@docusaurus/utils-validation": "4.0.0-canary-7110",
30
+ "@docusaurus/babel": "4.0.0-canary-7130",
31
+ "@docusaurus/bundler": "4.0.0-canary-7130",
32
+ "@docusaurus/fs": "4.0.0-canary-7130",
33
+ "@docusaurus/glob": "4.0.0-canary-7130",
34
+ "@docusaurus/logger": "4.0.0-canary-7130",
35
+ "@docusaurus/mdx-loader": "4.0.0-canary-7130",
36
+ "@docusaurus/utils": "4.0.0-canary-7130",
37
+ "@docusaurus/utils-common": "4.0.0-canary-7130",
38
+ "@docusaurus/utils-validation": "4.0.0-canary-7130",
39
39
  "@rspack/core": "^2.3.0",
40
40
  "@rspack/dev-server": "^2.2.2",
41
41
  "boxen": "^9.0.0",
@@ -68,8 +68,8 @@
68
68
  "webpack-merge": "^6.0.1"
69
69
  },
70
70
  "devDependencies": {
71
- "@docusaurus/module-type-aliases": "4.0.0-canary-7110",
72
- "@docusaurus/types": "4.0.0-canary-7110",
71
+ "@docusaurus/module-type-aliases": "4.0.0-canary-7130",
72
+ "@docusaurus/types": "4.0.0-canary-7130",
73
73
  "@total-typescript/shoehorn": "^0.1.2",
74
74
  "@types/escape-html": "^1.0.4",
75
75
  "@types/history": "^4.7.11",