Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract opengraph methods #10655

Merged
merged 41 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
7df0115
add toOpengraph method
notbakaneko Oct 16, 2023
6a3bf2b
more toOpengraph methods
notbakaneko Oct 16, 2023
3e84b70
move shared descriptions
notbakaneko Oct 16, 2023
13d0101
add toOpengraph method for forum and topic show
notbakaneko Oct 16, 2023
d0c15f0
ogp description always same as meta description
notbakaneko Oct 16, 2023
12bb5cb
remove markdown/up from featured artist description; also don't put e…
notbakaneko Oct 16, 2023
e96033d
removing toMetaDescription
notbakaneko Oct 16, 2023
c24c508
add missing opengraph for beatmapset
notbakaneko Oct 16, 2023
83d9ac4
add more cover images to opengraph headers
notbakaneko Oct 16, 2023
72fd995
add more titles
notbakaneko Oct 16, 2023
6c50026
move opengraph stuff to separate classes; skip passing variable to view
notbakaneko Oct 19, 2023
92cb2fb
users.show.profile version of title not actually used on current site
notbakaneko Oct 20, 2023
1f6c85a
Merge branch 'master' into feature/opengraph-interface-2
notbakaneko Oct 23, 2023
23f63d0
add opengraph for comment
notbakaneko Oct 23, 2023
efe5cda
memoize message_html
notbakaneko Oct 23, 2023
7dbb641
wiki page opengraph
notbakaneko Oct 23, 2023
5927427
record excerpt from first text paragraph
notbakaneko Oct 25, 2023
cfdf270
no extra data for missing page
notbakaneko Oct 25, 2023
32e692f
single line
notbakaneko Oct 25, 2023
991b6e2
don't coalesce into self
notbakaneko Oct 25, 2023
c2b393f
non-model namespace can be problem for future (if at all)
notbakaneko Oct 25, 2023
bb95035
set only on current request
notbakaneko Oct 25, 2023
911d0f4
modding opengraph descriptions
notbakaneko Oct 25, 2023
bde5e30
single quotes
notbakaneko Oct 25, 2023
0bf535b
typo
notbakaneko Oct 30, 2023
078e18f
already escaped
notbakaneko Oct 30, 2023
6b5cef0
Revert "record excerpt from first text paragraph"
notbakaneko Oct 30, 2023
6188225
use the text-only searchable version for opengraph previews.
notbakaneko Oct 30, 2023
ada79a7
assume always guest for opengraph headers
notbakaneko Oct 30, 2023
6560b14
opengraph title doesn't override titlePrepend
notbakaneko Oct 30, 2023
9a9fc1d
remove username from description (standardized with profile info)
notbakaneko Nov 2, 2023
fb6f795
missing typehint
notbakaneko Nov 2, 2023
0bb17e0
add page_title to opengraph title by default;
notbakaneko Nov 2, 2023
68451af
rewrap in HtmlString after appending page_title
notbakaneko Nov 6, 2023
d2b1930
whoops
notbakaneko Nov 6, 2023
25afc43
shorter
notbakaneko Nov 6, 2023
7a7967f
unused
notbakaneko Nov 7, 2023
6f52526
remove page_title from og:site_name (which apparently is supposed to …
notbakaneko Nov 7, 2023
5c466b7
implemnent interface
notbakaneko Nov 7, 2023
b2f6727
remove kind of useless interface;
notbakaneko Nov 7, 2023
6911367
Merge branch 'master' into feature/opengraph-interface-2
nanaya Nov 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/Http/Controllers/ArtistsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public function show($id)
}
}

set_opengraph($artist);

return ext_view('artists.show', [
'artist' => $artist,
'images' => $images,
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/BeatmapsetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public function show($id)

$noindex = !$beatmapset->esShouldIndex();

set_opengraph($beatmapset);

return ext_view('beatmapsets.show', compact(
'beatmapset',
'commentBundle',
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/CommentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public function show($id)
return $commentBundle->toArray();
}

set_opengraph($comment);

return ext_view('comments.show', compact('commentBundle'));
}

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/ContestsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function show($id)
$contests = collect([$contest]);
}

set_opengraph($contest);

if ($contest->isVotingStarted()) {
if ($contest->isVotingOpen()) {
// TODO: add support for $contests requirement instead of at parent
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Forum/ForumsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public function show($id)

$noindex = !$forum->enable_indexing;

set_opengraph($forum);

return ext_view('forum.forums.show', compact(
'cover',
'forum',
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Forum/TopicsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public function show($id)

$posts->last()->markRead($currentUser);

$coverModel = $topic->cover()->firstOrNew([]);
$coverModel = $topic->cover ?? new TopicCover();
$coverModel->setRelation('topic', $topic);
$cover = json_item($coverModel, new TopicCoverTransformer());

Expand All @@ -438,6 +438,8 @@ public function show($id)
$featureVotes = $this->groupFeatureVotes($topic);
$noindex = !$topic->forum->enable_indexing;

set_opengraph($topic);

return ext_view('forum.topics.show', compact(
'canEditPoll',
'cover',
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public function show($slug)
return $postJson;
}

set_opengraph($post);

return ext_view('news.show', [
'commentBundle' => CommentBundle::forEmbed($post),
'post' => $post,
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Users/ModdingHistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function index()

$jsonChunks = ModdingHistoryEventsBundle::forProfile($user, $this->searchParams)->toArray();

set_opengraph($this->user, 'modding');

return ext_view('users.beatmapset_activities', compact(
'jsonChunks',
'user'
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Users/MultiplayerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function index($userId, $typeGroup)
return $json;
}

set_opengraph($user, 'multiplayer');

$jsonUser = json_item(
$user,
(new UserTransformer())->setMode($user->playmode),
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public function show($id, $mode = null)
abort(404);
}

// preload and set relation for toMetaDescription and transformer sharing data
// preload and set relation for opengraph header and transformer sharing data
$user->statistics($currentMode)?->setRelation('user', $user);

$userArray = $this->fillDeprecatedDuplicateFields(json_item(
Expand All @@ -654,9 +654,9 @@ public function show($id, $mode = null)
'user' => $userArray,
];

$pageDescription = blade_safe($user->toMetaDescription(['ruleset' => $currentMode]));
set_opengraph($user, 'show', $currentMode);

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

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/WikiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public function show($locale = null, $path = null)
return json_item($page, 'WikiPage');
}

set_opengraph($page);

return ext_view(
$page->template(),
['contentLocale' => $page->locale, 'page' => $page],
Expand Down
26 changes: 26 additions & 0 deletions app/Libraries/Opengraph/ArtistOpengraph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Libraries\Opengraph;

use App\Models\Artist;

class ArtistOpengraph implements OpengraphInterface
{
public function __construct(private Artist $artist)
{
}

public function get(): array
{
return [
'description' => first_paragraph(markdown_plain($this->artist->description)),
'image' => $this->artist->cover_url,
'title' => $this->artist->name,
];
}
}
29 changes: 29 additions & 0 deletions app/Libraries/Opengraph/BeatmapsetOpengraph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Libraries\Opengraph;

use App\Models\Beatmapset;

class BeatmapsetOpengraph implements OpengraphInterface
{
public function __construct(private Beatmapset $beatmapset)
{
}

public function get(): array
{
$section = osu_trans('layout.menu.beatmaps._');
$title = "{$this->beatmapset->artist} - {$this->beatmapset->title}"; // opengraph header always intended for guest.

return [
'description' => "osu! » {$section} » {$title}",
'image' => $this->beatmapset->coverURL('card'),
'title' => $title,
];
}
}
29 changes: 29 additions & 0 deletions app/Libraries/Opengraph/CommentOpengraph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Libraries\Opengraph;

use App\Models\Comment;

class CommentOpengraph implements OpengraphInterface
{
public function __construct(private Comment $comment)
{
}

public function get(): array
{
$user = $this->comment->user;

return priv_check_user(null, 'CommentShow', $this->comment)->can()
? [
'description' => blade_safe(html_excerpt($this->comment->message_html, 100)),
'image' => $user->user_avatar,
'title' => osu_trans('comments.ogp.title', ['user' => $user->username]),
] : [];
}
}
26 changes: 26 additions & 0 deletions app/Libraries/Opengraph/ContestOpengraph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Libraries\Opengraph;

use App\Models\Contest;

class ContestOpengraph implements OpengraphInterface
{
public function __construct(private Contest $contest)
{
}

public function get(): array
{
return [
'description' => strip_tags(markdown($this->contest->currentDescription())),
'image' => $this->contest->header_url,
'title' => $this->contest->name,
];
}
}
41 changes: 41 additions & 0 deletions app/Libraries/Opengraph/Forum/ForumOpengraph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Libraries\Opengraph\Forum;

use App\Libraries\Opengraph\OpengraphInterface;
use App\Models\Forum\Forum;

class ForumOpengraph implements OpengraphInterface
{
public function __construct(private Forum $forum)
{
}

// Reminder to update Topic::toOpengraph() as necessary if this value changes.
public function description(): string
{
$stack = [osu_trans('forum.title')];
foreach ($this->forum->forum_parents as $forumId => $forumData) {
$stack[] = $forumData[0];
}

$stack[] = $this->forum->forum_name;

return implode(' » ', $stack);
}

public function get(): array
{

return [
'description' => $this->description(),
'title' => $this->forum->forum_name,
'image' => $this->forum->cover?->fileUrl(),
];
}
}
29 changes: 29 additions & 0 deletions app/Libraries/Opengraph/Forum/TopicOpengraph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Libraries\Opengraph\Forum;

use App\Libraries\Opengraph\OpengraphInterface;
use App\Models\Forum\Topic;

class TopicOpengraph implements OpengraphInterface
{
public function __construct(private Topic $topic)
{
}

public function get(): array
{
$forumDescription = (new ForumOpengraph($this->topic->forum))->description();

return [
'description' => "{$forumDescription} » {$this->topic->topic_title}",
'image' => $this->topic->cover?->fileUrl() ?? $this->topic->forum->cover?->defaultTopicCover->fileUrl(),
'title' => $this->topic->topic_title,
];
}
}
26 changes: 26 additions & 0 deletions app/Libraries/Opengraph/NewsPostOpengraph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Libraries\Opengraph;

use App\Models\NewsPost;

class NewsPostOpengraph implements OpengraphInterface
{
public function __construct(private NewsPost $post)
{
}

public function get(): array
{
return [
'description' => $this->post->previewText(),
'image' => $this->post->firstImage(true),
'title' => $this->post->title(),
];
}
}
13 changes: 13 additions & 0 deletions app/Libraries/Opengraph/OpengraphInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Libraries\Opengraph;

interface OpengraphInterface
{
public function get(): array;
}
Loading