Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option for flattening per profile directories #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ return [
# overwrite original date pattern - `/2020/10/30/img.jpg` --> `/images/img.jpg`
'customFolder' => '/images', # (string|null) default: null

# String to use to separate the profile name from the file name
# Defaults to false, which will generate a directory per profile, eg: /small/img.jpg
# If specified, files will exist in single directory, eg /[email protected]
'profileNameSeparator' => '@', # (string|null) default: null

# Spatie image optimizer (requires additional binaries)
'optimize' => true, # (bool) default: false

Expand Down
12 changes: 9 additions & 3 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
'optimize' => false, # Use Spatie optimizer
'replaceAssetsManager' => false, # modified assets manager
'syncFileNamesWithTitle' => false, # set file name to sluggified title (experimental)
'profileNameSeparator' => null, # use a directory per profile, rather than modifying file name
],
$this->app->storage->getKey('cockpit/options', 'imageresize', []),
$this->app->retrieve('imageresize', [])
Expand Down Expand Up @@ -285,11 +286,16 @@
$width = $c['width'] ? $c['width'] : $asset['width'];
$height = $c['height'] ? $c['height'] : $asset['height'];

$dir = !empty($c['folder']) ? $c['folder'] : $name;
$dir = '/'.\trim($dir, '/').'/';
$profile_name = !empty($c['folder']) ? $c['folder'] : $name;
$file_name = \basename($asset['path']);

$destination = "{$dir}{$file_name}";
if($this->config['profileNameSeparator']) {
$parts = pathinfo($file_name);
$destination = "{$parts['filename']}{$this->config['profileNameSeparator']}{$profile_name}.{$parts['extension']}";
} else {
$dir = '/'.\trim($profile_name, '/').'/';
$destination = "{$dir}{$file_name}";
}

if (!$rebuild && $this->app->filestorage->has("assets://{$destination}")) {
return false;
Expand Down