Create a single default list of asset extensions. Add .ico to it. Fixes #1830.
This commit is contained in:
parent
bca8b854dd
commit
5a2f9c8ca6
7 changed files with 19 additions and 13 deletions
|
@ -63,9 +63,8 @@ module Middleman::Cli
|
||||||
@app = ::Middleman::Application.new do
|
@app = ::Middleman::Application.new do
|
||||||
config[:mode] = :build
|
config[:mode] = :build
|
||||||
config[:show_exceptions] = false
|
config[:show_exceptions] = false
|
||||||
config[:cli_options] = cli_options.reduce({}) do |sum, (k, v)|
|
config[:cli_options] = cli_options.each_with_object({}) do |(k, v), sum|
|
||||||
sum[k] = v unless v == :undefined
|
sum[k] = v unless v == :undefined
|
||||||
sum
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -160,6 +160,10 @@ module Middleman
|
||||||
# @return [Array.<String>]
|
# @return [Array.<String>]
|
||||||
define_setting :extensions_with_layout, %w(.htm .html .xhtml .php), 'Which file extensions have a layout by default.'
|
define_setting :extensions_with_layout, %w(.htm .html .xhtml .php), 'Which file extensions have a layout by default.'
|
||||||
|
|
||||||
|
# Which file extensions are "assets."
|
||||||
|
# @return [Array.<String>]
|
||||||
|
define_setting :asset_extensions, %w(.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2 .eot .ico .map), 'Which file extensions are treated as assets.'
|
||||||
|
|
||||||
# Default string encoding for templates and output.
|
# Default string encoding for templates and output.
|
||||||
# @return [String]
|
# @return [String]
|
||||||
define_setting :encoding, 'utf-8', 'Default string encoding for templates and output'
|
define_setting :encoding, 'utf-8', 'Default string encoding for templates and output'
|
||||||
|
|
|
@ -3,7 +3,7 @@ require 'middleman-core/rack'
|
||||||
|
|
||||||
class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
||||||
option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for hashable assets.'
|
option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for hashable assets.'
|
||||||
option :exts, %w(.jpg .jpeg .png .gif .webp .js .css .otf .woff .woff2 .eot .ttf .svg .svgz .map), 'List of extensions that get asset hashes appended to them.'
|
option :exts, nil, 'List of extensions that get asset hashes appended to them.'
|
||||||
option :ignore, [], 'Regexes of filenames to skip adding asset hashes to'
|
option :ignore, [], 'Regexes of filenames to skip adding asset hashes to'
|
||||||
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
|
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
|
||||||
|
|
||||||
|
@ -17,8 +17,12 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
||||||
# Allow specifying regexes to ignore, plus always ignore apple touch icons
|
# Allow specifying regexes to ignore, plus always ignore apple touch icons
|
||||||
@ignore = Array(options.ignore) + [/^apple-touch-icon/]
|
@ignore = Array(options.ignore) + [/^apple-touch-icon/]
|
||||||
|
|
||||||
|
# Exclude .ico from the default list because browsers expect it
|
||||||
|
# to be named "favicon.ico"
|
||||||
|
@exts = options.exts || (app.config[:asset_extensions] - %w(.ico))
|
||||||
|
|
||||||
app.rewrite_inline_urls id: :asset_hash,
|
app.rewrite_inline_urls id: :asset_hash,
|
||||||
url_extensions: options.exts.sort.reverse,
|
url_extensions: @exts.sort.reverse,
|
||||||
source_extensions: options.sources,
|
source_extensions: options.sources,
|
||||||
ignore: @ignore,
|
ignore: @ignore,
|
||||||
rewrite_ignore: options.rewrite_ignore,
|
rewrite_ignore: options.rewrite_ignore,
|
||||||
|
@ -70,7 +74,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
||||||
|
|
||||||
Contract IsA['Middleman::Sitemap::Resource'] => Maybe[IsA['Middleman::Sitemap::Resource']]
|
Contract IsA['Middleman::Sitemap::Resource'] => Maybe[IsA['Middleman::Sitemap::Resource']]
|
||||||
def manipulate_single_resource(resource)
|
def manipulate_single_resource(resource)
|
||||||
return unless options.exts.include?(resource.ext)
|
return unless @exts.include?(resource.ext)
|
||||||
return if ignored_resource?(resource)
|
return if ignored_resource?(resource)
|
||||||
return if resource.ignored?
|
return if resource.ignored?
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'addressable/uri'
|
||||||
|
|
||||||
class Middleman::Extensions::AssetHost < ::Middleman::Extension
|
class Middleman::Extensions::AssetHost < ::Middleman::Extension
|
||||||
option :host, nil, 'The asset host to use or a Proc to determine asset host', required: true
|
option :host, nil, 'The asset host to use or a Proc to determine asset host', required: true
|
||||||
option :exts, %w(.jpg .jpeg .png .gif .webp .js .css .otf .woff .woff2 .eot .ttf .svg .svgz .map), 'List of extensions that get cache busters strings appended to them.'
|
option :exts, nil, 'List of extensions that get cache busters strings appended to them.'
|
||||||
option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for bustable assets.'
|
option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for bustable assets.'
|
||||||
option :ignore, [], 'Regexes of filenames to skip adding query strings to'
|
option :ignore, [], 'Regexes of filenames to skip adding query strings to'
|
||||||
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for host rewrites'
|
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for host rewrites'
|
||||||
|
@ -11,7 +11,7 @@ class Middleman::Extensions::AssetHost < ::Middleman::Extension
|
||||||
super
|
super
|
||||||
|
|
||||||
app.rewrite_inline_urls id: :asset_host,
|
app.rewrite_inline_urls id: :asset_host,
|
||||||
url_extensions: options.exts,
|
url_extensions: options.exts || app.config[:asset_extensions],
|
||||||
source_extensions: options.sources,
|
source_extensions: options.sources,
|
||||||
ignore: options.ignore,
|
ignore: options.ignore,
|
||||||
rewrite_ignore: options.rewrite_ignore,
|
rewrite_ignore: options.rewrite_ignore,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# The Cache Buster extension
|
# The Cache Buster extension
|
||||||
class Middleman::Extensions::CacheBuster < ::Middleman::Extension
|
class Middleman::Extensions::CacheBuster < ::Middleman::Extension
|
||||||
option :exts, %w(.css .png .jpg .jpeg .webp .svg .svgz .js .gif), 'List of extensions that get cache busters strings appended to them.'
|
option :exts, nil, 'List of extensions that get cache busters strings appended to them.'
|
||||||
option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for bustable assets.'
|
option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for bustable assets.'
|
||||||
option :ignore, [], 'Regexes of filenames to skip adding query strings to'
|
option :ignore, [], 'Regexes of filenames to skip adding query strings to'
|
||||||
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
|
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
|
||||||
|
@ -9,7 +9,7 @@ class Middleman::Extensions::CacheBuster < ::Middleman::Extension
|
||||||
super
|
super
|
||||||
|
|
||||||
app.rewrite_inline_urls id: :cache_buster,
|
app.rewrite_inline_urls id: :cache_buster,
|
||||||
url_extensions: options.exts,
|
url_extensions: options.exts || app.config[:asset_extensions],
|
||||||
source_extensions: options.sources,
|
source_extensions: options.sources,
|
||||||
ignore: options.ignore,
|
ignore: options.ignore,
|
||||||
rewrite_ignore: options.rewrite_ignore,
|
rewrite_ignore: options.rewrite_ignore,
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'addressable/uri'
|
||||||
|
|
||||||
# Relative Assets extension
|
# Relative Assets extension
|
||||||
class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
||||||
option :exts, %w(.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2 .eot), 'List of extensions that get cache busters strings appended to them.'
|
option :exts, nil, 'List of extensions that get cache busters strings appended to them.'
|
||||||
option :sources, %w(.css .htm .html .xhtml), 'List of extensions that are searched for relative assets.'
|
option :sources, %w(.css .htm .html .xhtml), 'List of extensions that are searched for relative assets.'
|
||||||
option :ignore, [], 'Regexes of filenames to skip adding query strings to'
|
option :ignore, [], 'Regexes of filenames to skip adding query strings to'
|
||||||
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
|
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
|
||||||
|
@ -11,7 +11,7 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
||||||
super
|
super
|
||||||
|
|
||||||
app.rewrite_inline_urls id: :asset_hash,
|
app.rewrite_inline_urls id: :asset_hash,
|
||||||
url_extensions: options.exts,
|
url_extensions: options.exts || app.config[:asset_extensions],
|
||||||
source_extensions: options.sources,
|
source_extensions: options.sources,
|
||||||
ignore: options.ignore,
|
ignore: options.ignore,
|
||||||
rewrite_ignore: options.rewrite_ignore,
|
rewrite_ignore: options.rewrite_ignore,
|
||||||
|
|
|
@ -140,9 +140,8 @@ module Middleman
|
||||||
)
|
)
|
||||||
|
|
||||||
app = ::Middleman::Application.new do
|
app = ::Middleman::Application.new do
|
||||||
cli_options.reduce({}) do |sum, (k, v)|
|
cli_options.each_with_object({}) do |(k, v), sum|
|
||||||
sum[k] = v unless v == :undefined
|
sum[k] = v unless v == :undefined
|
||||||
sum
|
|
||||||
end
|
end
|
||||||
|
|
||||||
ready do
|
ready do
|
||||||
|
|
Loading…
Reference in a new issue