Skip to content

Commit

Permalink
Glide Improvements (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored Jul 18, 2022
1 parent d3fc6be commit 90cd590
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions config/ssg.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@

'glide' => [
'directory' => 'img',
'override' => true,
],

/*
Expand Down
9 changes: 9 additions & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 90cd590

Please sign in to comment.