seo fixes
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Tool;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ToolController extends Controller
|
||||
{
|
||||
@@ -72,7 +73,7 @@ class ToolController extends Controller
|
||||
'tool' => $tool,
|
||||
'related' => $related,
|
||||
'title' => $tool->name.' — AI Tools — '.config('app.name'),
|
||||
'description' => str($tool->description)->limit(155, '')->toString(),
|
||||
'description' => $this->metaDescription($tool->description),
|
||||
'canonical' => route('tools.show', $tool),
|
||||
'image' => $tool->logo_url,
|
||||
]);
|
||||
@@ -86,4 +87,17 @@ class ToolController extends Controller
|
||||
|
||||
return redirect()->away($tool->url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate to ~155 chars without cutting a word in half. Google appends
|
||||
* its own ellipsis when it truncates in search results, so we don't add one.
|
||||
*/
|
||||
private function metaDescription(string $description, int $limit = 155): string
|
||||
{
|
||||
if (Str::length($description) <= $limit) {
|
||||
return $description;
|
||||
}
|
||||
|
||||
return Str::of($description)->limit($limit, '')->beforeLast(' ')->toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user