Skip to content

Commit 3aefb86

Browse files
authored
Include users in scan folders by default (#15)
* include users dir in scan folders * update readme * update
1 parent 35f84b9 commit 3aefb86

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

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

9-
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.
9+
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.
1010

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

@@ -48,6 +48,7 @@ return [
4848
*/
4949
'scan_folders' => [
5050
'content',
51+
'users',
5152
],
5253

5354
/**
@@ -74,3 +75,22 @@ return [
7475
'minimum_age_in_days' => 0,
7576
];
7677
```
78+
79+
## Common Questions
80+
81+
**It's deleting assets that I'm referencing in my antlers templates!**
82+
83+
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.
84+
85+
**How do I always keep PDF files?**
86+
87+
Add `*.pdf` to the `ignore_filenames` config.
88+
89+
**How do I always keep assets from a specific container?**
90+
91+
Add the container's slug to the `ignore_containers` config.
92+
93+
**How do I only delete assets older than 30 days?**
94+
95+
Set `minimum_age_in_days` to `30` in the config.
96+

config/statamic-clear-assets.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
'scan_folders' => [
1111
'content',
12+
'users',
1213
],
1314

1415
/**

src/ClearAssets.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ private function filterUnused(AssetCollection $assets)
105105
return true;
106106
});
107107

108-
collect(config('statamic-clear-assets.scan_folders', ['content']))
108+
collect(config('statamic-clear-assets.scan_folders', ['content', 'users']))
109+
->filter(fn ($folder) => file_exists(base_path($folder)))
109110
->map(fn ($folder) => File::allFiles(base_path($folder)))
110111
->flatten()
111112
->unique()

0 commit comments

Comments
 (0)