Last active
February 22, 2020 21:16
-
-
Save rosswintle/fbc611a2fa3e875365e1ee35123445ec to your computer and use it in GitHub Desktop.
Statamic tag for my LaravelAssetCache package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Tag for my LaravelAssetCache package: https://github.com/rosswintle/laravel-asset-cache/ | |
* | |
* This grabs the asset file from the specified npm package from jsdelivr.net, and caches and serves it locally | |
* | |
* Before use you'll need to: | |
* composer require rosswintle/laravel-asset-cache | |
* php artisan storage:link (in all environments) | |
* | |
* Tag usage: {{ asset_cache package_name='alpinejs' version='' filename='dist/alpine.min.js' }} | |
* | |
*/ | |
namespace App\Tags; | |
use Statamic\Tags\Tags; | |
use RossWintle\LaravelAssetCache\Facades\LaravelAssetCache; | |
class AssetCache extends Tags | |
{ | |
/** | |
* The {{ asset_cache }} tag | |
* | |
* @return string|array | |
*/ | |
public function index() | |
{ | |
return LaravelAssetCache::cachedAssetUrl( | |
$this->params->get('package_name'), | |
$this->params->get('version') ?? '', | |
$this->params->get('filename') ?? '' | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment