Fix rich editor image preview URLs
This commit is contained in:
@@ -30,6 +30,35 @@ class GuidePage extends Model
|
||||
return route('guides.pages.show', $this->id);
|
||||
}
|
||||
|
||||
public function getNormalizedContentAttribute(): string
|
||||
{
|
||||
return static::normalizeRichTextContent($this->content);
|
||||
}
|
||||
|
||||
public static function normalizeRichTextContent(?string $content): string
|
||||
{
|
||||
if (blank($content)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$content = preg_replace_callback(
|
||||
'~(?:https?:)?//[^"\'\s<>()]+(?<path>/storage/guide-pages/[^"\'\s<>()]*)~i',
|
||||
static fn (array $matches): string => $matches['path'],
|
||||
$content,
|
||||
) ?? $content;
|
||||
|
||||
return preg_replace(
|
||||
'~(?<=["\'])storage/guide-pages/~i',
|
||||
'/storage/guide-pages/',
|
||||
$content,
|
||||
) ?? $content;
|
||||
}
|
||||
|
||||
public static function uploadedAttachmentUrl(string $path): string
|
||||
{
|
||||
return '/storage/'.ltrim($path, '/');
|
||||
}
|
||||
|
||||
public function guide()
|
||||
{
|
||||
return $this->belongsTo(Guide::class);
|
||||
@@ -60,7 +89,6 @@ class GuidePage extends Model
|
||||
|
||||
public function isEntry(): bool
|
||||
{
|
||||
return !$this->incomingEdges()->exists();
|
||||
return ! $this->incomingEdges()->exists();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user