progmaweb
The site and account service of Progmasoft: a Next.js frontend and an ASP.NET Core API.
Clonegit clone https://git.progmasoft.com/progmaweb
Give an unknown address a page of the site, in the visitor's language
- Commit
0036d3f1348f13dda83f97cba8a0a135abe5a7da- Author
- Leitwolf11 ·
- Parents
477625cd75db
Changes
apps/web/app/not-found.tsx | 36 +++++++++++++++++++++++++ apps/web/app/products/[slug]/page.tsx | 11 +++++--- apps/web/app/site.css | 23 ++++++++++++++++ apps/web/e2e/not-found.spec.ts | 51 +++++++++++++++++++++++++++++++++++ apps/web/lib/localization.ts | 20 ++++++++++++++ 5 files changed, 138 insertions(+), 3 deletions(-) diff --git a/apps/web/app/not-found.tsx b/apps/web/app/not-found.tsx new file mode 100644 index 0000000..f6c510a --- /dev/null +++ b/apps/web/app/not-found.tsx @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com> +// SPDX-License-Identifier: AGPL-3.0-or-later + +import type { Metadata } from "next"; +import { Footer } from "@/components/Footer"; +import { SiteHeader } from "@/components/SiteHeader"; +import { getLocale } from "@/lib/locale.server"; +import { getMessages } from "@/lib/localization"; +import "./site.css"; + +export async function generateMetadata(): Promise<Metadata> { + const { notFound } = getMessages(await getLocale()); + return { title: notFound.pageTitle, robots: { index: false } }; +} + +/** + * What every host of the site shows for an address it has no page for: the + * header and the footer of the site around one sentence, in the language of + * the visitor, with the status 404. + */ +export default async function NotFound() { + const locale = await getLocale(); + const { notFound } = getMessages(locale); + return ( + <div className="pm-page"> + <SiteHeader locale={locale} /> + <main className="pm-not-found"> + <div className="pm-shell"> + <h1>{notFound.title}</h1> + <p>{notFound.text}</p> + </div> + </main> + <Footer locale={locale} /> + </div> + ); +} diff --git a/apps/web/app/products/[slug]/page.tsx b/apps/web/app/products/[slug]/page.tsx index 664278b..311810d 100644 --- a/apps/web/app/products/[slug]/page.tsx +++ b/apps/web/app/products/[slug]/page.tsx @@ -10,7 +10,7 @@ import { StatusBadge, } from "@/components/ProductCatalog"; import { getLocale } from "@/lib/locale.server"; -import { forwardArrow } from "@/lib/localization"; +import { forwardArrow, getMessages } from "@/lib/localization"; import { getCatalogMessages, isProductSlug, products } from "@/lib/products"; interface ProductPageProps { @@ -21,10 +21,15 @@ export async function generateMetadata({ params, }: ProductPageProps): Promise<Metadata> { const { slug } = await params; + const locale = await getLocale(); if (!isProductSlug(slug)) { - return {}; + // The page answers with the not-found page; its title says so too. + return { + title: getMessages(locale).notFound.pageTitle, + robots: { index: false }, + }; } - const catalog = getCatalogMessages(await getLocale()); + const catalog = getCatalogMessages(locale); return { title: `${products[slug].name} · ${catalog.categories[products[slug].category]}`, description: catalog.products[slug].description, diff --git a/apps/web/app/site.css b/apps/web/app/site.css index 58106e3..93df053 100644 --- a/apps/web/app/site.css +++ b/apps/web/app/site.css @@ -565,3 +565,26 @@ padding-top: 24px; border-top: 1px solid var(--line); } + +/* The page of an address the site has none for: one sentence in the middle of the page. */ +.pm-not-found { + display: grid; + min-height: 60vh; + align-items: center; + padding-block: 96px; + text-align: center; +} + +.pm-not-found h1 { + margin: 0 auto; + max-width: 980px; + font-size: clamp(1.9rem, 4vw, 2.6rem); + letter-spacing: -0.02em; + line-height: 1.2; +} + +.pm-not-found p { + margin: 18px auto 0; + max-width: 640px; + color: var(--ink-650); +} diff --git a/apps/web/e2e/not-found.spec.ts b/apps/web/e2e/not-found.spec.ts new file mode 100644 index 0000000..7be30f5 --- /dev/null +++ b/apps/web/e2e/not-found.spec.ts @@ -0,0 +1,51 @@ +// SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com> +// SPDX-License-Identifier: AGPL-3.0-or-later + +import { expect, test } from "@playwright/test"; + +const hosts = [ + "progmasoft.com", + "account.progmasoft.com", + "viget.progmasoft.com", + "product.progmasoft.com", +]; + +for (const host of hosts) { + test(`${host} answers an unknown address with its own page and 404`, async ({ + page, + }) => { + const response = await page.goto(`http://${host}/example.txt`); + expect(response?.status()).toBe(404); + await expect(page.locator("h1")).toHaveText( + "We are sorry, the page you requested cannot be found.", + ); + await expect(page.locator("header.site-header")).toBeVisible(); + await expect(page.locator("footer.site-footer")).toBeVisible(); + expect(await page.locator("title").count()).toBe(1); + await expect(page).toHaveTitle("Page not found · Progmasoft"); + const overflow = await page.evaluate( + () => + document.documentElement.scrollWidth - + document.documentElement.clientWidth, + ); + expect(overflow).toBe(0); + }); +} + +test("the page of an unknown address speaks the visitor's language", async ({ + page, + context, +}) => { + await context.addCookies([ + { + name: "progmasoft_locale", + value: "de-DE", + domain: ".progmasoft.com", + path: "/", + }, + ]); + await page.goto("http://viget.progmasoft.com/nope"); + await expect(page.locator("h1")).toHaveText( + "Es tut uns leid, die angeforderte Seite wurde nicht gefunden.", + ); +}); diff --git a/apps/web/lib/localization.ts b/apps/web/lib/localization.ts index f2a012f..e1c1c83 100644 --- a/apps/web/lib/localization.ts +++ b/apps/web/lib/localization.ts @@ -163,6 +163,11 @@ export const messages = { dark: "Dark", language: "Language", }, + notFound: { + title: "We are sorry, the page you requested cannot be found.", + text: "The address may be misspelled, or the page you are looking for is no longer available.", + pageTitle: "Page not found", + }, footer: { summary: "Developer tools and data infrastructure built with durable contracts.", @@ -424,6 +429,11 @@ export const messages = { dark: "Dunkel", language: "Sprache", }, + notFound: { + title: "Es tut uns leid, die angeforderte Seite wurde nicht gefunden.", + text: "Die Adresse ist vielleicht falsch geschrieben, oder die gesuchte Seite ist nicht mehr verfügbar.", + pageTitle: "Seite nicht gefunden", + }, footer: { summary: "Entwicklerwerkzeuge und Dateninfrastruktur auf der Grundlage beständiger Verträge.", @@ -689,6 +699,11 @@ export const messages = { dark: "Тёмная", language: "Язык", }, + notFound: { + title: "К сожалению, запрошенная страница не найдена.", + text: "Возможно, адрес написан с ошибкой или страница, которую вы ищете, больше недоступна.", + pageTitle: "Страница не найдена", + }, footer: { summary: "Инструменты разработчика и инфраструктура данных, построенные на надёжных контрактах.", @@ -953,6 +968,11 @@ export const messages = { dark: "כהה", language: "שפה", }, + notFound: { + title: "מצטערים, הדף שביקשת לא נמצא.", + text: "ייתכן שהכתובת שגויה, או שהדף שחיפשת כבר אינו זמין.", + pageTitle: "הדף לא נמצא", + }, footer: { summary: "כלי פיתוח ותשתית נתונים, הבנויים על חוזים יציבים.", products: "מוצרים",