Skip to content

Commit

Permalink
Merge pull request #725 from pinkary-project/chore/fix-link-preview
Browse files Browse the repository at this point in the history
Chore: fix link preview
  • Loading branch information
nunomaduro authored Nov 3, 2024
2 parents 119f19a + 67f9a34 commit 60a82f1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/EventActions/UpdateQuestionHashtags.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function handle(): array

$existingHashtags = Hashtag::query()->whereIn('name', $parsedHashtags->all())->get();

$newHashtags = $parsedHashtags->diff($existingHashtags->pluck('name'))
$newHashtags = $parsedHashtags->diff($existingHashtags->pluck('name')) // @phpstan-ignore-line
->map(fn (string $name): Hashtag => Hashtag::query()->create(['name' => $name]));

return $this->question->hashtags()->sync($existingHashtags->merge($newHashtags));
Expand Down
1 change: 0 additions & 1 deletion app/Services/Autocomplete/Types/Mentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public function matchExpression(): string
*/
public function search(?string $query): Collection
{
// @phpstan-ignore-next-line
return Collection::make(
User::query()
->when(auth()->id(), fn (Builder $constraint, string|int $id) => $constraint->whereKeyNot($id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ function (array $matches): string {

$url = $isMail ? 'mailto:'.$humanUrl : $url;

$linkHtml = '<a data-navigate-ignore="true" class="text-blue-500 hover:underline hover:text-blue-700 cursor-pointer" target="_blank" href="'.$url.'">'.$humanUrl.'</a>';

if (! $isMail && $url) {
$service = new MetaData($url);
$metadata = $service->fetch();
Expand All @@ -50,11 +52,11 @@ function (array $matches): string {
])->render()
);

return (string) preg_replace('/<!--(.|\s)*?-->/', '', $trimmed);
return $linkHtml.' '.preg_replace('/<!--(.|\s)*?-->/', '', $trimmed);
}
}

return '<a data-navigate-ignore="true" class="text-blue-500 hover:underline hover:text-blue-700 cursor-pointer" target="_blank" href="'.$url.'">'.$humanUrl.'</a>';
return $linkHtml;
},
str_replace('&amp;', '&', $content)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div
<a data-navigate-ignore="true" class="text-blue-500 hover:underline hover:text-blue-700 cursor-pointer" target="_blank" href="https://pinkary.com/@nunomaduro">pinkary.com/@nunomaduro</a> <div
id="link-preview-card"
data-url="https://pinkary.com/<a href="/@nunomaduro" data-navigate-ignore="true" class="text-blue-500 hover:underline hover:text-blue-700 cursor-pointer" wire-navigate>@nunomaduro</a>"
class="mx-auto mt-2 min-w-full group/preview" data-navigate-ignore="true"
Expand All @@ -25,4 +25,5 @@
<a href="https://pinkary.com/@nunomaduro" target="_blank" rel="noopener noreferrer"
class="text-xs text-slate-500 group-hover/preview:text-pink-600">From: pinkary.com</a>
</div>

</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Sure, here is the link: <div
Sure, here is the link: <a data-navigate-ignore="true" class="text-blue-500 hover:underline hover:text-blue-700 cursor-pointer" target="_blank" href="https://laravel.com">laravel.com</a> <div
id="link-preview-card"
data-url="https://laravel.com"
class="mx-auto mt-2 min-w-full group/preview" data-navigate-ignore="true"
Expand All @@ -25,4 +25,5 @@ Sure, here is the link: <div
<a href="https://laravel.com" target="_blank" rel="noopener noreferrer"
class="text-xs text-slate-500 group-hover/preview:text-pink-600">From: laravel.com</a>
</div>

</div>. Let me know if you have any questions.

0 comments on commit 60a82f1

Please sign in to comment.