-
Notifications
You must be signed in to change notification settings - Fork 382
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
Extract opengraph methods #10655
Conversation
factory since only metadata view needs it.
I'm skipping reviewing the other one |
Adding per beatmap opengraph on the beatmapset url isn't currently possible as the beatmap portion of the url is part of the fragment and client-side; |
app/helpers.php
Outdated
@@ -1690,6 +1691,15 @@ function seeded_shuffle(array &$items, int $seed = 0) | |||
mt_srand(); | |||
} | |||
|
|||
function set_opengraph(HasOpengraph $model, ...$options) | |||
{ | |||
$className = 'App\\Libraries\\Opengraph\\'.get_class_basename(get_class($model)).'Opengraph'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use plain replace otherwise models in subdirectory will be structured wrong (like the wiki page).
also, there's $model::class
@@ -6,6 +6,8 @@ | |||
$appUrl = config('app.url'); | |||
$currentLocale = App::getLocale(); | |||
$fallbackLocale = config('app.fallback_locale'); | |||
|
|||
$opengraph['description'] ??= $opengraph['description'] ?? $pageDescription ?? null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant $opengraph['description']
app/Models/Comment.php
Outdated
|
||
private function getMessageHtml(): ?string | ||
{ | ||
return $this->memoize(__FUNCTION__, function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use shorter fn
?
|
||
return [ | ||
// TODO: need a way to mark which wiki text to use as excerpt; first_paragraph just returns the title on wiki. | ||
'description' => html_excerpt($this->page->get()['output']), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error on nonexistent page
app/helpers.php
Outdated
View::share([ | ||
'opengraph' => (new $className($model, ...$options))->get(), | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be reset after each request because the value persists to the next requests until overwritten
resources/lang/en/users.php
Outdated
@@ -124,6 +124,9 @@ | |||
], | |||
|
|||
'ogp' => [ | |||
'modding_description' => ':user\'s beatmaps: :counts', | |||
'modding_description_empty' => ':user doesn\'t have nay beatmaps...', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any
{ | ||
$user = $this->comment->user; | ||
|
||
return priv_check('CommentShow', $this->comment)->can() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
priv_check_user with null user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
originally, I had everything assume opengrapgh would be viewed only by null
user, but if you go to the page with a deleted comment as a moderator, you see a different thing, so I'm not so sure now 👀
|
||
return priv_check('CommentShow', $this->comment)->can() | ||
? [ | ||
'description' => html_excerpt($this->comment->message_html, 100), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blade_safe
? return of html_excerpt
is already escaped
although I noticed discord double unescape description by default 🤔 and twitter is even worse
$pageData = $this->page->get(); | ||
|
||
return [ | ||
'description' => $pageData['excerpt'] ?? html_excerpt($pageData['output']), // html_excerpt fallback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another one needing blade_safe
@@ -263,6 +269,15 @@ private function proxyImage() | |||
} | |||
} | |||
|
|||
private function recordExcerpt(): void | |||
{ | |||
if ($this->excerpt !== null || !$this->node instanceof Paragraph || !$this->event->isEntering()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with first two paragraphs may not even contain actual content I wonder if it's better to just show first 100 characters instead.
This reverts commit 5927427.
The downside is it makes elasticsearch return more text that we don't need
site_name isn't displayed on most cards, also apparently should just be "osu!"?
@php | ||
if ($key === 'title') { | ||
$isHtmlString = $value instanceof HtmlString; | ||
$value .= ' · '.page_title(); | ||
if ($isHtmlString) { | ||
$value = new HtmlString($value); | ||
} | ||
} | ||
@endphp | ||
<meta property="og:{{ $key }}" content="{{ $value }}"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bit more repetitive but a lot shorter. (also the page_title()
should be escaped)
@php | |
if ($key === 'title') { | |
$isHtmlString = $value instanceof HtmlString; | |
$value .= ' · '.page_title(); | |
if ($isHtmlString) { | |
$value = new HtmlString($value); | |
} | |
} | |
@endphp | |
<meta property="og:{{ $key }}" content="{{ $value }}"> | |
@if ($key === 'title') | |
<meta property="og:{{ $key }}" content="{{ $value }} · {{ page_title() }}"> | |
@else | |
<meta property="og:{{ $key }}" content="{{ $value }}"> | |
@endif |
@if (isset($opengraph)) | ||
<meta property="og:site_name" content="osu! » {{ page_title() }}"> | ||
<meta property="og:type" content="website"> | ||
<meta property="og:site_name" content="osu! » {{ page_title() }}"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
page title not needed anymore? Both og title and html title always have it now
@@ -3,9 +3,14 @@ | |||
See the LICENCE file in the repository root for full licence text. | |||
--}} | |||
@php | |||
use Illuminate\Support\HtmlString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used
|
||
use App\Models\Beatmapset; | ||
|
||
class BeatmapsetOpengraph |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implements Something
? The set_opengraph
assumes everything here have the get
method.
namespace App\Libraries\Opengraph; | ||
|
||
interface HasOpengraph | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should require something like $opengraphClass
and use it for set_opengraph
. Not sure if helps anything at all though. And this currently isn't enforcing anything. One can have HasOpengraph model without corresponding class and it'll only explode on runtime. That said, specifying the class name won't help either since it's not checked and can't specify inheritance either.
eh 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got rid of it since the type check is more of "belongs to App\Models
" than anything 🤷
…be constant, anyway)
public function get(): array | ||
{ | ||
$section = osu_trans('layout.menu.beatmaps._'); | ||
$title = "{$this->beatmapset->artist} - {$this->beatmapset->title}"; // opengrah header always intended for guest. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right, opengraph missing p
doesn't actually implement anything, not really used for typecheck
Also I did think of removing the
Opengraph
suffixes from the class names, except, they're usually used in places where there'd already be an existing model class import with the same name, so they'd have to be aliased toas xxOpengraph
anyway 👀Not sure what to with the user multiplayer tabs descriptions as the room/playlist counts seems...not useful 🤔