internal linking

This commit is contained in:
2026-08-11 00:06:19 +03:00
parent 443ff374c3
commit 6ffb24f20a
6 changed files with 261 additions and 16 deletions
+4 -1
View File
@@ -3,6 +3,7 @@
namespace App\Models;
use App\Enums\PostStatus;
use App\Support\ToolLinker;
use Database\Factories\PostFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\RouteKey;
@@ -88,12 +89,14 @@ class Post extends Model
// The page template already renders the post title as an <h1>. If the
// Markdown body also opens with a top-level heading repeating that
// title, drop it so the page doesn't ship two identical <h1>s.
return preg_replace_callback(
$html = preg_replace_callback(
'/^\s*<h1>(.*?)<\/h1>/is',
fn ($matches) => trim(strip_tags($matches[1])) === trim($this->title) ? '' : $matches[0],
$html,
limit: 1
);
return (new ToolLinker)->link($html);
});
}