Show more alternate titles on anime detail pages

This commit is contained in:
Timothy Warren 2020-05-06 09:08:27 -04:00
parent 48e51c816f
commit b806519b22
6 changed files with 40 additions and 5 deletions

View File

@ -45,7 +45,7 @@
</aside>
<article class="text">
<h2 class="toph"><a rel="external" href="<?= $data['url'] ?>"><?= $data['title'] ?></a></h2>
<?php foreach ($data['titles'] as $title): ?>
<?php foreach ($data['titles_more'] as $title): ?>
<h3><?= $title ?></h3>
<?php endforeach ?>
<br />

View File

@ -195,6 +195,23 @@ final class Kitsu {
return [];
}
/**
* Get the list of titles
*
* @param array $data
* @return array
*/
public static function getTitles(array $data): array
{
$raw = array_unique([
$data['canonicalTitle'],
...array_values($data['titles']),
...array_values($data['abbreviatedTitles']),
]);
return array_diff($raw,[$data['canonicalTitle']]);
}
/**
* Filter out duplicate and very similar names from
*
@ -217,6 +234,17 @@ final class Kitsu {
}
}
if (array_key_exists('abbreviatedTitles', $data))
{
foreach ($data['abbreviatedTitles'] as $alternateTitle)
{
if (self::titleIsUnique($alternateTitle, $valid))
{
$valid[] = $alternateTitle;
}
}
}
return $valid;
}

View File

@ -252,8 +252,8 @@ final class Model {
'fields' => [
'characters' => 'canonicalName,slug,image',
'characterVoices' => 'mediaCharacter',
'anime' => 'canonicalTitle,titles,slug,posterImage',
'manga' => 'canonicalTitle,titles,slug,posterImage',
'anime' => 'canonicalTitle,abbreviatedTitles,titles,slug,posterImage',
'manga' => 'canonicalTitle,abbreviatedTitles,titles,slug,posterImage',
'mediaCharacters' => 'role,media,character',
'mediaStaff' => 'role,media,person',
],

View File

@ -42,6 +42,7 @@ final class AnimeTransformer extends AbstractTransformer {
$title = $item['canonicalTitle'];
$titles = Kitsu::filterTitles($item);
$titles_more = Kitsu::getTitles($item);
$characters = [];
$staff = [];
@ -123,6 +124,7 @@ final class AnimeTransformer extends AbstractTransformer {
'synopsis' => $item['synopsis'],
'title' => $title,
'titles' => $titles,
'titles_more' => $titles_more,
'trailer_id' => $item['youtubeVideoId'],
'url' => "https://kitsu.io/anime/{$item['slug']}",
]);

View File

@ -97,6 +97,11 @@ class Anime extends AbstractType {
*/
public array $titles = [];
/**
* @var array
*/
public array $titles_more = [];
/**
* @var string
*/

View File

@ -23,10 +23,10 @@ final class AnimePage extends Anime {
/**
* @var array
*/
public $characters;
public array $characters = [];
/**
* @var array
*/
public $staff;
public array $staff = [];
}