Skip to content

Commit 5af30eb

Browse files
committed
localized project page title in cloudflare worker
1 parent dc2d045 commit 5af30eb

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

package-lock.json

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/cloudflare/functions/projects/[slug].ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import htmlTemplate from "../../public/template.html";
44

55
import { fsConfig } from "@dzcode.io/utils/dist/config";
66
import { Environment, environments } from "@dzcode.io/utils/dist/config/environment";
7+
import { plainLocalize } from "@dzcode.io/web/dist/components/locale/utils";
8+
import { dictionary } from "@dzcode.io/web/dist/components/locale/dictionary";
79

810
// @TODO-ZM: pass envs during deployment
911
export interface Env {
@@ -28,15 +30,17 @@ export const onRequest: PagesFunction<Env> = async (context) => {
2830
// @TODO-ZM: render 404 page
2931
if (!projectId) return new Response("Not found", { status: 404 });
3032

33+
// @TODO-ZM: get language from request url
34+
const language = "en";
35+
const localize = (key: string) => plainLocalize(dictionary, language, key, "NO-TRANSLATION");
36+
3137
// @TODO-ZM: use fetchV2
32-
console.log("zako", `${apiUrl}/Projects/${projectId}/name`);
3338
const projectResponse = await fetch(`${apiUrl}/Projects/${projectId}/name`);
3439
const projectData = await projectResponse.json();
35-
// @ts-expect-error @TODO-ZM: import @dzcode.oi/api
36-
// @TODO-ZM: localize
37-
const pageTitle = `See the details of ${projectData.project.name} project | DzCode i/o`;
40+
// @ts-expect-error @TODO-ZM: import @dzcode.io/api
41+
const pageTitle = `${localize("project-title-pre")} ${projectData.project.name} ${localize("project-title-post")}`;
3842

39-
const newData = htmlTemplate.replace(/{{template-title}}/, pageTitle);
43+
const newData = htmlTemplate.replace(/{{template-title}}/g, pageTitle);
4044

4145
return new Response(newData, {
4246
headers: {

web/cloudflare/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2-
"name": "dzcode-dot-io",
2+
"name": "@dzcode.io/cloudflare",
33
"version": "0.0.0",
44
"dependencies": {
5-
"@dzcode.io/utils": "*"
5+
"@dzcode.io/utils": "*",
6+
"@dzcode.io/web": "*"
67
},
78
"devDependencies": {
89
"@cloudflare/workers-types": "^4.20240919.0",
@@ -11,9 +12,10 @@
1112
},
1213
"private": true,
1314
"scripts": {
15+
"build": "lerna run build:alone [email protected]/web --include-dependencies --stream",
1416
"deploy:prd": "wrangler pages deploy --project-name dzcode-dot-io --directory=./public --branch main",
1517
"deploy:stg": "wrangler pages deploy --project-name stage-dot-dzcode-dot-io --directory=./public --branch main",
16-
"dev": "wrangler pages dev . --port 8080",
18+
"dev": "npm run build && wrangler pages dev . --port 8080",
1719
"generate:htmls": "cd .. && npm run bundle && npm run pre-deploy",
1820
"lint:eslint": "eslint --config ../../packages/tooling/eslint.config.mjs",
1921
"lint:prettier": "prettier --config ../../packages/tooling/.prettierrc --ignore-path ../../packages/tooling/.prettierignore --log-level warn"

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
},
6363
"scripts": {
6464
"build": "lerna run build:alone [email protected]/web --include-dependencies --stream",
65+
"build:alone": "tspc",
6566
"build:watch": "lerna run build:alone:watch [email protected]/web --include-dependencies --parallel",
6667
"bundle": "npm run build && npm run bundle:alone",
6768
"bundle:alone": "cross-env NODE_ENV=production rsbuild build",

0 commit comments

Comments
 (0)