swiftmade/statamic-clear-assets

删除未使用的资产。节省存储空间。

支持包维护!
swiftmade

安装次数: 15,116

依赖关系: 0

建议者: 0

安全: 0

星标: 15

关注者: 3

分支: 4

开放问题: 1

类型:statamic-addon

v3.1.0 2024-08-06 09:43 UTC

This package is auto-updated.

Last update: 2024-09-06 09:58:23 UTC


README

Statamic 3.0+ Latest Version on Packagist Downloads

支持Statamic 3、4和5。

清理Statamic站点的未使用图像和资产。节省存储空间,保持整洁。

插件会扫描整个contentusers目录。如果一个资产在任何地方都没有被引用,它将被标记为未使用。您可以查看未使用资产的列表并删除它们。

插件易于配置。请参阅下面的配置部分。

demo

如何安装

您可以在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