Update meta tags, improve descriptions and seo/og tags

This commit is contained in:
Daniel Supernault 2024-01-03 01:54:30 -07:00
parent 0ef6812709
commit fd44c80ce9
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1
4 changed files with 110 additions and 28 deletions

View File

@ -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;
}
}

View File

@ -12,9 +12,9 @@
<title>{{ $title ?? config_cache('app.name') }}</title>
<link rel="manifest" href="{{url('/manifest.json')}}">
<meta property="og:site_name" content="{{ config_cache('app.name') }}">
<meta property="og:title" content="{{ $title ?? config_cache('app.name') }}">
<meta property="og:type" content="article">
<meta property="og:site_name" content="Pixelfed">
<meta property="og:title" content="{{ $ogTitle ?? $title ?? config_cache('app.name') }}">
<meta property="og:type" content="{{ $ogType ?? 'article' }}">
<meta property="og:url" content="{{url(request()->url())}}">
@stack('meta')
@ -73,9 +73,9 @@
<title>{{ $title ?? config('app.name', 'Pixelfed') }}</title>
<link rel="manifest" href="/manifest.json">
<meta property="og:site_name" content="{{ config('app.name', 'pixelfed') }}">
<meta property="og:title" content="{{ $title ?? config('app.name', 'pixelfed') }}">
<meta property="og:type" content="article">
<meta property="og:site_name" content="Pixelfed">
<meta property="og:title" content="{{ $ogTitle ?? $title ?? config('app.name', 'pixelfed') }}">
<meta property="og:type" content="{{ $ogType ?? 'article' }}">
<meta property="og:url" content="{{url(request()->url())}}">
@stack('meta')

View File

@ -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
<profile profile-id="{{$profile->id}}" profile-username="{{$profile->username}}" :profile-settings="{{json_encode($settings)}}" profile-layout="metro"></profile>
@if($profile->website)
<a class="d-none" href="{{$profile->website}}" rel="me external nofollow noopener">{{$profile->website}}</a>
@endif
<noscript>
<div class="container">
@ -20,13 +26,20 @@
@endsection
@push('meta')<meta property="og:description" content="{{strip_tags($profile->bio)}}">
@if(false == $settings['crawlable'] || $profile->remote_url)
<meta name="robots" content="noindex, nofollow">
@else <meta property="og:image" content="{{$profile->avatarUrl()}}">
<link href="{{$profile->permalink('.atom')}}" rel="alternate" title="{{$profile->username}} on Pixelfed" type="application/atom+xml">
<link href='{{$profile->permalink()}}' rel='alternate' type='application/activity+json'>
@endif
@push('meta')<meta name="description" content="{{$metaDescription}}">
<meta property="og:description" content="{{$metaDescription}}">
<meta property="og:image" content="{{$profile->avatarUrl()}}">
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta property="twitter:card" content="summary">
<meta property="profile:username" content="{{$acct}}">
<link href="{{$profile->permalink('.atom')}}" rel="alternate" title="{{$profile->username}} on Pixelfed" type="application/atom+xml">
<link href="{{$profile->permalink()}}" rel="alternate" type="application/activity+json">
<meta name="application-name" content="Pixelfed">
<meta name="generator" content="pixelfed">
@if($profile->website)<link href="{{$profile->website}}" rel="me" type="text/html">
@endif
@if(false == $settings['crawlable'] || $profile->remote_url)<meta name="robots" content="noindex, nofollow">@endif
@endpush
@push('scripts')<script type="text/javascript" src="{{ mix('js/profile.js') }}"></script>

View File

@ -1,4 +1,30 @@
@extends('layouts.app',['title' => "{$user->username} shared a post"])
@extends('layouts.app', [
'title' => $desc ?? "{$user->username} shared a post",
'ogTitle' => $ogTitle
])
@php
$s = \App\Services\StatusService::get($status->id);
$displayName = $s && $s['account'] ? $s['account']['display_name'] : false;
$captionPreview = false;
$domain = $displayName ? '@' . parse_url($s['account']['url'], PHP_URL_HOST) : '';
$wf = $displayName ? $s['account']['username'] . $domain : '';
$ogTitle = $displayName ? $displayName . ' (@' . $s['account']['username'] . $domain . ')' : '';
$mediaCount = $s['media_attachments'] && count($s['media_attachments']) ? count($s['media_attachments']) : 0;
$mediaSuffix = $mediaCount < 2 ? '' : 's';
$ogDescription = $s['content_text'] ? $s['content_text'] : 'Attached: ' . $mediaCount . ' ' . $s['media_attachments'][0]['type'] . $mediaSuffix;
if($s['content_text']) {
$captionLen = strlen($s['content_text']);
$captionPreview = $captionLen > 40 ? substr($s['content_text'], 0, 40) . '…' : $s['content_text'];
}
$desc = false;
if($displayName && $captionPreview) {
$desc = $displayName . ': "' . $captionPreview . '" - Pixelfed';
} else if($displayName) {
$desc = $displayName . ': Shared a new post - Pixelfed';
}
@endphp
@section('content')
<noscript>
@ -7,20 +33,28 @@
</div>
</noscript>
<div class="mt-md-4"></div>
<post-component status-template="{{$status->viewType()}}" status-id="{{$status->id}}" status-username="{{$status->profile->username}}" status-url="{{$status->url()}}" status-profile-url="{{$status->profile->url()}}" status-avatar="{{$status->profile->avatarUrl()}}" status-profile-id="{{$status->profile_id}}" profile-layout="metro"></post-component>
<post-component
status-template="{{$status->viewType()}}"
status-id="{{$status->id}}"
status-username="{{$s['account']['username']}}"
status-url="{{$s['url']}}"
status-profile-url="{{$s['account']['url']}}"
status-avatar="{{$s['account']['avatar']}}"
status-profile-id="{{$status->profile_id}}"
profile-layout="metro" />
@endsection
@push('meta')
<meta property="og:description" content="{{ $status->caption }}">
<meta property="og:image" content="{{$status->thumb()}}">
<link href='{{$status->url()}}' rel='alternate' type='application/activity+json'>
<meta name="twitter:card" content="summary_large_image">
@if($status->viewType() == "video" || $status->viewType() == "video:album")
<meta property="og:video" content="{{$status->mediaUrl()}}">
@endif
@push('meta')@if($mediaCount && $s['pf_type'] === "photo" || $s['pf_type'] === "photo:album")
<meta property="og:image" content="{{$s['media_attachments'][0]['url']}}">
@elseif($mediaCount && $s['pf_type'] === "video" || $s['pf_type'] === "video:album")<meta property="og:video" content="{{$s['media_attachments'][0]['url']}}">
@endif<meta property="og:description" content="{{ $ogDescription }}">
<meta property="og:published_time" content="{{$s['created_at']}}">
<meta property="profile:username" content="{{ $wf }}">
<link href='{{$s['url']}}' rel='alternate' type='application/activity+json'>
<meta name="twitter:card" content="summary">
<meta name="description" content="{{ $ogDescription }}">
@endpush
@push('scripts')