Skip to content

Commit

Permalink
Dynamic path
Browse files Browse the repository at this point in the history
  • Loading branch information
robdekort committed Oct 26, 2021
1 parent ae96f18 commit c56c07e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions app/Jobs/GenerateSocialImagesJob.php
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Spatie\Browsershot\Browsershot;
use Statamic\Facades\AssetContainer;

class GenerateSocialImagesJob implements ShouldQueue
{
Expand All @@ -38,10 +39,12 @@ public function handle()
{
$this->items->each(function($item, $key) {

$disk = AssetContainer::find('social_images')->disk();

// Delete any old images remaining.
collect([
public_path("social_images/{$item->get('og_image')}"),
public_path("social_images/{$item->get('twitter_image')}"),
$disk->path($item->get('og_image')),
$disk->path($item->get('twitter_image')),
])->each(function ($image) {
if (File::exists($image))
File::delete($image);
Expand All @@ -58,15 +61,15 @@ public function handle()
$image = Browsershot::url("{$app_url}/social-images/{$id}")
->windowSize(1200, 630)
->select('#og')
->save(public_path("social_images/{$file}"));
->save($disk->path($file));
$item->set('og_image', $file)->save();

// Generate, save and set default twitter image.
$file = "{$title}-twitter-{$unique}.png";
$image = Browsershot::url("{$app_url}/social-images/{$id}")
->windowSize(1200, 600)
->select('#twitter')
->save(public_path("social_images/{$file}"));
->save($disk->path($file));
$item->set('twitter_image', $file)->save();
});

Expand Down
11 changes: 7 additions & 4 deletions dev/app/Jobs/GenerateSocialImagesJob.php
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Spatie\Browsershot\Browsershot;
use Statamic\Facades\AssetContainer;

class GenerateSocialImagesJob implements ShouldQueue
{
Expand All @@ -38,10 +39,12 @@ public function handle()
{
$this->items->each(function($item, $key) {

$disk = AssetContainer::find('social_images')->disk();

// Delete any old images remaining.
collect([
public_path("social_images/{$item->get('og_image')}"),
public_path("social_images/{$item->get('twitter_image')}"),
$disk->path($item->get('og_image')),
$disk->path($item->get('twitter_image')),
])->each(function ($image) {
if (File::exists($image))
File::delete($image);
Expand All @@ -58,15 +61,15 @@ public function handle()
$image = Browsershot::url("{$app_url}/social-images/{$id}")
->windowSize(1200, 630)
->select('#og')
->save(public_path("social_images/{$file}"));
->save($disk->path($file));
$item->set('og_image', $file)->save();

// Generate, save and set default twitter image.
$file = "{$title}-twitter-{$unique}.png";
$image = Browsershot::url("{$app_url}/social-images/{$id}")
->windowSize(1200, 600)
->select('#twitter')
->save(public_path("social_images/{$file}"));
->save($disk->path($file));
$item->set('twitter_image', $file)->save();
});

Expand Down

0 comments on commit c56c07e

Please sign in to comment.