swiftmade / statamic-clear-assets
删除未使用的资产。节省存储空间。
v3.1.0
2024-08-06 09:43 UTC
Requires
- php: ^7.4|^8.0
- laravel/framework: ^7.30.3|^8.24|^9.0|^10.0|^11.0
- statamic/cms: ^3.0.0|^4.0|^5.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- nunomaduro/collision: ^4.1|^5.0|^6.0|^8.1
- orchestra/testbench: ^5.0|^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.5|^10.0
This package is auto-updated.
Last update: 2024-09-06 09:58:23 UTC
README
支持Statamic 3、4和5。
清理Statamic站点的未使用图像和资产。节省存储空间,保持整洁。
插件会扫描整个content
和users
目录。如果一个资产在任何地方都没有被引用,它将被标记为未使用。您可以查看未使用资产的列表并删除它们。
插件易于配置。请参阅下面的配置部分。
如何安装
您可以在Statamic控制面板的工具 > 插件
部分搜索此插件,并点击安装,或者从您的项目根目录运行以下命令
composer require swiftmade/statamic-clear-assets
如何使用
只需运行
php please assets:clear
它将列出内容目录中未引用的所有资产。您可以一次性删除所有资产,也可以逐个删除。
如果您想跳过交互式模式,可以使用--force
标志
# This will delete all the unused assets without asking for confirmation!
php please assets:clear --force=true
配置
要发布配置文件,请使用
php artisan vendor:publish --tag=statamic-clear-assets-config
以下是所有配置选项及其默认值
return [ /** * Where should we look to see if assets are still referenced or not? * If you're referencing assets elsewhere in your codebase, add those paths here. * All paths are relative to the base_path() */ 'scan_folders' => [ 'content', 'users', ], /** * All assets from these containers will be left alone. * You can see all your asset containers under content/assets folder. */ 'ignore_containers' => [ 'favicons', 'social_images', ], /** * If we come across these filenames, we'll just leave them alone. * You can use "*" as a wildcard. eg: "IMAGE*.jpg" will ignore IMAGE1.jpg IMAGE23.jpg etc... */ 'ignore_filenames' => [ // ], /** * You might not want to delete very fresh assets, as perhaps you want to use them soon. * Use this config to only detect and delete files older than x days. */ 'minimum_age_in_days' => 0, ];
常见问题
它正在删除我在antlers模板中引用的资产!
如果您想忽略视图中的引用资产,请将resources/views
添加到scan_folders
配置中。请注意,这只会在代码中确切地提到了文件名时才有效。如果您使用变量或其他逻辑来引用资产,插件可能无法检测到该资产被使用。
我如何始终保留PDF文件?
将*.pdf
添加到ignore_filenames
配置。
我如何始终保留特定容器的资产?
将容器的slug添加到ignore_containers
配置。
我如何只删除30天前的资产?
在配置中将minimum_age_in_days
设置为30
。