presprog / kirby-auto-file-templates
根据文件类型自动分配文件模板
1.0.1
2024-04-26 07:50 UTC
Requires
- php: ^8.2
- getkirby/composer-installer: ^1.2
README
自动将模板分配给上传的文件
⚡ 已准备好支持 Kirby 4!
此插件根据相应的文件类型自动将文件模板分配给上传的文件。这样,无论您从哪个字段或部分上传哪种文件类型,分配的模板始终相同。当您在每个页面上使用单个文件部分存储页面上的所有不同文件类型时,这特别方便。
重要
需要至少 Kirby 4.0 和 PHP 8.2
🚀 如何使用
首先设置您的配置(请参阅下一节)。然后,插件将在每次上传文件后(file.create:after
钩子)运行,并自动分配配置的模板。
如果您将插件添加到现有项目中,可以从 CLI 运行 auto-templates
命令。它将遍历每个页面的每个文件,并根据配置分配模板
$ php vendor/bin/kirby auto-templates
image.png: image
video.mp4: video
> All files updated
默认情况下,现有模板分配不会受到影响。要更改此,请使用带有 --force/-f
的命令运行,或在您的 config.php
中全局设置 forceOverwrite
选项(见下文)。
⚙️ 配置
插件以可选方式工作:除非您告诉它,否则它不会做任何事情。
// site/config/config.php 'presprog/auto-file-templates' => [ // Do nothing (default) 'auto-assign' => false, // OR automatically assign a file template for every file type 'auto-assign' => true, // OR only assign templates to some file types (ignore file types other than `image` and `video` 'auto-assign' => [ 'image' => true, 'video' => true, ], // OR define a specific template for just some file types and let the plugin decide for the others 'auto-assign' => [ 'image' => 'my-custom-image-blueprint', 'video' => true, // => 'video' ], // OR handle more advanced use-cases in callable yourself (assign different file templates for vector and raster images) 'auto-assign' => [ 'image' => function(\Kirby\Cms\File $file) { return match (F::extension($file->filename())) { 'svg' => 'vector', default => 'image', }; }, ], // Overwrite existing template assignments (default: false) 'forceOverwrite' => true, ],
使用 auto-assign = true
,每种文件类型将分配同名文件蓝图作为模板
支持 kirby 核心文件类型 archive
、audio
、document
、image
和 video
以及 您自定义的文件类型扩展
💻 如何安装
通过 Composer 安装此插件(推荐)
composer require presprog/kirby-auto-file-templates
或从 GitHub 下载 ZIP 文件 并将其解压到 site/plugins/kirby-auto-file-templates
或作为 Git 子模块
git submodule add https://github.com/presprog/kirby-auto-file-templates.git site/plugins/auto-file-templates
✅ 待办事项
- 添加多语言支持
📄 许可证
MIT 许可证 版权所有 © 2024 Present Progressive
由 Present Progressive 为 Kirby 社区制作。