From a4e537756caa9ef42bff0870fd439399def300aa Mon Sep 17 00:00:00 2001 From: maxitect Date: Fri, 13 Nov 2026 23:23:56 +0000 Subject: [PATCH 1/7] feat(calendar): serve the calendar at /calendrier in French and /calendar in English --- next.config.ts | 17 +++ src/app/(calendar)/_page/CalendarPage.tsx | 127 ++++++++++++++++++ .../{calendrier => }/_page/markup.ts | 14 +- .../{calendrier => }/_page/messages.ts | 4 + .../{calendrier => }/_page/openingSound.ts | 0 .../{calendrier => }/_page/script.ts | 0 .../{calendrier => }/_page/styles.ts | 1 + src/app/(calendar)/calendar/page.tsx | 5 + src/app/(calendar)/calendrier/page.tsx | 126 +---------------- src/lib/security/headers.ts | 1 + 10 files changed, 167 insertions(+), 128 deletions(-) create mode 100644 src/app/(calendar)/_page/CalendarPage.tsx rename src/app/(calendar)/{calendrier => }/_page/markup.ts (82%) rename src/app/(calendar)/{calendrier => }/_page/messages.ts (97%) rename src/app/(calendar)/{calendrier => }/_page/openingSound.ts (100%) rename src/app/(calendar)/{calendrier => }/_page/script.ts (100%) rename src/app/(calendar)/{calendrier => }/_page/styles.ts (99%) create mode 100644 src/app/(calendar)/calendar/page.tsx diff --git a/next.config.ts b/next.config.ts index 515e41c..65034a3 100644 --- a/next.config.ts +++ b/next.config.ts @@ -11,6 +11,22 @@ const nextConfig: NextConfig = { images: { remotePatterns: storageEndpoint ? [new URL(`${storageEndpoint}/**`)] : [], }, + async redirects() { + return [ + { + source: "/calendrier", + has: [{ type: "query", key: "isFrench", value: "false" }], + destination: "/calendar?", + permanent: false, + }, + { + source: "/calendar", + has: [{ type: "query", key: "isFrench", value: "true" }], + destination: "/calendrier?", + permanent: false, + }, + ]; + }, // Without a database the admin and Payload API stay hidden, as before Payload. async rewrites() { if (process.env.DATABASE_URL) return []; @@ -18,6 +34,7 @@ const nextConfig: NextConfig = { beforeFiles: [ { source: "/admin/:path*", destination: "/nope" }, { source: "/calendrier", destination: "/nope" }, + { source: "/calendar", destination: "/nope" }, { source: "/api/:path((?!send-emails$).*)", destination: "/nope", diff --git a/src/app/(calendar)/_page/CalendarPage.tsx b/src/app/(calendar)/_page/CalendarPage.tsx new file mode 100644 index 0000000..9d364af --- /dev/null +++ b/src/app/(calendar)/_page/CalendarPage.tsx @@ -0,0 +1,127 @@ +import { headers } from "next/headers"; +import { Suspense } from "react"; +import { + textNames, + type CalendarLocale, + type TextName, +} from "@/lib/calendar/defaults"; +import { getPublicState } from "@/lib/calendar/doors"; +import { accentFontOptions } from "@/lib/calendar/fontOptions"; +import { + accentFamilies, + bodyFamilies, + titleFamilies, +} from "@/lib/calendar/fonts"; +import { isMember } from "@/lib/calendar/member"; +import { + defaultDoorRows, + doorRowsCss, + sandColor, + themeVariables, +} from "@/lib/calendar/theme"; +import { calendarMarkup, holdingMarkup } from "./markup"; +import { getMessages } from "./messages"; +import { openingSoundUrl } from "./openingSound"; +import { calendarScript } from "./script"; +import { calendarCss } from "./styles"; + +interface PageProps { + locale: CalendarLocale; +} + +const SITE_URL = + process.env.NEXT_PUBLIC_SITE_URL || "https://clarksbowlingclub.com"; + +const paths = { fr: "/calendrier", en: "/calendar" } as const satisfies Record< + CalendarLocale, + string +>; + +const scriptJson = (value: unknown) => + JSON.stringify(value).replace(/(table: Record, key: string, fallback: Value) { + return Object.hasOwn(table, key) ? table[key] : fallback; +} + +async function Calendar({ locale }: PageProps) { + const requestHeaders = new Headers(await headers()); + const [{ settings, open }, member] = await Promise.all([ + getPublicState(), + isMember(requestHeaders), + ]); + const holding = !open && !member; + + const texts = Object.fromEntries( + textNames.map((name) => [ + name, + settings.texts[locale][name].replaceAll("{year}", String(settings.year)), + ]) + ) as Record; + const other = locale === "fr" ? "en" : "fr"; + const messages = getMessages(locale, texts); + + const accent = settings.fonts.accent; + const accentItalic = pick(accentFontOptions, accent, accentFontOptions.georgia).italic; + const fonts = [ + `--font-title:${pick(titleFamilies, settings.fonts.title, titleFamilies.georgia)}`, + `--font-accent:${pick(accentFamilies, accent, accentFamilies.georgia)}`, + `--font-body:${pick(bodyFamilies, settings.fonts.body, bodyFamilies.system)}`, + ].join(";"); + const css = calendarCss({ + vars: `${themeVariables(settings.colors)};${fonts}`, + background: settings.backgroundUrl + ? `url("${encodeURI(settings.backgroundUrl)}") center/cover fixed no-repeat,` + : "", + doorRows: doorRowsCss(settings.doorColors ?? defaultDoorRows(settings.colors)), + accentStyle: accentItalic ? "italic" : "normal", + }); + + const script = [ + `const M=${scriptJson(messages)},LANG=${scriptJson(locale)},YEAR=${settings.year};`, + "document.documentElement.lang=LANG;", + "const fill=(text,values)=>text.replace(/\\{(\\w+)\\}/g,(_,key)=>values[key]);", + calendarScript.replace("__OPENING_SOUND__", () => scriptJson(openingSoundUrl)), + ].join("\n"); + + const title = `${messages.title} ${messages.accentLine}`; + + return ( + <> + {title} + + + + + + + + {settings.shareUrl ? ( + <> + + + + ) : null} + {holding ? : null} +