35 lines
1 KiB
PHP
35 lines
1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
$related = $page->related_articles()->toPages();
|
||
|
|
if ($related->isEmpty()) {
|
||
|
|
$related = $page->siblings()->listed()->not($page)->shuffle()->limit(3);
|
||
|
|
}
|
||
|
|
|
||
|
|
$specificData = [
|
||
|
|
'date' => $page->date()->toDate('Y-m-d'),
|
||
|
|
'date_formatted' => $page->date()->toDate('d/m/Y'),
|
||
|
|
'intro' => $page->intro()->value(),
|
||
|
|
'author' => [
|
||
|
|
'name' => $page->author_name()->value(),
|
||
|
|
'role' => $page->author_role()->value(),
|
||
|
|
'photo' => $page->author_photo()->toFile()?->url()
|
||
|
|
],
|
||
|
|
'cover' => $page->cover()->toFile()?->url(),
|
||
|
|
'content' => $page->article_content()->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(),
|
||
|
|
'parent_url' => $page->parent()->url()
|
||
|
|
];
|
||
|
|
|
||
|
|
$pageData = array_merge($genericData, $specificData);
|
||
|
|
|
||
|
|
header('Content-Type: application/json');
|
||
|
|
echo json_encode($pageData);
|