diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 48a37396a89..540847ba417 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -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')); } } diff --git a/app/Models/User.php b/app/Models/User.php index c518d0e6f54..0f87deb6fda 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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) : '-', + ]), + 'global' => osu_trans('users.ogp.description.global', [ + 'rank' => $globalRank !== null ? '#' . i18n_number_format($globalRank) : '-', + ]), + 'mode' => $mode, + ]); + } + public function hasProfile() { return $this->getKey() !== null diff --git a/resources/lang/en/users.php b/resources/lang/en/users.php index b7b984785f4..939e0bb3905 100644 --- a/resources/lang/en/users.php +++ b/resources/lang/en/users.php @@ -123,6 +123,14 @@ ], ], + 'ogp' => [ + 'description' => [ + '_' => 'Rank (:mode): :global | :country', + 'country' => 'Country :rank', + 'global' => 'Global :rank', + ], + ], + 'posts' => [ 'title' => ':username\'s posts', ], diff --git a/resources/views/users/show.blade.php b/resources/views/users/show.blade.php index 6a1263a41d7..1135d912935 100644 --- a/resources/views/users/show.blade.php +++ b/resources/views/users/show.blade.php @@ -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,