From 537e2769cd77a56746a95251f436b8173a401fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Sat, 27 Dec 2025 09:45:10 +0300 Subject: [PATCH] Improve Asset Path Handling and Add Preview Action: Enhanced the ImportHtmlTemplates command to support fallback asset paths for better template import functionality. Updated the TemplateService to handle old asset paths. Added a preview action in the SectionTemplates localization files for improved user experience in template management. --- app/Console/Commands/ImportHtmlTemplates.php | 21 ++++++++++++-------- app/Services/TemplateService.php | 5 +++++ lang/en/section-templates.php | 2 +- lang/tr/section-templates.php | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/Console/Commands/ImportHtmlTemplates.php b/app/Console/Commands/ImportHtmlTemplates.php index 2009896..1ec6a59 100644 --- a/app/Console/Commands/ImportHtmlTemplates.php +++ b/app/Console/Commands/ImportHtmlTemplates.php @@ -323,6 +323,11 @@ class ImportHtmlTemplates extends Command if (str_starts_with($path, 'assets/')) { $sourcePath = public_path('html/' . $path); + // Eğer html/assets altında yoksa, ana assets klasörüne bak + if (!File::exists($sourcePath)) { + $sourcePath = public_path($path); + } + if (File::exists($sourcePath)) { // Dosya adını ve klasörünü belirle $fileName = basename($path); @@ -344,7 +349,7 @@ class ImportHtmlTemplates extends Command } // Dosya bulunamadıysa eski usul devam et - return '/html/' . $path; + return '/' . $path; } return $path; @@ -361,13 +366,13 @@ class ImportHtmlTemplates extends Command // CSS içindeki url('assets/...') kısımlarını yakalamak için daha genel bir yaklaşım // Ancak processNode zaten img taglerini hallettiği için burası sadece kalanlar için. - $html = str_replace('src="assets/', 'src="/html/assets/', $html); - $html = str_replace('href="assets/', 'href="/html/assets/', $html); - $html = str_replace("src='assets/", "src='/html/assets/", $html); - $html = str_replace("href='assets/", "href='/html/assets/", $html); - $html = str_replace('url(assets/', 'url(/html/assets/', $html); - $html = str_replace('url("assets/', 'url("/html/assets/', $html); - $html = str_replace("url('assets/", "url('/html/assets/", $html); + $html = str_replace('src="assets/', 'src="/assets/', $html); + $html = str_replace('href="assets/', 'href="/assets/', $html); + $html = str_replace("src='assets/", "src='/assets/", $html); + $html = str_replace("href='assets/", "href='/assets/", $html); + $html = str_replace('url(assets/', 'url(/assets/', $html); + $html = str_replace('url("assets/', 'url("/assets/', $html); + $html = str_replace("url('assets/", "url('/assets/", $html); return $html; } diff --git a/app/Services/TemplateService.php b/app/Services/TemplateService.php index 650e38a..b703149 100644 --- a/app/Services/TemplateService.php +++ b/app/Services/TemplateService.php @@ -641,6 +641,11 @@ class TemplateService if (str_starts_with($value, 'templates/')) { return asset('storage/' . $value); } + + // Support for old assets/ path (if import not run) + if (str_starts_with($value, 'assets/')) { + return asset($value); + } // If it's already using asset() or Storage::url(), assume it's already formatted // Otherwise, prepend storage/ if it looks like a storage path diff --git a/lang/en/section-templates.php b/lang/en/section-templates.php index 58b847d..fbc3233 100644 --- a/lang/en/section-templates.php +++ b/lang/en/section-templates.php @@ -26,6 +26,7 @@ return [ 'column_deleted_at' => 'Deleted At', // Actions + 'action_preview' => 'Preview', 'create' => 'New Section Template', 'edit' => 'Edit Section Template', 'view' => 'View Section Template', @@ -39,4 +40,3 @@ return [ 'deleted_successfully' => 'Section template deleted successfully.', 'restored_successfully' => 'Section template restored successfully.', ]; - diff --git a/lang/tr/section-templates.php b/lang/tr/section-templates.php index acc6a24..d609a1e 100644 --- a/lang/tr/section-templates.php +++ b/lang/tr/section-templates.php @@ -26,6 +26,7 @@ return [ 'column_deleted_at' => 'Silinme', // Actions + 'action_preview' => 'Önizleme', 'create' => 'Yeni Section Şablonu', 'edit' => 'Section Şablonunu Düzenle', 'view' => 'Section Şablonunu Görüntüle', @@ -39,4 +40,3 @@ return [ 'deleted_successfully' => 'Section şablonu başarıyla silindi.', 'restored_successfully' => 'Section şablonu başarıyla geri yüklendi.', ]; -