fix: latest version

This commit is contained in:
2026-05-19 11:33:13 -04:00
parent a8c016d7b1
commit 1d5bb8bd90
5 changed files with 27 additions and 34 deletions

View File

@@ -44,40 +44,10 @@ declare global {
}
}
// WP's PHP serializer omits empty ACF fields, so sections coming from the CMS can
// be missing title/body/etc. Treat those missing-or-empty values as "fall back to
// the local content" instead of letting them blow up the React render.
function isEmptyValue(v: unknown): boolean {
if (v === null || v === undefined) return true;
if (typeof v === "string") return v === "";
if (Array.isArray(v)) return v.length === 0;
if (typeof v === "object") {
const obj = v as Record<string, unknown>;
if ("fr" in obj && "en" in obj) return !obj.fr && !obj.en;
}
return false;
}
function mergeSection(local: SectionBlock | undefined, wp: SectionBlock): SectionBlock {
if (!local || local.type !== wp.type) return wp;
const merged: Record<string, unknown> = { ...local };
for (const [key, val] of Object.entries(wp)) {
if (!isEmptyValue(val)) merged[key] = val;
}
return merged as unknown as SectionBlock;
}
export function PageRenderer({ page }: { page: PageContent }) {
const { t, locale } = useLocale();
const wpPage = window.__CASCA_PAGE__;
const wpSections = wpPage?.sections;
const renderedPage = wpSections?.length
? ({
...page,
...wpPage,
sections: wpSections.map((wpSec, i) => mergeSection(page.sections[i], wpSec)),
} as PageContent)
: page;
const renderedPage = wpPage?.sections?.length ? ({ ...page, ...wpPage } as PageContent) : page;
// Per-page SEO (title + description). React 19 will hoist these to <head>.
useEffect(() => {

View File

@@ -4,7 +4,15 @@ import { Calendar, MapPin } from "lucide-react";
function formatDate(iso: string, locale: "fr" | "en") {
const d = new Date(iso + "T00:00:00");
return iso;
try
{return new Intl.DateTimeFormat(locale === "fr" ? "fr-CA" : "en-CA", {
day: "numeric",
month: "long",
year: "numeric",
}).format(d);
} catch {
return iso;
}
}
export function EventsList({ block }: { block: EventsListBlock }) {