From 3aefb86f46456cc48d464a2c512fc27695677298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=96z=C4=B1=C5=9F=C4=B1k?= Date: Thu, 1 Feb 2024 22:59:58 +0200 Subject: [PATCH] Include users in scan folders by default (#15) * include users dir in scan folders * update readme * update --- README.md | 22 +++++++++++++++++++++- config/statamic-clear-assets.php | 1 + src/ClearAssets.php | 3 ++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1fe2823..35fa9c7 100644 --- a/README.md +++ b/README.md @@ -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. @@ -48,6 +48,7 @@ return [ */ 'scan_folders' => [ 'content', + 'users', ], /** @@ -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. + diff --git a/config/statamic-clear-assets.php b/config/statamic-clear-assets.php index daf12f0..d19c640 100644 --- a/config/statamic-clear-assets.php +++ b/config/statamic-clear-assets.php @@ -9,6 +9,7 @@ */ 'scan_folders' => [ 'content', + 'users', ], /** diff --git a/src/ClearAssets.php b/src/ClearAssets.php index 31e23df..90a9822 100644 --- a/src/ClearAssets.php +++ b/src/ClearAssets.php @@ -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()