From 65d49c1716388c7625d8ee9e851267aafa39be5e Mon Sep 17 00:00:00 2001 From: Puleeno Date: Mon, 1 Jan 2024 15:56:41 +0700 Subject: [PATCH] Improve asset manager and added min URL for common-css --- app/Core/Assets/CascadingStyleSheets.php | 5 +++-- app/Core/Assets/JavaScript.php | 5 +++-- app/Core/ExternalAsset.php | 6 +++++- app/bootstrap.php | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/Core/Assets/CascadingStyleSheets.php b/app/Core/Assets/CascadingStyleSheets.php index b20d36b..5505b43 100644 --- a/app/Core/Assets/CascadingStyleSheets.php +++ b/app/Core/Assets/CascadingStyleSheets.php @@ -13,10 +13,11 @@ public function renderHtml() echo HookManager::applyFilters( 'print_css_html', sprintf( - '', + '', HookManager::applyFilters("asset_css_url", $this->getUrl( Env::get("COMPRESSED_ASSETS", Env::get("DEBUG") === false) - ), $this->id, $this) + ), $this->id, $this), + $this->id ), $this->getId(), $this diff --git a/app/Core/Assets/JavaScript.php b/app/Core/Assets/JavaScript.php index 1ce00f4..8848b84 100644 --- a/app/Core/Assets/JavaScript.php +++ b/app/Core/Assets/JavaScript.php @@ -17,10 +17,11 @@ public function renderHtml() echo HookManager::applyFilters( 'print_js_html', sprintf( - '', + '', HookManager::applyFilters("asset_js_url", $this->getUrl( Env::get("COMPRESSED_ASSETS", Env::get("DEBUG") === false) - ), $this->id, $this) + ), $this->id, $this), + $this->id ), $this->getId(), $this diff --git a/app/Core/ExternalAsset.php b/app/Core/ExternalAsset.php index 83997f9..e0ca216 100644 --- a/app/Core/ExternalAsset.php +++ b/app/Core/ExternalAsset.php @@ -16,12 +16,16 @@ public function setUrl(AssetUrl $url): self return $this; } - public function getUrl($supportMinUrl = false) + public function getUrl($supportMinUrl = null) { if (empty($this->url)) { return ""; } + if (is_null($supportMinUrl)) { + $supportMinUrl = Env::get('COMPRESSED_ASSETS', !Env::get('DEBUG', false)); + } + return $this->url->getUrl($supportMinUrl); } } diff --git a/app/bootstrap.php b/app/bootstrap.php index 5820c2d..859f87c 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -158,8 +158,8 @@ protected function setup() protected function initAssets() { AssetManager::registerAsset( - 'common-css', - new AssetUrl('/extensions/common/assets/css/common.css'), + 'common', + new AssetUrl('/extensions/common/assets/css/common.css', '/extensions/common/assets/css/common.min.css'), AssetTypeEnum::CSS(), [], '1.0.0',