Skip to content

Commit

Permalink
shorter display
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko committed Sep 20, 2023
1 parent 5f27f16 commit 1f63630
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
4 changes: 3 additions & 1 deletion app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,9 @@ public function show($id, $mode = null)
'user' => $userArray,
];

return ext_view('users.show', compact('currentMode', 'initialData', 'user'));
$pageDescription = $user->toMetaDescription(['mode' => $currentMode]);

return ext_view('users.show', compact('initialData', 'pageDescription', 'user'));
}
}

Expand Down
22 changes: 22 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,28 @@ public function titleUrl(): ?string
return $this->rank?->url;
}

public function toMetaDescription(array $options = []): ?string
{
$mode = $options['mode'] ?? $this->playmode;
$stats = $this->statistics($mode);
if ($stats === null) {
return null;
}

$countryRank = $stats->countryRank();
$globalRank = $stats->globalRank();

return osu_trans('users.ogp.description._', [
'country' => osu_trans('users.ogp.description.country', [
'rank' => $countryRank !== null ? '#' . i18n_number_format($countryRank) : '-',

Check failure on line 1830 in app/Models/User.php

View workflow job for this annotation

GitHub Actions / Lint all

Concat operator must not be surrounded by spaces
]),
'global' => osu_trans('users.ogp.description.global', [
'rank' => $globalRank !== null ? '#' . i18n_number_format($globalRank) : '-',

Check failure on line 1833 in app/Models/User.php

View workflow job for this annotation

GitHub Actions / Lint all

Concat operator must not be surrounded by spaces
]),
'mode' => $mode,
]);
}

public function hasProfile()
{
return $this->getKey() !== null
Expand Down
8 changes: 8 additions & 0 deletions resources/lang/en/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@
],
],

'ogp' => [
'description' => [
'_' => 'Rank (:mode): :global | :country',
'country' => 'Country :rank',
'global' => 'Global :rank',
],
],

'posts' => [
'title' => ':username\'s posts',
],
Expand Down
18 changes: 1 addition & 17 deletions resources/views/users/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,10 @@
See the LICENCE file in the repository root for full licence text.
--}}

@php
$userJson = $initialData['user'];
$stats = $initialData['user']['statistics'];
$globalRank = $stats['global_rank'] ?? null;
$countryRank = $stats['country_rank'] ?? null;
$rankDescriptions = [];
if ($globalRank !== null) {
$rankDescriptions[] = trans('users.show.rank.global', ['mode' => $currentMode]) . ': #' . i18n_number_format($globalRank);
}
if ($countryRank !== null) {
$rankDescriptions[] = trans('users.show.rank.country', ['mode' => $currentMode]) . ': #' . i18n_number_format($countryRank);
}
@endphp

@extends('master', [
'canonicalUrl' => $user->url(),
'titlePrepend' => blade_safe(str_replace(' ', ' ', e($user->username))),
'pageDescription' => presence(implode(', ', $rankDescriptions)),
'pageDescription' => $pageDescription,
'opengraph' => [
'title' => trans('users.show.title', ['username' => $user->username]),
'image' => $user->user_avatar,
Expand Down

0 comments on commit 1f63630

Please sign in to comment.