Only rewrite urls in sitemap. Fixes #1873
This commit is contained in:
parent
4791e01f10
commit
b794961916
40 changed files with 28 additions and 18 deletions
4
Gemfile
4
Gemfile
|
@ -5,9 +5,7 @@ gem 'rake', '~> 10.3', require: false
|
|||
gem 'yard', '~> 0.8', require: false
|
||||
|
||||
# Test tools
|
||||
gem 'pry', '~> 0.10', group: :development, require: false
|
||||
gem 'pry-byebug'
|
||||
gem 'pry-stack_explorer'
|
||||
gem 'byebug'
|
||||
gem 'aruba', '~> 0.7.4', require: false
|
||||
gem 'rspec', '~> 3.0', require: false
|
||||
gem 'cucumber', '~> 2.0', require: false
|
||||
|
|
|
@ -111,28 +111,29 @@ Feature: Assets get file hashes appended to them and references to them are upda
|
|||
Given a fixture app "asset-hash-host-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
set :sass_source_maps, false
|
||||
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-210612a0.css"'
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/fragment-7000b132.css"'
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/site-7474cadd.css"'
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/fragment-2902933e.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-210612a0.css"'
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/site-7474cadd.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-210612a0.css"'
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/site-7474cadd.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-7000b132.css"
|
||||
When I go to "/stylesheets/fragment-2902933e.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");'
|
||||
|
@ -142,28 +143,29 @@ Feature: Assets get file hashes appended to them and references to them are upda
|
|||
Given a fixture app "asset-hash-host-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
set :sass_source_maps, false
|
||||
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-210612a0.css"'
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/fragment-7000b132.css"'
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/site-7474cadd.css"'
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/fragment-2902933e.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-210612a0.css"'
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/site-7474cadd.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-210612a0.css"'
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/site-7474cadd.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-7000b132.css"
|
||||
When I go to "/stylesheets/fragment-2902933e.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")'
|
||||
|
|
|
@ -82,7 +82,7 @@ module Middleman
|
|||
dirpath = ::Pathname.new(File.dirname(path))
|
||||
|
||||
rewritten = ::Middleman::Util.instrument 'inline_url_rewriter', path: path do
|
||||
::Middleman::Util.rewrite_paths(body, path, all_asset_exts) do |asset_path|
|
||||
::Middleman::Util.rewrite_paths(body, path, all_asset_exts, @middleman_app) do |asset_path|
|
||||
uri = ::Addressable::URI.parse(asset_path)
|
||||
|
||||
relative_path = uri.host.nil?
|
||||
|
|
|
@ -20,8 +20,8 @@ module Middleman
|
|||
result
|
||||
end
|
||||
|
||||
Contract String, String, ArrayOf[String], Proc => String
|
||||
def rewrite_paths(body, _path, exts, &_block)
|
||||
Contract String, String, ArrayOf[String], IsA['::Middleman::Application'], Proc => String
|
||||
def rewrite_paths(body, path, exts, app, &_block)
|
||||
matcher = /([\'\"\(,]\s*|# sourceMappingURL=)([^\s\'\"\)\(>]+(#{::Regexp.union(exts)}))/
|
||||
|
||||
url_fn_prefix = 'url('
|
||||
|
@ -35,14 +35,24 @@ module Middleman
|
|||
asset_path = asset_path[url_fn_prefix.length..-1]
|
||||
end
|
||||
|
||||
current_resource = app.sitemap.find_resource_by_destination_path(path)
|
||||
|
||||
begin
|
||||
uri = ::Addressable::URI.parse(asset_path)
|
||||
|
||||
if uri.relative? && uri.host.nil? && !(asset_path =~ /^[^\/].*[a-z]+\.[a-z]+\/.*/) && (result = yield(asset_path))
|
||||
if uri.relative? && uri.host.nil? && !(asset_path =~ /^[^\/].*[a-z]+\.[a-z]+\/.*/)
|
||||
dest_path = ::Middleman::Util.url_for(app, asset_path, relative: false, current_resource: current_resource)
|
||||
|
||||
resource = app.sitemap.find_resource_by_destination_path(dest_path)
|
||||
|
||||
if resource && (result = yield(asset_path))
|
||||
"#{opening_character}#{result}"
|
||||
else
|
||||
match
|
||||
end
|
||||
else
|
||||
match
|
||||
end
|
||||
rescue ::Addressable::URI::InvalidURIError
|
||||
match
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue