2013-04-20 23:27:25 +02:00
|
|
|
# The Cache Buster extension
|
|
|
|
class Middleman::Extensions::CacheBuster < ::Middleman::Extension
|
2014-08-14 19:14:26 +02:00
|
|
|
option :exts, %w(.css .png .jpg .jpeg .webp .svg .svgz .js .gif), 'List of extensions that get cache busters strings appended to them.'
|
2014-04-07 21:43:16 +02:00
|
|
|
option :sources, %w(.htm .html .php .css .js), 'List of extensions that are searched for bustable assets.'
|
|
|
|
option :ignore, [], 'Regexes of filenames to skip adding query strings to'
|
2016-01-09 16:06:47 +01:00
|
|
|
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
|
2014-04-07 21:43:16 +02:00
|
|
|
|
2013-04-20 23:27:25 +02:00
|
|
|
def initialize(app, options_hash={}, &block)
|
|
|
|
super
|
|
|
|
|
2016-01-14 02:16:36 +01:00
|
|
|
app.rewrite_inline_urls id: :cache_buster,
|
|
|
|
url_extensions: options.exts,
|
|
|
|
source_extensions: options.sources,
|
|
|
|
ignore: options.ignore,
|
|
|
|
rewrite_ignore: options.rewrite_ignore,
|
|
|
|
proc: method(:rewrite_url)
|
2014-04-07 21:43:16 +02:00
|
|
|
end
|
2013-04-20 23:27:25 +02:00
|
|
|
|
2014-07-03 04:04:34 +02:00
|
|
|
Contract String, Or[String, Pathname], Any => String
|
2014-06-16 18:05:24 +02:00
|
|
|
def rewrite_url(asset_path, _dirpath, _request_path)
|
2014-04-07 21:43:16 +02:00
|
|
|
asset_path + '?' + Time.now.strftime('%s')
|
2011-11-21 09:23:16 +01:00
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
end
|