From fd44c80ce9723cf91ece4767539f0c503b2f833f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 3 Jan 2024 01:54:30 -0700 Subject: [PATCH 1/2] Update meta tags, improve descriptions and seo/og tags --- app/Services/AccountService.php | 35 ++++++++++++++++ resources/views/layouts/app.blade.php | 12 +++--- resources/views/profile/show.blade.php | 35 +++++++++++----- resources/views/status/show.blade.php | 56 +++++++++++++++++++++----- 4 files changed, 110 insertions(+), 28 deletions(-) diff --git a/app/Services/AccountService.php b/app/Services/AccountService.php index 98e878845..5ffc1e9b5 100644 --- a/app/Services/AccountService.php +++ b/app/Services/AccountService.php @@ -13,6 +13,7 @@ use League\Fractal; use League\Fractal\Serializer\ArraySerializer; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; +use \NumberFormatter; class AccountService { @@ -244,4 +245,38 @@ class AccountService return UserDomainBlock::whereProfileId($pid)->whereDomain($domain)->exists(); } + + public static function formatNumber($num) { + if(!$num || $num < 1) { + return "0"; + } + $num = intval($num); + $formatter = new NumberFormatter('en_US', NumberFormatter::DECIMAL); + $formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, 1); + + if ($num >= 1000000000) { + return $formatter->format($num / 1000000000) . 'B'; + } else if ($num >= 1000000) { + return $formatter->format($num / 1000000) . 'M'; + } elseif ($num >= 1000) { + return $formatter->format($num / 1000) . 'K'; + } else { + return $formatter->format($num); + } + } + + public static function getMetaDescription($id) + { + $account = self::get($id, true); + + if(!$account) return ""; + + $posts = self::formatNumber($account['statuses_count']) . ' Posts, '; + $following = self::formatNumber($account['following_count']) . ' Following, '; + $followers = self::formatNumber($account['followers_count']) . ' Followers'; + $note = $account['note'] && strlen($account['note']) ? + ' · ' . \Purify::clean(strip_tags(str_replace("\n", '', str_replace("\r", '', $account['note'])))) : + ''; + return $posts . $following . $followers . $note; + } } diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 94f90ed97..0136842bb 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -12,9 +12,9 @@ {{ $title ?? config_cache('app.name') }} - - - + + + @stack('meta') @@ -73,9 +73,9 @@ {{ $title ?? config('app.name', 'Pixelfed') }} - - - + + + @stack('meta') diff --git a/resources/views/profile/show.blade.php b/resources/views/profile/show.blade.php index 5107c0ab3..dfa8edabb 100644 --- a/resources/views/profile/show.blade.php +++ b/resources/views/profile/show.blade.php @@ -1,4 +1,13 @@ -@extends('layouts.app',['title' => $profile->username . " on " . config('app.name')]) +@extends('layouts.app', [ + 'title' => $profile->name . ' (@' . $acct . ') - Pixelfed', + 'ogTitle' => $profile->name . ' (@' . $acct . ')', + 'ogType' => 'profile' +]) + +@php +$acct = $profile->username . '@' . config('pixelfed.domain.app'); +$metaDescription = \App\Services\AccountService::getMetaDescription($profile->id); +@endphp @section('content') @if (session('error')) @@ -8,9 +17,6 @@ @endif -@if($profile->website) -{{$profile->website}} -@endif
- + @endsection -@push('meta') - - - - - - @if($status->viewType() == "video" || $status->viewType() == "video:album") - - @endif +@push('meta')@if($mediaCount && $s['pf_type'] === "photo" || $s['pf_type'] === "photo:album") + + @elseif($mediaCount && $s['pf_type'] === "video" || $s['pf_type'] === "video:album") + @endif + + + + + @endpush @push('scripts') From 5087a878854cb30b147e527985bb89e5180dfb4f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 3 Jan 2024 02:00:47 -0700 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10b13f261..13baca035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,7 @@ - Update AdminShadowFilter, fix deleted profile bug ([a492a95a](https://github.com/pixelfed/pixelfed/commit/a492a95a)) - Update FollowerService, add $silent param to remove method to more efficently purge relationships ([1664a5bc](https://github.com/pixelfed/pixelfed/commit/1664a5bc)) - Update AP ProfileTransformer, add published attribute ([adfaa2b1](https://github.com/pixelfed/pixelfed/commit/adfaa2b1)) +- Update meta tags, improve descriptions and seo/og tags ([fd44c80c](https://github.com/pixelfed/pixelfed/commit/fd44c80c)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.9 (2023-08-21)](https://github.com/pixelfed/pixelfed/compare/v0.11.8...v0.11.9)