world-game/site/templates/article.json.php
isUnknown 69859cc60f Refactor: snake_case → camelCase dans blueprints, templates et vues
- Blueprints : renommage des champs (member_name, related_articles,
  background_video, play_links, images_gallery, external_links) et
  des noms de sections
- Templates JSON PHP : clés de sortie et appels ->method() en camelCase
- Vues Svelte (Play, Portfolio) : accès aux données alignés

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 13:40:33 +01:00

34 lines
1 KiB
PHP

<?php
$related = $page->relatedArticles()->toPages();
if ($related->isEmpty()) {
$related = $page->siblings()->listed()->not($page)->shuffle()->limit(3);
}
$specificData = [
'date' => $page->date()->toDate('Y-m-d'),
'dateFormatted' => $page->date()->toDate('d/m/Y'),
'intro' => $page->intro()->value(),
'author' => [
'name' => $page->authorName()->value(),
'role' => $page->authorRole()->value(),
'photo' => $page->authorPhoto()->toFile()?->url()
],
'cover' => $page->cover()->toFile()?->url(),
'content' => $page->articleContent()->toBlocks(),
'tags' => $page->tags()->split(),
'related' => $related->map(function($rec) {
return [
'title' => $rec->title()->value(),
'url' => $rec->url(),
'category' => $rec->category()->value(),
'cover' => $rec->cover()->toFile()?->thumb(['width' => 400])->url()
];
})->values(),
'parentUrl' => $page->parent()->url()
];
$pageData = array_merge($genericData, $specificData);
header('Content-Type: application/json');
echo json_encode($pageData);