diff --git a/middleman-core/features/asset_hash.feature b/middleman-core/features/asset_hash.feature index 751b9e30..7d23ae6b 100644 --- a/middleman-core/features/asset_hash.feature +++ b/middleman-core/features/asset_hash.feature @@ -107,7 +107,45 @@ Feature: Assets get file hashes appended to them and references to them are upda And I should see 'src="images/100px-5fd6fb90.jpg"' And I should see 'srcset="images/100px-5fd6fb90.jpg 1x, images/200px-c11eb203.jpg 2x, images/300px-59adce76.jpg 3x"' - Scenario: Enabling an asset host still produces hashed files and references + Scenario: Enabling an asset host still produces hashed files and references (hash first) + Given a fixture app "asset-hash-host-app" + And a file named "config.rb" with: + """ + activate :asset_hash + activate :directory_indexes + activate :asset_host, host: 'http://middlemanapp.com' + """ + Given the Server is running at "asset-hash-host-app" + When I go to "/" + Then I should see 'href="http://middlemanapp.com/stylesheets/site-4b64a653.css"' + Then I should see 'href="http://middlemanapp.com/stylesheets/fragment-a772891f.css"' + And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg"' + And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg?test"' + And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg?#test"' + And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg#test"' + When I go to "/subdir/" + Then I should see 'href="http://middlemanapp.com/stylesheets/site-4b64a653.css"' + And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg"' + When I go to "/other/" + Then I should see 'href="http://middlemanapp.com/stylesheets/site-4b64a653.css"' + And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg"' + And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg?test"' + And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg?#test"' + And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg#test"' + When I go to "/stylesheets/fragment-a772891f.css" + And I should see 'url("http://middlemanapp.com/images/100px-5fd6fb90.jpg")' + And I should see 'url("http://middlemanapp.com/images/100px-5fd6fb90.jpg?test")' + And I should see 'url("http://middlemanapp.com/images/100px-5fd6fb90.jpg?#test")' + And I should see 'url("http://middlemanapp.com/images/100px-5fd6fb90.jpg#test")' + + Scenario: Enabling an asset host still produces hashed files and references (host first) + Given a fixture app "asset-hash-host-app" + And a file named "config.rb" with: + """ + activate :asset_host, host: 'http://middlemanapp.com' + activate :directory_indexes + activate :asset_hash + """ Given the Server is running at "asset-hash-host-app" When I go to "/" Then I should see 'href="http://middlemanapp.com/stylesheets/site-4b64a653.css"' diff --git a/middleman-core/fixtures/asset-hash-host-app/config.rb b/middleman-core/fixtures/asset-hash-host-app/config.rb deleted file mode 100644 index 085caeb7..00000000 --- a/middleman-core/fixtures/asset-hash-host-app/config.rb +++ /dev/null @@ -1,4 +0,0 @@ - -activate :asset_hash -activate :directory_indexes -activate :asset_host, host: 'http://middlemanapp.com' diff --git a/middleman-core/fixtures/asset-hash-host-app/source/index.html.erb b/middleman-core/fixtures/asset-hash-host-app/source/index.html.erb index ea81c790..c9fefc2a 100644 --- a/middleman-core/fixtures/asset-hash-host-app/source/index.html.erb +++ b/middleman-core/fixtures/asset-hash-host-app/source/index.html.erb @@ -3,7 +3,7 @@ <% end %>

Image url:

-<%= image_tag('100px.jpg') %> + <%= image_tag('100px.jpg?test') %> <%= image_tag('100px.jpg?#test') %> <%= image_tag('100px.jpg#test') %> diff --git a/middleman-core/lib/middleman-core/core_extensions/inline_url_rewriter.rb b/middleman-core/lib/middleman-core/core_extensions/inline_url_rewriter.rb index a7f7e778..7d42b667 100644 --- a/middleman-core/lib/middleman-core/core_extensions/inline_url_rewriter.rb +++ b/middleman-core/lib/middleman-core/core_extensions/inline_url_rewriter.rb @@ -17,7 +17,8 @@ module Middleman proc: Or[Proc, Method], url_extensions: ArrayOf[String], source_extensions: ArrayOf[String], - ignore: ArrayOf[IGNORE_DESCRIPTOR] + ignore: ArrayOf[IGNORE_DESCRIPTOR], + after: Maybe[Symbol] }.freeze def initialize(app, options_hash={}, &block) @@ -32,8 +33,15 @@ module Middleman end def after_configuration - app.use Rack, rewriters: @rewriters.values, - middleman_app: @app + rewriters = @rewriters.values.sort do |a, b| + if b[:after] && b[:after] == a[:id] + 1 + else + 0 + end + end + + app.use Rack, rewriters: rewriters, middleman_app: @app end class Rack diff --git a/middleman-core/lib/middleman-core/extensions/asset_hash.rb b/middleman-core/lib/middleman-core/extensions/asset_hash.rb index 7122eb10..ac464b69 100644 --- a/middleman-core/lib/middleman-core/extensions/asset_hash.rb +++ b/middleman-core/lib/middleman-core/extensions/asset_hash.rb @@ -22,7 +22,8 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension source_extensions: options.sources, ignore: @ignore, rewrite_ignore: options.rewrite_ignore, - proc: method(:rewrite_url) + proc: method(:rewrite_url), + after: :asset_host end Contract String, Or[String, Pathname], Any => Maybe[String]