world-game/site/templates/white-papers.json.php

27 lines
730 B
PHP
Raw Permalink Normal View History

<?php
$items = $page->children()->listed()->sortBy('published', 'desc');
$mapItem = function ($item) {
return [
'title' => $item->title()->value(),
'slug' => $item->slug(),
'published' => $item->published()->toDate('d/m/Y'),
'intro' => $item->intro()->value(),
'cover' => $item->cover()->toFile()?->url(),
];
};
$singleSlug = $items->count() === 1 ? $items->first()->slug() : null;
$specificData = [
'intro' => $page->intro()->value(),
'items' => $items->map($mapItem)->values(),
'singleSlug' => $singleSlug,
];
$pageData = array_merge($genericData, $specificData);
header('Content-Type: application/json');
echo json_encode($pageData);