designtopack/public/site/plugins/helpers/index.php
2024-12-20 07:19:46 +01:00

37 lines
No EOL
1.1 KiB
PHP

<?php
function getFileData($file) {
$data = [
'modified' => $file->modified('YYYY-MM-dd'),
'url' => $file->thumb([
'width' => 1000,
'quality' => 80,
'format' => 'webp'
])->url(),
'parent' => [
"title" => (string) $file->parent()->title(),
"uri" => $file->parent()->uri()
],
'uuid' => (string) $file->uuid(),
'name' => $file->filename(),
'label' => (string) $file->label(),
'type' => (string) $file->type(),
'cover' => $file->cover()->isNotEmpty() ? $file->cover()->toFile()->thumb([
'width' => 1000,
'quality' => 80,
'format' => 'webp'
])->url() : null
];
if ($file->description()->exists()) {
$data['description'] = $file->description()->value();
$data['tags'] = $file->tags()->split();
};
if($file->comments()->exists()) {
$data['comments'] = $file->comments()->exists() && $file->comments() ? Data::decode($file->comments()->value(), 'yaml') : [];
$data['cover'] = $file->cover()->exists() && $file->cover()->isNotEmpty() ? $file->cover()->toFile()->resize(576)->url() : false;
}
return $data;
}