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");
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 }) {

View File

@@ -47,7 +47,7 @@ function cascapedia_st_jules_register_acf(): void {
acf_add_local_field_group([
'key' => 'group_document_fields',
'title' => 'Document',
'fields' => [ csj_file('field_document_file', 'document_file', 'PDF'), csj_text('field_document_group', 'document_group', 'Groupe'), csj_date('field_document_date', 'document_date', 'Date') ],
'fields' => [ csj_file('field_document_file', 'document_file', 'PDF'), csj_date('field_document_date', 'document_date', 'Date') ],
'location' => [[['param' => 'post_type', 'operator' => '==', 'value' => 'document']]],
]);
acf_add_local_field_group([

View File

@@ -26,4 +26,18 @@ function cascapedia_st_jules_register_content_types(): void {
'rewrite' => ['slug' => str_replace( '_', '-', $slug )],
] );
}
register_taxonomy( 'document_category', ['document'], [
'labels' => [
'name' => 'Catégories de documents',
'singular_name' => 'Catégorie de document',
'add_new_item' => 'Ajouter une catégorie de document',
'edit_item' => 'Modifier la catégorie de document',
],
'hierarchical' => true,
'public' => true,
'show_admin_column' => true,
'show_in_rest' => true,
'rewrite' => ['slug' => 'documents/categorie'],
] );
}

View File

@@ -67,7 +67,8 @@ function cascapedia_st_jules_get_documents(): array {
]);
$groups = [];
foreach ( $posts as $post ) {
$group = get_post_meta( $post->ID, 'document_group', true ) ?: __( 'Documents', 'cascapedia-st-jules' );
$terms = get_the_terms( $post, 'document_category' );
$group = ( ! is_wp_error( $terms ) && ! empty( $terms ) ) ? $terms[0]->name : __( 'Documents', 'cascapedia-st-jules' );
$file_id = (int) get_post_meta( $post->ID, 'document_file', true );
$href = $file_id ? wp_get_attachment_url( $file_id ) : '';
if ( ! $href ) {