diff --git a/app/Services/ContentService.php b/app/Services/ContentService.php index 260227dd..2474d1d3 100644 --- a/app/Services/ContentService.php +++ b/app/Services/ContentService.php @@ -10,6 +10,8 @@ class ContentService { + private const string IMAGE_PATTERN = '/\d{4}_\d{2}_\d{2}_\d{2}_\d{2}_\d{2}_[a-zA-Z0-9]+\.(jpg|jpeg|png|bmp|gif|webp)/u'; + /** * 生成用來優化 SEO 的 slug * @@ -66,11 +68,9 @@ public static function getImagesInContent(string $body): array $imageList = []; foreach ($dom->getElementsByTagName('img') as $img) { - $pattern = '/\d{4}_\d{2}_\d{2}_\d{2}_\d{2}_\d{2}_[a-zA-Z0-9]+\.(jpeg|png|jpg|gif|svg)/u'; - $imageName = basename($img->getAttribute('src')); - if (preg_match($pattern, $imageName)) { + if (preg_match(self::IMAGE_PATTERN, $imageName)) { $imageList[] = $imageName; } }