seo fixes

This commit is contained in:
2026-08-09 12:43:21 +03:00
parent bed4c48900
commit 443ff374c3
5 changed files with 138 additions and 2 deletions
+48
View File
@@ -2,6 +2,7 @@
namespace App\Models;
use App\Jobs\MirrorToolLogo;
use Database\Factories\ToolFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\RouteKey;
@@ -40,6 +41,28 @@ class Tool extends Model
$tool->slug = Str::slug($tool->name);
}
});
static::created(function (Tool $tool) {
$tool->queueLogoMirrorIfNeeded();
});
static::updated(function (Tool $tool) {
if ($tool->wasChanged('logo_url')) {
$tool->queueLogoMirrorIfNeeded();
}
});
}
public function hasLocalLogo(): bool
{
return str_starts_with((string) $this->logo_url, rtrim(config('app.url'), '/').'/storage/tools/');
}
public function queueLogoMirrorIfNeeded(): void
{
if ($this->logo_url && ! $this->hasLocalLogo()) {
MirrorToolLogo::dispatch($this, $this->logo_url);
}
}
/**
@@ -63,4 +86,29 @@ class Tool extends Model
{
return Attribute::get(fn () => config("tools.categories.{$this->category}", $this->category));
}
/**
* Structured-data-safe price, parsed from the free-text `pricing` field
* (e.g. "Free", "$29/month"). schema.org's Offer.price expects a plain
* number with a currency, so values we can't parse into that (e.g.
* "Freemium", "Contact for pricing") are left out rather than guessed.
*/
protected function offerData(): Attribute
{
return Attribute::get(function () {
if (! $this->pricing) {
return null;
}
if (strcasecmp($this->pricing, 'free') === 0) {
return ['price' => '0', 'priceCurrency' => 'USD'];
}
if (preg_match('/^\$(\d+(?:\.\d+)?)/', $this->pricing, $matches)) {
return ['price' => $matches[1], 'priceCurrency' => 'USD'];
}
return null;
});
}
}