Skip to content

Commit 2c605da

Browse files
committed
refactor(Sanitizer): improve artist names display
- Enhance artist names output by limiting the display to a maximum of three artists - Add ellipsis (...) to indicate additional artists when more than three are present - Improve code readability with the use of collection methods
1 parent 67bb221 commit 2c605da

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

app/Concerns/Sanitizer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ public function sanitize(array $song, string $keyword): array
3838
{
3939
$song = Arr::only($song, ['name', 'artist', 'album', 'source', 'size', 'br']);
4040
$song['name'] = str_replace($keyword, "<fg=red;options=bold>$keyword</>", (string) $song['name']);
41-
$song['artist'] = str_replace($keyword, "<fg=red;options=bold>$keyword</>", implode(',', $song['artist']));
41+
$song['artist'] = str_replace(
42+
$keyword,
43+
"<fg=red;options=bold>$keyword</>",
44+
collect($song['artist'])
45+
->when(
46+
\count($song['artist']) > 3,
47+
static fn (Collection $artist): Collection => $artist->take(3)->push('...')
48+
)
49+
->implode(',')
50+
);
4251
$song['album'] = str_replace($keyword, "<fg=red;options=bold>$keyword</>", (string) $song['album']);
4352
$song['size'] = isset($song['size']) ? \sprintf('<fg=yellow>%s</>', Number::fileSize((float) $song['size'], 1)) : null;
4453
$song['br'] = (int) $song['br'];

0 commit comments

Comments
 (0)