diff --git a/middleman-cli/lib/middleman-cli/build.rb b/middleman-cli/lib/middleman-cli/build.rb index d6cf884b..7d5dd3af 100644 --- a/middleman-cli/lib/middleman-cli/build.rb +++ b/middleman-cli/lib/middleman-cli/build.rb @@ -63,9 +63,8 @@ module Middleman::Cli @app = ::Middleman::Application.new do config[:mode] = :build 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 end end diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index d02a6a9b..edc28ade 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -160,6 +160,10 @@ module Middleman # @return [Array.] 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.] + 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. # @return [String] define_setting :encoding, 'utf-8', 'Default string encoding for templates and output' diff --git a/middleman-core/lib/middleman-core/extensions/asset_hash.rb b/middleman-core/lib/middleman-core/extensions/asset_hash.rb index 247d1160..b38bab9f 100644 --- a/middleman-core/lib/middleman-core/extensions/asset_hash.rb +++ b/middleman-core/lib/middleman-core/extensions/asset_hash.rb @@ -3,7 +3,7 @@ require 'middleman-core/rack' 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 :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 :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 @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, - url_extensions: options.exts.sort.reverse, + url_extensions: @exts.sort.reverse, source_extensions: options.sources, ignore: @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']] 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 resource.ignored? diff --git a/middleman-core/lib/middleman-core/extensions/asset_host.rb b/middleman-core/lib/middleman-core/extensions/asset_host.rb index 9793960a..f7c7e8fc 100644 --- a/middleman-core/lib/middleman-core/extensions/asset_host.rb +++ b/middleman-core/lib/middleman-core/extensions/asset_host.rb @@ -2,7 +2,7 @@ require 'addressable/uri' class Middleman::Extensions::AssetHost < ::Middleman::Extension 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 :ignore, [], 'Regexes of filenames to skip adding query strings to' option :rewrite_ignore, [], 'Regexes of filenames to skip processing for host rewrites' @@ -11,7 +11,7 @@ class Middleman::Extensions::AssetHost < ::Middleman::Extension super app.rewrite_inline_urls id: :asset_host, - url_extensions: options.exts, + url_extensions: options.exts || app.config[:asset_extensions], source_extensions: options.sources, ignore: options.ignore, rewrite_ignore: options.rewrite_ignore, diff --git a/middleman-core/lib/middleman-core/extensions/cache_buster.rb b/middleman-core/lib/middleman-core/extensions/cache_buster.rb index 958bd203..2de11632 100644 --- a/middleman-core/lib/middleman-core/extensions/cache_buster.rb +++ b/middleman-core/lib/middleman-core/extensions/cache_buster.rb @@ -1,6 +1,6 @@ # The Cache Buster 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 :ignore, [], 'Regexes of filenames to skip adding query strings to' option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites' @@ -9,7 +9,7 @@ class Middleman::Extensions::CacheBuster < ::Middleman::Extension super app.rewrite_inline_urls id: :cache_buster, - url_extensions: options.exts, + url_extensions: options.exts || app.config[:asset_extensions], source_extensions: options.sources, ignore: options.ignore, rewrite_ignore: options.rewrite_ignore, diff --git a/middleman-core/lib/middleman-core/extensions/relative_assets.rb b/middleman-core/lib/middleman-core/extensions/relative_assets.rb index 7fcb80d2..b319de1b 100644 --- a/middleman-core/lib/middleman-core/extensions/relative_assets.rb +++ b/middleman-core/lib/middleman-core/extensions/relative_assets.rb @@ -2,7 +2,7 @@ require 'addressable/uri' # Relative Assets 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 :ignore, [], 'Regexes of filenames to skip adding query strings to' option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites' @@ -11,7 +11,7 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension super app.rewrite_inline_urls id: :asset_hash, - url_extensions: options.exts, + url_extensions: options.exts || app.config[:asset_extensions], source_extensions: options.sources, ignore: options.ignore, rewrite_ignore: options.rewrite_ignore, diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index b10076d7..293a334f 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -140,9 +140,8 @@ module Middleman ) 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 end ready do