diff --git a/config/hyde.php b/config/hyde.php index 7e640f21..113af009 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -108,7 +108,7 @@ /* |-------------------------------------------------------------------------- - | Asset Locations + | Asset Locations and Versions |-------------------------------------------------------------------------- | | Since v0.15.0, the default Hyde styles are no longer included as @@ -118,9 +118,14 @@ | changing the config setting below. If you set it to | false, Hyde will load the media/app.css, which | you compile using NPM. + | + | The CDN version is defined in the AssetService class, + | but can be changed here to a valid HydeFront tag. + | */ - 'loadTailwindFromCDN' => true, + // 'loadTailwindFromCDN' => true, + // 'cdnHydeFrontVersionOverride' => 'v1.0.0, /* |-------------------------------------------------------------------------- diff --git a/src/Concerns/Internal/AssetManager.php b/src/Concerns/Internal/AssetManager.php index 58b7717e..a648b92f 100644 --- a/src/Concerns/Internal/AssetManager.php +++ b/src/Concerns/Internal/AssetManager.php @@ -2,7 +2,7 @@ namespace Hyde\Framework\Concerns\Internal; -use function config; +use Hyde\Framework\Services\AssetService; /** * AssetManager for the Hyde Facade. @@ -14,9 +14,7 @@ trait AssetManager */ public static function tailwind(): string|false { - return config('hyde.loadTailwindFromCDN') - ? 'https://cdn.jsdelivr.net/gh/hydephp/hydefront@v1.3.1/dist/app.css' - : false; + return (new AssetService)->tailwindPath(); } /** @@ -24,7 +22,7 @@ public static function tailwind(): string|false */ public static function styles(): string { - return 'https://cdn.jsdelivr.net/gh/hydephp/hydefront@v1.3.1/dist/hyde.css'; + return (new AssetService)->stylePath(); } /** @@ -32,6 +30,6 @@ public static function styles(): string */ public static function scripts(): string { - return 'https://cdn.jsdelivr.net/gh/hydephp/hydefront@v1.3.1/dist/hyde.js'; + return (new AssetService)->scriptPath(); } } diff --git a/src/Contracts/AssetServiceContract.php b/src/Contracts/AssetServiceContract.php new file mode 100644 index 00000000..e7bae5c2 --- /dev/null +++ b/src/Contracts/AssetServiceContract.php @@ -0,0 +1,33 @@ +version); + } + + public function tailwindPath(): string|false + { + return config('hyde.loadTailwindFromCDN', false) + ? $this->cdnPathConstructor('app.css') + : false; + } + + public function stylePath(): string + { + return $this->cdnPathConstructor('hyde.css'); + } + + public function scriptPath(): string + { + return $this->cdnPathConstructor('hyde.js'); + } + + public function cdnPathConstructor(string $file): string + { + return 'https://cdn.jsdelivr.net/gh/hydephp/hydefront@' . $this->version() . '/dist/' . $file; + } +} \ No newline at end of file