From 90cd5907748d0f10e34a00176ef305af14c11960 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 18 Jul 2022 15:30:55 -0400 Subject: [PATCH] Glide Improvements (#104) --- README.md | 35 +++++++++++++++++++++++++++++++++++ config/ssg.php | 1 + src/Generator.php | 9 +++++++++ 3 files changed, 45 insertions(+) diff --git a/README.md b/README.md index 065a1a5..b2bc3b4 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,41 @@ class AppServiceProvider extends Provider ``` +## Glide Images + +The default configuration of Statamic is to have Glide use "dynamic" images, which means that the `glide` tag will only output URLs. The images themselves will be generated when the URLs are visited. For a static site, this no longer makes sense since it will typically be deployed somewhere where there is no dynamic Glide route available. + +By default, the SSG will automatically reconfigure Glide to generate images into the `img` directory whenever `glide` tags are used. This is essentially Glide's [custom static path option](https://statamic.dev/image-manipulation#custom-path-static). + +You can customize where the images will be generated: + +```php +'glide' => [ + 'directory' => 'images', +], +``` + +If you are using a [custom glide disk](https://statamic.dev/image-manipulation#custom-disk-cdn), you can tell the SSG to leave it alone: + +```php +'glide' => [ + 'override' => false, +], +``` + +And then copy the images over (or create a symlink) after generating has completed: + +```php +SSG::after(function () { + $from = public_path('img'); + $to = config('statamic.ssg.destination').'/img'; + + app('files')->copyDirectory($from, $to); + // or + app('files')->link($from, $to); +}); +``` + ## Triggering Command Failures If you are using the SSG in a CI environment, you may want to prevent the command from succeeding if any pages aren't generated (e.g. to prevent deployment of an incomplete site). diff --git a/config/ssg.php b/config/ssg.php index a8b917a..16c0328 100644 --- a/config/ssg.php +++ b/config/ssg.php @@ -88,6 +88,7 @@ 'glide' => [ 'directory' => 'img', + 'override' => true, ], /* diff --git a/src/Generator.php b/src/Generator.php index 28ab18f..7c73de0 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -11,6 +11,7 @@ use Illuminate\Support\Arr; use Statamic\Facades\Collection; use Statamic\Facades\Entry; +use Statamic\Facades\Glide; use Statamic\Facades\Term; use League\Flysystem\Adapter\Local; use Statamic\Imaging\ImageGenerator; @@ -98,6 +99,14 @@ public function generate() public function bindGlide() { + $override = $this->config['glide']['override'] ?? true; + + if (! $override) { + return $this; + } + + Glide::cacheStore()->clear(); + $directory = Arr::get($this->config, 'glide.directory'); // Determine which adapter to use for Flysystem 1.x or 3.x.