120 lines
4.1 KiB
PHP
120 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Models\MusicProduction;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Support\Str;
|
|
|
|
class MusicProductionStructuredData extends StructuredData
|
|
{
|
|
public static function forIndex(LengthAwarePaginator $productions, string $pageUrl): array
|
|
{
|
|
$pageName = __('music_productions.meta-index-title');
|
|
$pageDescription = __('music_productions.meta-index-description');
|
|
|
|
$itemListElements = [];
|
|
$offset = ($productions->currentPage() - 1) * $productions->perPage();
|
|
|
|
foreach ($productions as $index => $production) {
|
|
$itemListElements[] = self::listItem(
|
|
$offset + $index + 1,
|
|
self::productionSchema($production),
|
|
);
|
|
}
|
|
|
|
return self::wrap([
|
|
self::websiteNode(route('music-productions.index') . '?q={search_term_string}'),
|
|
self::organizationNode(),
|
|
self::webPageNode($pageUrl, $pageName, $pageDescription, [
|
|
'@type' => 'CollectionPage',
|
|
'mainEntity' => ['@id' => $pageUrl . '#itemlist'],
|
|
]),
|
|
self::breadcrumbNode($pageUrl, [
|
|
['name' => __('music_productions.breadcrumb_home'), 'item' => self::siteUrl()],
|
|
['name' => __('music_productions.nav-music-productions'), 'item' => route('music-productions.index')],
|
|
]),
|
|
[
|
|
'@type' => 'ItemList',
|
|
'@id' => $pageUrl . '#itemlist',
|
|
'name' => $pageName,
|
|
'numberOfItems' => $productions->total(),
|
|
'itemListElement' => $itemListElements,
|
|
],
|
|
]);
|
|
}
|
|
|
|
public static function forShow(MusicProduction $production, string $pageUrl): array
|
|
{
|
|
$title = $production->translate('title');
|
|
$description = Str::limit(strip_tags((string) $production->translate('content')), 160);
|
|
|
|
$webPageExtra = [
|
|
'mainEntity' => ['@id' => $pageUrl . '#production'],
|
|
];
|
|
|
|
if ($production->updated_at) {
|
|
$webPageExtra['dateModified'] = $production->updated_at->toIso8601String();
|
|
}
|
|
|
|
return self::wrap([
|
|
self::websiteNode(route('music-productions.index') . '?q={search_term_string}'),
|
|
self::organizationNode(),
|
|
self::webPageNode($pageUrl, $title, $description, $webPageExtra),
|
|
self::breadcrumbNode($pageUrl, [
|
|
['name' => __('music_productions.breadcrumb_home'), 'item' => self::siteUrl()],
|
|
['name' => __('music_productions.nav-music-productions'), 'item' => route('music-productions.index')],
|
|
['name' => $title, 'item' => $pageUrl],
|
|
]),
|
|
array_merge(
|
|
['@id' => $pageUrl . '#production'],
|
|
self::productionSchema($production),
|
|
),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
protected static function productionSchema(MusicProduction $production): array
|
|
{
|
|
$schema = [
|
|
'@type' => filled($production->spotify_album_id) ? 'MusicAlbum' : 'CreativeWork',
|
|
'name' => $production->translate('title'),
|
|
'url' => route('music-productions.show', $production->slug),
|
|
];
|
|
|
|
if ($production->cover_image_url) {
|
|
$schema['image'] = [$production->cover_image_url];
|
|
}
|
|
|
|
$content = strip_tags((string) $production->translate('content'));
|
|
if ($content !== '') {
|
|
$schema['description'] = Str::limit($content, 300);
|
|
}
|
|
|
|
if ($production->production_date) {
|
|
$schema['datePublished'] = $production->production_date->toIso8601String();
|
|
}
|
|
|
|
$clientName = $production->translate('client_name');
|
|
if ($clientName) {
|
|
$schema['creator'] = [
|
|
'@type' => 'Organization',
|
|
'name' => $clientName,
|
|
];
|
|
}
|
|
|
|
$sameAs = array_values(array_filter([
|
|
$production->spotify_url,
|
|
$production->youtube_url,
|
|
]));
|
|
|
|
if ($sameAs !== []) {
|
|
$schema['sameAs'] = $sameAs;
|
|
}
|
|
|
|
return $schema;
|
|
}
|
|
}
|