Skip to content

Commit

Permalink
Merge pull request #603 from dzcode-io/cloudflare-redirect
Browse files Browse the repository at this point in the history
fix: Cloudflare 404 redirect
  • Loading branch information
ZibanPirate authored Sep 22, 2024
2 parents 97ed8a4 + 60b89a0 commit 609f84b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"build:watch": "lerna run build:alone:watch [email protected]/web --include-dependencies --parallel",
"bundle": "npm run build && npm run bundle:alone",
"bundle:alone": "cross-env NODE_ENV=production rsbuild build",
"bundle:preview": "rsbuild preview",
"bundle:doctor": "RSDOCTOR=true rsbuild build",
"clean": "lerna run clean:alone [email protected]/web --include-dependencies --stream",
"clean:alone": "rimraf dist coverage bundle node_modules/.cache && rimraf ./cloudflare/public",
Expand Down
15 changes: 8 additions & 7 deletions web/src/_build/gen-multiple-htmls.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// for dev, run:
// npm run clean && npm run bundle && npm run generate:htmls
// npm run rsbuild preview
// npm run bundle:preview

import { join } from "path";
import { readFileSync, writeFileSync, mkdirSync } from "fs";
Expand All @@ -24,13 +24,14 @@ const SKIP_ROOT_HTML = process.env.SKIP_ROOT_HTML === "true";
console.log(`generating ${allPages.length} html files ...`);

allPages.forEach((pageInfo) => {
const pathName = pageInfo.uri;
const outputHtmlDir = join(distFolder, pathName);
const outputHtmlPath = join(outputHtmlDir, "index.html");
if (SKIP_ROOT_HTML && outputHtmlPath === indexHtmlPath) {
console.log(`skipping root html: ${outputHtmlPath}`);
let pathName = pageInfo.uri.replace(/\/$/, "");
pathName = `${pathName || "index"}.html`;
if (SKIP_ROOT_HTML && pathName === "index.html") {
console.log(`skipping root html`);
return;
}
const outputHtmlPath = join(distFolder, pathName);
const outputHtmlParentDir = join(outputHtmlPath, "..");

let newHtml = indexHtml;
newHtml = newHtml.replace(
Expand Down Expand Up @@ -58,7 +59,7 @@ allPages.forEach((pageInfo) => {
newHtml = newHtml.replace(/{{ogImage}}/g, pageInfo.ogImage);
newHtml = newHtml.replace(/{{sentryOrigin}}/g, `https://${SENTRY_ORIGIN}`);

mkdirSync(outputHtmlDir, { recursive: true });
mkdirSync(outputHtmlParentDir, { recursive: true });
writeFileSync(outputHtmlPath, newHtml);

console.log(outputHtmlPath, "✅");
Expand Down
2 changes: 1 addition & 1 deletion web/src/_build/gen-robots-txt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// for dev, run:
// npm run clean && npm run bundle && npm run generate:robots-txt
// npm run rsbuild preview
// npm run bundle:preview

import { join } from "path";
import { writeFileSync } from "fs";
Expand Down
8 changes: 8 additions & 0 deletions web/src/_build/pages/static-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ const staticURLs: PageInfoWithLocalKeys[] = [
"https://images.unsplash.com/photo-1526663089957-f2aa2776f572?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=750&q=80&auto=format&fit=crop&w=1200&h=627&q=80",
keywords: "faq, open-source, algeria, dzcode",
},
{
uri: "/404",
title: "notfound-title",
description: "notfound-description",
ogImage:
"https://images.unsplash.com/photo-1510133768164-a8f7e4d4e3dc?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=750&q=80&auto=format&fit=crop&w=1200&h=627&q=80",
keywords: "faq, open-source, algeria, dzcode",
},
];

export const staticPages: PageInfo[] = staticURLs.reduce<PageInfo[]>(
Expand Down

0 comments on commit 609f84b

Please sign in to comment.