mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-25 15:55:22 +00:00
Update meta tags, improve descriptions and seo/og tags
This commit is contained in:
parent
0ef6812709
commit
fd44c80ce9
4 changed files with 110 additions and 28 deletions
|
@ -13,6 +13,7 @@ use League\Fractal;
|
||||||
use League\Fractal\Serializer\ArraySerializer;
|
use League\Fractal\Serializer\ArraySerializer;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use \NumberFormatter;
|
||||||
|
|
||||||
class AccountService
|
class AccountService
|
||||||
{
|
{
|
||||||
|
@ -244,4 +245,38 @@ class AccountService
|
||||||
|
|
||||||
return UserDomainBlock::whereProfileId($pid)->whereDomain($domain)->exists();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
<title>{{ $title ?? config_cache('app.name') }}</title>
|
<title>{{ $title ?? config_cache('app.name') }}</title>
|
||||||
<link rel="manifest" href="{{url('/manifest.json')}}">
|
<link rel="manifest" href="{{url('/manifest.json')}}">
|
||||||
|
|
||||||
<meta property="og:site_name" content="{{ config_cache('app.name') }}">
|
<meta property="og:site_name" content="Pixelfed">
|
||||||
<meta property="og:title" content="{{ $title ?? config_cache('app.name') }}">
|
<meta property="og:title" content="{{ $ogTitle ?? $title ?? config_cache('app.name') }}">
|
||||||
<meta property="og:type" content="article">
|
<meta property="og:type" content="{{ $ogType ?? 'article' }}">
|
||||||
<meta property="og:url" content="{{url(request()->url())}}">
|
<meta property="og:url" content="{{url(request()->url())}}">
|
||||||
@stack('meta')
|
@stack('meta')
|
||||||
|
|
||||||
|
@ -73,9 +73,9 @@
|
||||||
<title>{{ $title ?? config('app.name', 'Pixelfed') }}</title>
|
<title>{{ $title ?? config('app.name', 'Pixelfed') }}</title>
|
||||||
<link rel="manifest" href="/manifest.json">
|
<link rel="manifest" href="/manifest.json">
|
||||||
|
|
||||||
<meta property="og:site_name" content="{{ config('app.name', 'pixelfed') }}">
|
<meta property="og:site_name" content="Pixelfed">
|
||||||
<meta property="og:title" content="{{ $title ?? config('app.name', 'pixelfed') }}">
|
<meta property="og:title" content="{{ $ogTitle ?? $title ?? config('app.name', 'pixelfed') }}">
|
||||||
<meta property="og:type" content="article">
|
<meta property="og:type" content="{{ $ogType ?? 'article' }}">
|
||||||
<meta property="og:url" content="{{url(request()->url())}}">
|
<meta property="og:url" content="{{url(request()->url())}}">
|
||||||
@stack('meta')
|
@stack('meta')
|
||||||
|
|
||||||
|
|
|
@ -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')
|
@section('content')
|
||||||
@if (session('error'))
|
@if (session('error'))
|
||||||
|
@ -8,9 +17,6 @@
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<profile profile-id="{{$profile->id}}" profile-username="{{$profile->username}}" :profile-settings="{{json_encode($settings)}}" profile-layout="metro"></profile>
|
<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>
|
<noscript>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -20,13 +26,20 @@
|
||||||
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@push('meta')<meta property="og:description" content="{{strip_tags($profile->bio)}}">
|
@push('meta')<meta name="description" content="{{$metaDescription}}">
|
||||||
@if(false == $settings['crawlable'] || $profile->remote_url)
|
<meta property="og:description" content="{{$metaDescription}}">
|
||||||
<meta name="robots" content="noindex, nofollow">
|
<meta property="og:image" content="{{$profile->avatarUrl()}}">
|
||||||
@else <meta property="og:image" content="{{$profile->avatarUrl()}}">
|
<meta property="og:image:width" content="200">
|
||||||
<link href="{{$profile->permalink('.atom')}}" rel="alternate" title="{{$profile->username}} on Pixelfed" type="application/atom+xml">
|
<meta property="og:image:height" content="200">
|
||||||
<link href='{{$profile->permalink()}}' rel='alternate' type='application/activity+json'>
|
<meta property="twitter:card" content="summary">
|
||||||
@endif
|
<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
|
@endpush
|
||||||
|
|
||||||
@push('scripts')<script type="text/javascript" src="{{ mix('js/profile.js') }}"></script>
|
@push('scripts')<script type="text/javascript" src="{{ mix('js/profile.js') }}"></script>
|
||||||
|
|
|
@ -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')
|
@section('content')
|
||||||
<noscript>
|
<noscript>
|
||||||
|
@ -7,20 +33,28 @@
|
||||||
</div>
|
</div>
|
||||||
</noscript>
|
</noscript>
|
||||||
<div class="mt-md-4"></div>
|
<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
|
@endsection
|
||||||
|
|
||||||
@push('meta')
|
@push('meta')@if($mediaCount && $s['pf_type'] === "photo" || $s['pf_type'] === "photo:album")
|
||||||
|
<meta property="og:image" content="{{$s['media_attachments'][0]['url']}}">
|
||||||
<meta property="og:description" content="{{ $status->caption }}">
|
@elseif($mediaCount && $s['pf_type'] === "video" || $s['pf_type'] === "video:album")<meta property="og:video" content="{{$s['media_attachments'][0]['url']}}">
|
||||||
<meta property="og:image" content="{{$status->thumb()}}">
|
@endif<meta property="og:description" content="{{ $ogDescription }}">
|
||||||
<link href='{{$status->url()}}' rel='alternate' type='application/activity+json'>
|
<meta property="og:published_time" content="{{$s['created_at']}}">
|
||||||
<meta name="twitter:card" content="summary_large_image">
|
<meta property="profile:username" content="{{ $wf }}">
|
||||||
@if($status->viewType() == "video" || $status->viewType() == "video:album")
|
<link href='{{$s['url']}}' rel='alternate' type='application/activity+json'>
|
||||||
<meta property="og:video" content="{{$status->mediaUrl()}}">
|
<meta name="twitter:card" content="summary">
|
||||||
@endif
|
<meta name="description" content="{{ $ogDescription }}">
|
||||||
@endpush
|
@endpush
|
||||||
|
|
||||||
@push('scripts')
|
@push('scripts')
|
||||||
|
|
Loading…
Reference in a new issue