internal linking
This commit is contained in:
+4
-1
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user