newism/craftcms-revved-url

该包的最新版本(1.0.3)没有可用的许可信息。

根据修改时间戳重命名 CraftCMS 资产 URL

安装: 14

依赖项: 0

建议者: 0

安全: 0

星级: 7

关注者: 2

分支: 2

开放问题: 0

类型:craft-plugin

1.0.3 2017-03-14 05:17 UTC

This package is auto-updated.

Last update: 2024-09-29 02:49:03 UTC


README

此 Twig 函数通过日期修改时间戳重命名资产 URL

安装

要安装 NSM Revved URL,请按照以下步骤操作

  1. 下载并解压缩文件,并将 nsmrevvedurl 目录放置到您的 craft/plugins 目录中
  2. - 或者 - 直接在您的 craft/plugins 文件夹中执行 git clone https://github.com/Newism/nsmrevvedurl.git。然后您可以使用 git pull 更新它
  3. - 或者 - 使用 Composer 通过 composer require nsm/craftcms-revved-url 安装
  4. 在 Craft 控制面板的“设置”>“插件”下安装插件
  5. 插件文件夹应命名为 nsmrevvedurl 以使 Craft 能够识别它。GitHub 最近开始在 zip 文件下载的文件夹名称中附加 -master(分支名称)。

NSM Revved URL 在 Craft 2.4.x 和 Craft 2.5.x 上工作。

用法

本地资产

很简单…只需调用函数并传递资产以及可选的转换

nsm_rev_asset_url(asset, transform)

重命名前

http://example.com/uploads/images/_572x430_crop_center-center_80/James-Ellis_elevation-render-1.jpg

重命名后

http://example.com/uploads/images/_572x430_crop_center-center_80/James-Ellis_elevation-render-1.1485302752.jpg

Imager 支持

NSM Revved URL 支持通过包装 Imager 插件功能 Imager 转换和 craft.imager.srcset()

返回重命名的 URL

{{ nsm_rev_imager_url(newsImage, transform) }}

返回重命名的 Imager 模型

注意,这会替换原始的 url 属性

{% set revvedImagerAsset = nsm_rev_imager_asset(newsImage, transform) }}
  
{# output the revved URL #}
{{ revvedImagerAsset.url }}

返回用于 craft.imager.srcset() 的重命名的 Imager 模型

{% set revvedImagerAsset = nsm_rev_imager_asset(newsImage, [transform1, transform2]) }}
{{ craft.imager.srcset(revvedImagerAsset) }}

更新您的服务器配置

此插件实际上不会更改服务器上的文件名。您需要在服务器上实现重写规则。

Apache

请参阅:https://github.com/h5bp/server-configs-apache/blob/master/dist/.htaccess#L968-L984

# ----------------------------------------------------------------------
# | Filename-based cache busting                                       |
# ----------------------------------------------------------------------

# If you're not using a build process to manage your filename version
# revving, you might want to consider enabling the following directives
# to route all requests such as `/style.12345.css` to `/style.css`.
#
# To understand why this is important and even a better solution than
# using something like `*.css?v231`, please see:
# http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/

# <IfModule mod_rewrite.c>
#     RewriteEngine On
#     RewriteCond %{REQUEST_FILENAME} !-f
#     RewriteRule ^(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ $1.$3 [L]
# </IfModule>

NGINX

请参阅:https://github.com/h5bp/server-configs-nginx/blob/master/h5bp/location/cache-busting.conf#L1-L10

# Built-in filename-based cache busting

# This will route all requests for /css/style.20120716.css to /css/style.css
# Read also this: github.com/h5bp/html5-boilerplate/wiki/cachebusting
# This is not included by default, because it'd be better if you use the build
# script to manage the file names.
location ~* (.+)\.(?:\d+)\.(js|css|png|jpg|jpeg|gif)$ {
  try_files $uri $1.$2;
}

Leevi Graham 提供