From b75d8e5e67cb95e50e90f1a40d6beb0ef85bdca0 Mon Sep 17 00:00:00 2001 From: Peppa Date: Sat, 21 Nov 2026 14:01:29 +0000 Subject: [PATCH] =?UTF-8?q?INA-2:=20=D0=BA=D0=B0=D1=80=D0=BA=D0=B0=D1=81?= =?UTF-8?q?=20Node/TS,=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=D1=8B?= =?UTF-8?q?=20ru/kk/en,=20=D1=80=D0=B5=D0=BD=D0=B4=D0=B5=D1=80=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B=20=D0=B8=20=D1=81?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D0=B5=D1=80,=20=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .gitignore | 2 + .peppa/project.json | 20 ++- biome.json | 7 + locales/en.json | 25 ++++ locales/kk.json | 25 ++++ locales/ru.json | 25 ++++ package.json | 23 +++ pnpm-lock.yaml | 355 ++++++++++++++++++++++++++++++++++++++++++++ src/i18n.ts | 67 +++++++++ src/index.ts | 15 ++ src/render.ts | 101 +++++++++++++ src/server.ts | 38 +++++ tsconfig.build.json | 9 ++ tsconfig.json | 18 +++ 14 files changed, 729 insertions(+), 1 deletion(-) create mode 100644 biome.json create mode 100644 locales/en.json create mode 100644 locales/kk.json create mode 100644 locales/ru.json create mode 100644 package.json create mode 100644 pnpm-lock.yaml create mode 100644 src/i18n.ts create mode 100644 src/index.ts create mode 100644 src/render.ts create mode 100644 src/server.ts create mode 100644 tsconfig.build.json create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 8f85d90..5bdf003 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ node_modules/ .env .env.local .DS_Store +dist/ +.pnpm-store/ diff --git a/.peppa/project.json b/.peppa/project.json index fe8391c..8289023 100644 --- a/.peppa/project.json +++ b/.peppa/project.json @@ -1 +1,19 @@ -{"slug":"inat","key":"INA","name":"inat","peppaUrl":"https://peppa.telecom.quest"} +{ + "slug": "inat", + "key": "INA", + "name": "inat", + "peppaUrl": "https://peppa.telecom.quest", + "checks": { + "install": "corepack enable >/dev/null 2>&1 || true; pnpm install --frozen-lockfile", + "lint": "pnpm lint", + "typecheck": "pnpm typecheck", + "test": "pnpm test", + "build": "pnpm build" + }, + "deploy": { + "compose": "deploy/compose.yml", + "service": "web", + "port": 3000, + "health": "/healthz" + } +} diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..8a3412c --- /dev/null +++ b/biome.json @@ -0,0 +1,7 @@ +{ + "$schema": "./node_modules/@biomejs/biome/configuration_schema.json", + "vcs": { "enabled": true, "clientKind": "git", "useIgnoreFile": true }, + "files": { "includes": ["src/**", "test/**", "locales/**", "*.json"] }, + "formatter": { "indentStyle": "space", "indentWidth": 2, "lineWidth": 100 }, + "linter": { "enabled": true, "rules": { "preset": "recommended" } } +} diff --git a/locales/en.json b/locales/en.json new file mode 100644 index 0000000..ab7ac39 --- /dev/null +++ b/locales/en.json @@ -0,0 +1,25 @@ +{ + "meta.title": "[PLACEHOLDER] Company name — business card website", + "meta.description": "[PLACEHOLDER] Short company description for search engines and links", + "site.name": "[PLACEHOLDER] Company name", + "site.tagline": "[PLACEHOLDER] Short company slogan", + "about.heading": "About us", + "about.text": "[PLACEHOLDER] This is where you will find our story: who we are, how long we have been working and why you can trust us.", + "services.heading": "What we do", + "services.text": "[PLACEHOLDER] This is where you will find a description of what the company does.", + "services.item1": "[PLACEHOLDER] First line of work", + "services.item2": "[PLACEHOLDER] Second line of work", + "services.item3": "[PLACEHOLDER] Third line of work", + "contacts.heading": "Contacts", + "contacts.text": "[PLACEHOLDER] This is where you will find ways to contact us.", + "contacts.phoneLabel": "Phone", + "contacts.phone": "[PLACEHOLDER] phone", + "contacts.emailLabel": "Email", + "contacts.email": "[PLACEHOLDER] email", + "contacts.addressLabel": "Address", + "contacts.address": "[PLACEHOLDER] address", + "footer.text": "[PLACEHOLDER] Company name", + "notFound.title": "Page not found", + "notFound.text": "This page does not exist. Go to the home page.", + "notFound.link": "Home page" +} diff --git a/locales/kk.json b/locales/kk.json new file mode 100644 index 0000000..fcbd1b8 --- /dev/null +++ b/locales/kk.json @@ -0,0 +1,25 @@ +{ + "meta.title": "[ҮЛГІ] Компания атауы — визитка-сайт", + "meta.description": "[ҮЛГІ] Іздеу жүйелері мен сілтемелерге арналған компанияның қысқаша сипаттамасы", + "site.name": "[ҮЛГІ] Компания атауы", + "site.tagline": "[ҮЛГІ] Компанияның қысқа ұраны", + "about.heading": "Біз туралы", + "about.text": "[ҮЛГІ] Мұнда компания туралы мәлімет болады: біз кімбіз, қанша жыл жұмыс істейміз және бізге неге сенуге болады.", + "services.heading": "Немен айналысамыз", + "services.text": "[ҮЛГІ] Мұнда компанияның қызметі сипатталады.", + "services.item1": "[ҮЛГІ] Бірінші жұмыс бағыты", + "services.item2": "[ҮЛГІ] Екінші жұмыс бағыты", + "services.item3": "[ҮЛГІ] Үшінші жұмыс бағыты", + "contacts.heading": "Байланыс", + "contacts.text": "[ҮЛГІ] Мұнда бізбен байланысу жолдары болады.", + "contacts.phoneLabel": "Телефон", + "contacts.phone": "[ҮЛГІ] телефон", + "contacts.emailLabel": "Пошта", + "contacts.email": "[ҮЛГІ] пошта", + "contacts.addressLabel": "Мекенжай", + "contacts.address": "[ҮЛГІ] мекенжай", + "footer.text": "[ҮЛГІ] Компания атауы", + "notFound.title": "Бет табылмады", + "notFound.text": "Мұндай бет жоқ. Басты бетке өтіңіз.", + "notFound.link": "Басты бетке" +} diff --git a/locales/ru.json b/locales/ru.json new file mode 100644 index 0000000..1d0b557 --- /dev/null +++ b/locales/ru.json @@ -0,0 +1,25 @@ +{ + "meta.title": "[ЗАГЛУШКА] Название компании — сайт-визитка", + "meta.description": "[ЗАГЛУШКА] Краткое описание компании для поисковиков и ссылок", + "site.name": "[ЗАГЛУШКА] Название компании", + "site.tagline": "[ЗАГЛУШКА] Короткий слоган компании", + "about.heading": "Кто мы", + "about.text": "[ЗАГЛУШКА] Здесь будет рассказ о компании: кто мы, сколько лет работаем и почему нам можно доверять.", + "services.heading": "Чем занимаемся", + "services.text": "[ЗАГЛУШКА] Здесь будет описание того, чем занимается компания.", + "services.item1": "[ЗАГЛУШКА] Первое направление работы", + "services.item2": "[ЗАГЛУШКА] Второе направление работы", + "services.item3": "[ЗАГЛУШКА] Третье направление работы", + "contacts.heading": "Контакты", + "contacts.text": "[ЗАГЛУШКА] Здесь будут способы связаться с нами.", + "contacts.phoneLabel": "Телефон", + "contacts.phone": "[ЗАГЛУШКА] телефон", + "contacts.emailLabel": "Почта", + "contacts.email": "[ЗАГЛУШКА] почта", + "contacts.addressLabel": "Адрес", + "contacts.address": "[ЗАГЛУШКА] адрес", + "footer.text": "[ЗАГЛУШКА] Название компании", + "notFound.title": "Страница не найдена", + "notFound.text": "Такой страницы нет. Перейдите на главную страницу.", + "notFound.link": "На главную" +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..81a14ae --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "inat", + "version": "0.1.0", + "private": true, + "type": "module", + "engines": { + "node": ">=22.18" + }, + "packageManager": "pnpm@10.34.9", + "scripts": { + "dev": "node src/index.ts", + "start": "node dist/index.js", + "lint": "biome check .", + "typecheck": "tsc --noEmit", + "test": "node --test \"test/**/*.test.ts\"", + "build": "tsc -p tsconfig.build.json" + }, + "devDependencies": { + "@biomejs/biome": "^2.6.8", + "@types/node": "^22.20.5", + "typescript": "^7.0.2" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 0000000..08d4b00 --- /dev/null +++ b/pnpm-lock.yaml @@ -0,0 +1,355 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + devDependencies: + '@biomejs/biome': + specifier: ^2.6.8 + version: 2.6.8 + '@types/node': + specifier: ^22.20.5 + version: 22.20.5 + typescript: + specifier: ^7.0.2 + version: 7.0.2 + +packages: + + '@biomejs/biome@2.6.8': + resolution: {integrity: sha512-kqZUFvX6/aYQOmzfRN5ANcfNS9wLH4aHLWWP/dQKyhRZVoA6rdWszA7DGugFcxPbMiznUyVYyukVl+ExZN4PQA==} + engines: {node: '>=14.21.3'} + hasBin: true + + '@biomejs/cli-android-arm64@2.6.8': + resolution: {integrity: sha512-X4JKPLK85kfUTwuuaORFplnBfGjKkp62PsFhhcL7F/Tpltc7pyUofjlkkMnlZZLWsifFl7LNB8ngVrwJg1uo1Q==} + engines: {node: '>=14.21.3'} + cpu: [arm64] + os: [android] + + '@biomejs/cli-android-x64@2.6.8': + resolution: {integrity: sha512-C3Hk485vl+deEj53K08+SYYelPIPkdSZL3qHuD31Xi+qydVa4q2ze+aCYo1k3iJGWtvWtjHaGkDh7S2sX6wk8w==} + engines: {node: '>=14.21.3'} + cpu: [x64] + os: [android] + + '@biomejs/cli-darwin-arm64@2.6.8': + resolution: {integrity: sha512-DHyj+JnRHcn4YdvpiqgTFZMYKSPELMCfFpNNlEuu1L8DKTGXhzW7raIwdsbo2Ie9nCljQLAQkVWQk/mwM0ueiA==} + engines: {node: '>=14.21.3'} + cpu: [arm64] + os: [darwin] + + '@biomejs/cli-darwin-x64@2.6.8': + resolution: {integrity: sha512-QWWUPjlA0RnkkgYnFLUHZu+RrDc0FdK0A+wEPA+dENQJwsuSHMH89lspnAw2QUWWc9VHyfluGx1Xmp6Y2GZi8Q==} + engines: {node: '>=14.21.3'} + cpu: [x64] + os: [darwin] + + '@biomejs/cli-linux-arm64-musl@2.6.8': + resolution: {integrity: sha512-WB9PhOitX+bRc0G3+GNJGlvbKoWn3JoB9z4E04JQizIC9aPCQyIvwvWG7QZHxw6k20Fi+dHLmZ2fSEmBa9HqiA==} + engines: {node: '>=14.21.3'} + cpu: [arm64] + os: [linux] + libc: [musl] + + '@biomejs/cli-linux-arm64@2.6.8': + resolution: {integrity: sha512-0Bjim8lKwnrvXUHoI4k3Tb51BjoiLEwDnovCI8nSzkk6wj3dShiuAjrx6+X0Hjf4ejR1sRZgTQiSDHlpy9vB7w==} + engines: {node: '>=14.21.3'} + cpu: [arm64] + os: [linux] + libc: [glibc] + + '@biomejs/cli-linux-x64-musl@2.6.8': + resolution: {integrity: sha512-64Yzo+J4fEk7Kf9SMnVdVxC+Y2A2e/L86QTP9JjGQ57lsddyELLpbBcNMxSJggre2T1AvISwwSrOApkBAHDqNA==} + engines: {node: '>=14.21.3'} + cpu: [x64] + os: [linux] + libc: [musl] + + '@biomejs/cli-linux-x64@2.6.8': + resolution: {integrity: sha512-XIk3pLQT56I6Tti+u0DF8FtSNXjCMTPbxVTzfJ9cS2t1ImVKvrqV5b52GuEaJg6/wuiXvz0sjfb5saB4TPRjzA==} + engines: {node: '>=14.21.3'} + cpu: [x64] + os: [linux] + libc: [glibc] + + '@biomejs/cli-win32-arm64@2.6.8': + resolution: {integrity: sha512-ezjCEZzHIWE2pdh83a7zLVcAAcDaERcTcvfA7uWlxqz/1CuDxgtfO19pDg9B6YY4wKYIDvYBw2QCMnqIshSwmw==} + engines: {node: '>=14.21.3'} + cpu: [arm64] + os: [win32] + + '@biomejs/cli-win32-x64@2.6.8': + resolution: {integrity: sha512-cD6HvGczZUiAYsY8s2TxxXj2AHFzEdMomvVJfEjzOjBM45nGqIDfBpbtvwGQzDCN8X2yKKk9u1jnDZisT2nxIg==} + engines: {node: '>=14.21.3'} + cpu: [x64] + os: [win32] + + '@types/node@22.20.5': + resolution: {integrity: sha512-U2+DNr+wSjpsTS/wZGYHq7GcwfuSmKiKvoPvK22zwTlRhU91yOniN4qRR5KhIjvif7ysw/dz/hKmfDH0Ris4aA==} + + '@typescript/typescript-aix-ppc64@7.0.2': + resolution: {integrity: sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ==} + engines: {node: '>=16.20.0'} + cpu: [ppc64] + os: [aix] + + '@typescript/typescript-darwin-arm64@7.0.2': + resolution: {integrity: sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [darwin] + + '@typescript/typescript-darwin-x64@7.0.2': + resolution: {integrity: sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [darwin] + + '@typescript/typescript-freebsd-arm64@7.0.2': + resolution: {integrity: sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [freebsd] + + '@typescript/typescript-freebsd-x64@7.0.2': + resolution: {integrity: sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [freebsd] + + '@typescript/typescript-linux-arm64@7.0.2': + resolution: {integrity: sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [linux] + + '@typescript/typescript-linux-arm@7.0.2': + resolution: {integrity: sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ==} + engines: {node: '>=16.20.0'} + cpu: [arm] + os: [linux] + + '@typescript/typescript-linux-loong64@7.0.2': + resolution: {integrity: sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ==} + engines: {node: '>=16.20.0'} + cpu: [loong64] + os: [linux] + + '@typescript/typescript-linux-mips64el@7.0.2': + resolution: {integrity: sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA==} + engines: {node: '>=16.20.0'} + cpu: [mips64el] + os: [linux] + + '@typescript/typescript-linux-ppc64@7.0.2': + resolution: {integrity: sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA==} + engines: {node: '>=16.20.0'} + cpu: [ppc64] + os: [linux] + + '@typescript/typescript-linux-riscv64@7.0.2': + resolution: {integrity: sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ==} + engines: {node: '>=16.20.0'} + cpu: [riscv64] + os: [linux] + + '@typescript/typescript-linux-s390x@7.0.2': + resolution: {integrity: sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw==} + engines: {node: '>=16.20.0'} + cpu: [s390x] + os: [linux] + + '@typescript/typescript-linux-x64@7.0.2': + resolution: {integrity: sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [linux] + + '@typescript/typescript-netbsd-arm64@7.0.2': + resolution: {integrity: sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [netbsd] + + '@typescript/typescript-netbsd-x64@7.0.2': + resolution: {integrity: sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [netbsd] + + '@typescript/typescript-openbsd-arm64@7.0.2': + resolution: {integrity: sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [openbsd] + + '@typescript/typescript-openbsd-x64@7.0.2': + resolution: {integrity: sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [openbsd] + + '@typescript/typescript-sunos-x64@7.0.2': + resolution: {integrity: sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [sunos] + + '@typescript/typescript-win32-arm64@7.0.2': + resolution: {integrity: sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [win32] + + '@typescript/typescript-win32-x64@7.0.2': + resolution: {integrity: sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [win32] + + typescript@7.0.2: + resolution: {integrity: sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA==} + engines: {node: '>=16.20.0'} + hasBin: true + + undici-types@6.21.0: + resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==} + +snapshots: + + '@biomejs/biome@2.6.8': + optionalDependencies: + '@biomejs/cli-android-arm64': 2.6.8 + '@biomejs/cli-android-x64': 2.6.8 + '@biomejs/cli-darwin-arm64': 2.6.8 + '@biomejs/cli-darwin-x64': 2.6.8 + '@biomejs/cli-linux-arm64': 2.6.8 + '@biomejs/cli-linux-arm64-musl': 2.6.8 + '@biomejs/cli-linux-x64': 2.6.8 + '@biomejs/cli-linux-x64-musl': 2.6.8 + '@biomejs/cli-win32-arm64': 2.6.8 + '@biomejs/cli-win32-x64': 2.6.8 + + '@biomejs/cli-android-arm64@2.6.8': + optional: true + + '@biomejs/cli-android-x64@2.6.8': + optional: true + + '@biomejs/cli-darwin-arm64@2.6.8': + optional: true + + '@biomejs/cli-darwin-x64@2.6.8': + optional: true + + '@biomejs/cli-linux-arm64-musl@2.6.8': + optional: true + + '@biomejs/cli-linux-arm64@2.6.8': + optional: true + + '@biomejs/cli-linux-x64-musl@2.6.8': + optional: true + + '@biomejs/cli-linux-x64@2.6.8': + optional: true + + '@biomejs/cli-win32-arm64@2.6.8': + optional: true + + '@biomejs/cli-win32-x64@2.6.8': + optional: true + + '@types/node@22.20.5': + dependencies: + undici-types: 6.21.0 + + '@typescript/typescript-aix-ppc64@7.0.2': + optional: true + + '@typescript/typescript-darwin-arm64@7.0.2': + optional: true + + '@typescript/typescript-darwin-x64@7.0.2': + optional: true + + '@typescript/typescript-freebsd-arm64@7.0.2': + optional: true + + '@typescript/typescript-freebsd-x64@7.0.2': + optional: true + + '@typescript/typescript-linux-arm64@7.0.2': + optional: true + + '@typescript/typescript-linux-arm@7.0.2': + optional: true + + '@typescript/typescript-linux-loong64@7.0.2': + optional: true + + '@typescript/typescript-linux-mips64el@7.0.2': + optional: true + + '@typescript/typescript-linux-ppc64@7.0.2': + optional: true + + '@typescript/typescript-linux-riscv64@7.0.2': + optional: true + + '@typescript/typescript-linux-s390x@7.0.2': + optional: true + + '@typescript/typescript-linux-x64@7.0.2': + optional: true + + '@typescript/typescript-netbsd-arm64@7.0.2': + optional: true + + '@typescript/typescript-netbsd-x64@7.0.2': + optional: true + + '@typescript/typescript-openbsd-arm64@7.0.2': + optional: true + + '@typescript/typescript-openbsd-x64@7.0.2': + optional: true + + '@typescript/typescript-sunos-x64@7.0.2': + optional: true + + '@typescript/typescript-win32-arm64@7.0.2': + optional: true + + '@typescript/typescript-win32-x64@7.0.2': + optional: true + + typescript@7.0.2: + optionalDependencies: + '@typescript/typescript-aix-ppc64': 7.0.2 + '@typescript/typescript-darwin-arm64': 7.0.2 + '@typescript/typescript-darwin-x64': 7.0.2 + '@typescript/typescript-freebsd-arm64': 7.0.2 + '@typescript/typescript-freebsd-x64': 7.0.2 + '@typescript/typescript-linux-arm': 7.0.2 + '@typescript/typescript-linux-arm64': 7.0.2 + '@typescript/typescript-linux-loong64': 7.0.2 + '@typescript/typescript-linux-mips64el': 7.0.2 + '@typescript/typescript-linux-ppc64': 7.0.2 + '@typescript/typescript-linux-riscv64': 7.0.2 + '@typescript/typescript-linux-s390x': 7.0.2 + '@typescript/typescript-linux-x64': 7.0.2 + '@typescript/typescript-netbsd-arm64': 7.0.2 + '@typescript/typescript-netbsd-x64': 7.0.2 + '@typescript/typescript-openbsd-arm64': 7.0.2 + '@typescript/typescript-openbsd-x64': 7.0.2 + '@typescript/typescript-sunos-x64': 7.0.2 + '@typescript/typescript-win32-arm64': 7.0.2 + '@typescript/typescript-win32-x64': 7.0.2 + + undici-types@6.21.0: {} diff --git a/src/i18n.ts b/src/i18n.ts new file mode 100644 index 0000000..88202e8 --- /dev/null +++ b/src/i18n.ts @@ -0,0 +1,67 @@ +import { readFileSync } from "node:fs"; +import { fileURLToPath } from "node:url"; + +export const LOCALES = ["ru", "kk", "en"] as const; +export type Locale = (typeof LOCALES)[number]; +export const DEFAULT_LOCALE: Locale = "ru"; + +/** Keys every locale file must contain. */ +export const REQUIRED_KEYS = [ + "meta.title", + "meta.description", + "site.name", + "site.tagline", + "about.heading", + "about.text", + "services.heading", + "services.text", + "services.item1", + "services.item2", + "services.item3", + "contacts.heading", + "contacts.text", + "contacts.phoneLabel", + "contacts.phone", + "contacts.emailLabel", + "contacts.email", + "contacts.addressLabel", + "contacts.address", + "footer.text", + "notFound.title", + "notFound.text", + "notFound.link", +] as const; +export type MessageKey = (typeof REQUIRED_KEYS)[number]; +export type Messages = Record; + +/** Locale files live in /locales both from src/ and from dist/. */ +export const LOCALES_DIR = fileURLToPath(new URL("../locales/", import.meta.url)); + +/** Returns problems with a locale dictionary: missing, empty or unknown keys. */ +export function validateMessages(data: unknown): string[] { + if (typeof data !== "object" || data === null || Array.isArray(data)) { + return ["file must contain a JSON object"]; + } + const record = data as Record; + const problems: string[] = []; + for (const key of REQUIRED_KEYS) { + const value = record[key]; + if (value === undefined) problems.push(`missing key ${key}`); + else if (typeof value !== "string" || value.trim() === "") problems.push(`empty key ${key}`); + } + const known = new Set(REQUIRED_KEYS); + for (const key of Object.keys(record)) { + if (!known.has(key)) problems.push(`unknown key ${key}`); + } + return problems; +} + +export function loadMessages(locale: Locale, dir: string = LOCALES_DIR): Messages { + const file = `${dir}/${locale}.json`; + const data: unknown = JSON.parse(readFileSync(file, "utf8")); + const problems = validateMessages(data); + if (problems.length > 0) { + throw new Error(`Invalid locale file ${file}: ${problems.join(", ")}`); + } + return data as Messages; +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..7316dab --- /dev/null +++ b/src/index.ts @@ -0,0 +1,15 @@ +import { createApp } from "./server.ts"; + +const port = Number(process.env.PORT ?? 3000); +const server = createApp(); + +server.listen(port, () => { + console.log(`inat: listening on port ${port}`); +}); + +for (const signal of ["SIGTERM", "SIGINT"] as const) { + process.on(signal, () => { + server.close(() => process.exit(0)); + setTimeout(() => process.exit(0), 5000).unref(); + }); +} diff --git a/src/render.ts b/src/render.ts new file mode 100644 index 0000000..17d75b4 --- /dev/null +++ b/src/render.ts @@ -0,0 +1,101 @@ +import type { Locale, Messages } from "./i18n.ts"; + +const HTML_ESCAPES: Record = { + "&": "&", + "<": "<", + ">": ">", + '"': """, + "'": "'", +}; + +export function escapeHtml(value: string): string { + return value.replace(/[&<>"']/g, (ch) => HTML_ESCAPES[ch] ?? ch); +} + +const STYLES = ` +*,*::before,*::after{box-sizing:border-box} +html{-webkit-text-size-adjust:100%;text-size-adjust:100%} +body{margin:0;font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif; + font-size:1.0625rem;line-height:1.6;color:#1f2328;background:#fff; + overflow-wrap:anywhere;word-break:normal} +.container{width:100%;max-width:46rem;margin:0 auto;padding:0 1rem} +header{padding:2.5rem 0 1.5rem;border-bottom:1px solid #d0d7de} +h1{margin:0 0 .5rem;font-size:clamp(1.5rem,5vw,2.25rem);line-height:1.2} +h2{margin:0 0 .75rem;font-size:clamp(1.25rem,4vw,1.6rem);line-height:1.25} +.tagline{margin:0;color:#57606a} +section{padding:1.75rem 0;border-bottom:1px solid #eaeef2} +p{margin:0 0 .75rem} +ul{margin:0;padding-left:1.25rem} +dl{margin:0;display:grid;grid-template-columns:minmax(0,max-content) minmax(0,1fr);gap:.25rem 1rem} +dt{font-weight:600} +dd{margin:0} +footer{padding:1.5rem 0 2.5rem;color:#57606a;font-size:.9375rem} +@media (max-width:30rem){dl{grid-template-columns:minmax(0,1fr)}dd{margin-bottom:.5rem}} +`.trim(); + +function layout(locale: Locale, title: string, description: string, body: string): string { + return ` + + + + +${escapeHtml(title)} + + + + +${body} + + +`; +} + +export function renderHomePage(locale: Locale, m: Messages): string { + const e = escapeHtml; + const body = `
+
+

${e(m["site.name"])}

+

${e(m["site.tagline"])}

+
+
+
+
+

${e(m["about.heading"])}

+

${e(m["about.text"])}

+
+
+

${e(m["services.heading"])}

+

${e(m["services.text"])}

+
    +
  • ${e(m["services.item1"])}
  • +
  • ${e(m["services.item2"])}
  • +
  • ${e(m["services.item3"])}
  • +
+
+
+

${e(m["contacts.heading"])}

+

${e(m["contacts.text"])}

+
+
${e(m["contacts.phoneLabel"])}
${e(m["contacts.phone"])}
+
${e(m["contacts.emailLabel"])}
${e(m["contacts.email"])}
+
${e(m["contacts.addressLabel"])}
${e(m["contacts.address"])}
+
+
+
+
+
${e(m["footer.text"])}
+
`; + return layout(locale, m["meta.title"], m["meta.description"], body); +} + +export function renderNotFoundPage(locale: Locale, m: Messages): string { + const e = escapeHtml; + const body = `
+
+

${e(m["notFound.title"])}

+

${e(m["notFound.text"])}

+

${e(m["notFound.link"])}

+
+
`; + return layout(locale, m["notFound.title"], m["meta.description"], body); +} diff --git a/src/server.ts b/src/server.ts new file mode 100644 index 0000000..6ab1e90 --- /dev/null +++ b/src/server.ts @@ -0,0 +1,38 @@ +import { createServer, type Server } from "node:http"; +import { DEFAULT_LOCALE, type Locale, loadMessages } from "./i18n.ts"; +import { renderHomePage, renderNotFoundPage } from "./render.ts"; + +const HTML = "text/html; charset=utf-8"; + +export function createApp(locale: Locale = DEFAULT_LOCALE): Server { + const messages = loadMessages(locale); + const home = renderHomePage(locale, messages); + const notFound = renderNotFoundPage(locale, messages); + + return createServer((req, res) => { + const path = new URL(req.url ?? "/", "http://localhost").pathname; + const method = req.method ?? "GET"; + const headOnly = method === "HEAD"; + + if (method !== "GET" && method !== "HEAD") { + res.writeHead(405, { Allow: "GET, HEAD", "Content-Type": "text/plain; charset=utf-8" }); + res.end("Method Not Allowed"); + return; + } + if (path === "/healthz") { + res.writeHead(200, { + "Content-Type": "text/plain; charset=utf-8", + "Cache-Control": "no-store", + }); + res.end(headOnly ? undefined : "ok"); + return; + } + if (path === "/" || path === "/index.html") { + res.writeHead(200, { "Content-Type": HTML, "Cache-Control": "no-cache" }); + res.end(headOnly ? undefined : home); + return; + } + res.writeHead(404, { "Content-Type": HTML }); + res.end(headOnly ? undefined : notFound); + }); +} diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..469ac55 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "outDir": "dist", + "rootDir": "src" + }, + "include": ["src"] +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..1620908 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "target": "es2023", + "module": "nodenext", + "moduleResolution": "nodenext", + "strict": true, + "noUncheckedIndexedAccess": true, + "resolveJsonModule": true, + "verbatimModuleSyntax": true, + "erasableSyntaxOnly": true, + "allowImportingTsExtensions": true, + "rewriteRelativeImportExtensions": true, + "types": ["node"], + "skipLibCheck": true, + "noEmit": true + }, + "include": ["src", "test"] +}