Skip to content

Commit

Permalink
Include users in scan folders by default (#15)
Browse files Browse the repository at this point in the history
* include users dir in scan folders

* update readme

* update
  • Loading branch information
aozisik authored Feb 1, 2024
1 parent 35f84b9 commit 3aefb86
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Clean up unused images and assets from your Statamic site. Saves storage, keep things tidy.

The addon scans your entire `content` directory. If an asset is not referenced in any of your content, it will be marked as unused. You can review the list of unused assets and delete them.
The addon scans your entire `content` and `users` directory. If an asset is not referenced anywhere, it will be marked as unused. You can review the list of unused assets and delete them.

The addon is easy to configure. See the [Configuration](#configuration) section below.

Expand Down Expand Up @@ -48,6 +48,7 @@ return [
*/
'scan_folders' => [
'content',
'users',
],

/**
Expand All @@ -74,3 +75,22 @@ return [
'minimum_age_in_days' => 0,
];
```

## Common Questions

**It's deleting assets that I'm referencing in my antlers templates!**

If you want to ignore the assets referenced in your views, add `resources/views` to the `scan_folders` config. Keep in mind that this will only work if the filename is mentioned verbatim in the code. If you are using variables or other logic to reference the asset, the addon might not be able to detect that the asset is being used.

**How do I always keep PDF files?**

Add `*.pdf` to the `ignore_filenames` config.

**How do I always keep assets from a specific container?**

Add the container's slug to the `ignore_containers` config.

**How do I only delete assets older than 30 days?**

Set `minimum_age_in_days` to `30` in the config.

1 change: 1 addition & 0 deletions config/statamic-clear-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
'scan_folders' => [
'content',
'users',
],

/**
Expand Down
3 changes: 2 additions & 1 deletion src/ClearAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private function filterUnused(AssetCollection $assets)
return true;
});

collect(config('statamic-clear-assets.scan_folders', ['content']))
collect(config('statamic-clear-assets.scan_folders', ['content', 'users']))
->filter(fn ($folder) => file_exists(base_path($folder)))
->map(fn ($folder) => File::allFiles(base_path($folder)))
->flatten()
->unique()
Expand Down

0 comments on commit 3aefb86

Please sign in to comment.