Fix up inline url confusion
This commit is contained in:
parent
2403fa2d81
commit
b127283040
9 changed files with 73 additions and 32 deletions
|
@ -29,13 +29,13 @@ module Middleman::Cli
|
|||
::Middleman::Logger.singleton(opts[:debug] ? 0 : 1, opts[:instrumenting] || false)
|
||||
end
|
||||
|
||||
interact_with @app
|
||||
self.class.interact_with @app
|
||||
end
|
||||
|
||||
# Start an interactive console in the context of the provided object.
|
||||
# @param [Object] context
|
||||
# @return [void]
|
||||
def interact_with(context)
|
||||
def self.interact_with(context)
|
||||
IRB.setup nil
|
||||
IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
|
||||
require 'irb/ext/multi-irb'
|
||||
|
|
|
@ -2,8 +2,17 @@
|
|||
<title>The Middleman!</title>
|
||||
<% end %>
|
||||
|
||||
<h2>Abs</h2>
|
||||
<p>http://example.com/test.jpg</p>
|
||||
|
||||
<h2>Image url:</h2>
|
||||
<p><%= image_path('100px.jpg') %></p>
|
||||
<p><img src="<%= image_path('100px.jpg') %>"></p>
|
||||
|
||||
<h2>Image url2:</h2>
|
||||
<p><%= image_tag('200px.jpg') %></p>
|
||||
|
||||
<h2>Image url3:</h2>
|
||||
<p><img src="/images/100px.jpg"></p>
|
||||
|
||||
<h2>Autogenerated tests:</h2>
|
||||
<p>images/100px.jpg</p>
|
||||
|
|
|
@ -20,3 +20,23 @@
|
|||
<%= image_tag "blank32.gif" %>
|
||||
<%= image_tag "blank33.gif" %>
|
||||
<%= image_tag "blank34.gif" %>
|
||||
<%= image_tag "blank100.gif" %>
|
||||
<%= image_tag "blank101.gif" %>
|
||||
<%= image_tag "blank102.gif" %>
|
||||
<%= image_tag "blank103.gif" %>
|
||||
<%= image_tag "blank104.gif" %>
|
||||
<%= image_tag "blank1010.gif" %>
|
||||
<%= image_tag "blank1021.gif" %>
|
||||
<%= image_tag "blank1032.gif" %>
|
||||
<%= image_tag "blank1043.gif" %>
|
||||
<%= image_tag "blank1054.gif" %>
|
||||
<%= image_tag "blank1020.gif" %>
|
||||
<%= image_tag "blank1021.gif" %>
|
||||
<%= image_tag "blank1022.gif" %>
|
||||
<%= image_tag "blank1023.gif" %>
|
||||
<%= image_tag "blank1024.gif" %>
|
||||
<%= image_tag "blank1030.gif" %>
|
||||
<%= image_tag "blank1031.gif" %>
|
||||
<%= image_tag "blank1032.gif" %>
|
||||
<%= image_tag "blank1033.gif" %>
|
||||
<%= image_tag "blank1034.gif" %>
|
|
@ -1,3 +1,4 @@
|
|||
require 'addressable/uri'
|
||||
require 'middleman-core/util'
|
||||
|
||||
class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
||||
|
@ -9,7 +10,6 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
|
||||
require 'digest/sha1'
|
||||
require 'rack/mock'
|
||||
require 'uri'
|
||||
require 'middleman-core/middleware/inline_url_rewriter'
|
||||
end
|
||||
|
||||
|
@ -28,7 +28,8 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
|
||||
Contract String, Or[String, Pathname], Any => Maybe[String]
|
||||
def rewrite_url(asset_path, dirpath, _request_path)
|
||||
relative_path = Pathname.new(asset_path).relative?
|
||||
uri = ::Addressable::URI.parse(asset_path)
|
||||
relative_path = uri.path[0..0] != '/'
|
||||
|
||||
full_asset_path = if relative_path
|
||||
dirpath.join(asset_path).to_s
|
||||
|
@ -36,10 +37,11 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
asset_path
|
||||
end
|
||||
|
||||
return unless asset_page = app.sitemap.find_resource_by_path(full_asset_path)
|
||||
return unless asset_page = app.sitemap.find_resource_by_destination_path(full_asset_path) || app.sitemap.find_resource_by_path(full_asset_path)
|
||||
|
||||
replacement_path = "/#{asset_page.destination_path}"
|
||||
replacement_path = Pathname.new(replacement_path).relative_path_from(dirpath).to_s if relative_path
|
||||
|
||||
replacement_path
|
||||
end
|
||||
|
||||
|
@ -56,7 +58,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
# This is so by the time we get around to the text files (which may reference
|
||||
# images and fonts) the static assets' hashes are already calculated.
|
||||
resources.sort_by do |a|
|
||||
if %w(.svg).include? a.ext
|
||||
if %w(.svg .svgz).include? a.ext
|
||||
0
|
||||
elsif %w(.js .css).include? a.ext
|
||||
1
|
||||
|
@ -73,9 +75,10 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
return if resource.ignored?
|
||||
|
||||
# Render through the Rack interface so middleware and mounted apps get a shot
|
||||
response = @rack_client.get(URI.escape(resource.destination_path),
|
||||
'bypass_inline_url_rewriter_asset_hash' => 'true'
|
||||
)
|
||||
response = @rack_client.get(
|
||||
URI.escape(resource.destination_path),
|
||||
'bypass_inline_url_rewriter_asset_hash' => 'true'
|
||||
)
|
||||
|
||||
raise "#{resource.path} should be in the sitemap!" unless response.status == 200
|
||||
|
||||
|
@ -87,6 +90,8 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
|
||||
Contract IsA['Middleman::Sitemap::Resource'] => Bool
|
||||
def ignored_resource?(resource)
|
||||
@ignore.any? { |ignore| Middleman::Util.path_match(ignore, resource.destination_path) }
|
||||
@ignore.any? do |ignore|
|
||||
Middleman::Util.path_match(ignore, resource.destination_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require 'addressable/uri'
|
||||
require 'middleman-core/middleware/inline_url_rewriter'
|
||||
|
||||
class Middleman::Extensions::AssetHost < ::Middleman::Extension
|
||||
|
@ -18,7 +19,8 @@ class Middleman::Extensions::AssetHost < ::Middleman::Extension
|
|||
|
||||
Contract String, Or[String, Pathname], Any => String
|
||||
def rewrite_url(asset_path, dirpath, _request_path)
|
||||
relative_path = Pathname.new(asset_path).relative?
|
||||
uri = ::Addressable::URI.parse(asset_path)
|
||||
relative_path = uri.path[0..0] != '/'
|
||||
|
||||
full_asset_path = if relative_path
|
||||
dirpath.join(asset_path).to_s
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
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), 'List of extensions that get cache busters strings appended to them.'
|
||||
|
@ -22,7 +24,11 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
|||
|
||||
Contract String, Or[String, Pathname], Any => Maybe[String]
|
||||
def rewrite_url(asset_path, dirpath, request_path)
|
||||
relative_path = Pathname.new(asset_path).relative?
|
||||
uri = ::Addressable::URI.parse(asset_path)
|
||||
|
||||
return if uri.path[0..0] != '/'
|
||||
|
||||
relative_path = uri.host.nil?
|
||||
|
||||
full_asset_path = if relative_path
|
||||
dirpath.join(asset_path).to_s
|
||||
|
@ -30,9 +36,9 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
|||
asset_path
|
||||
end
|
||||
|
||||
return unless !full_asset_path.include?('//') && !asset_path.start_with?('data:')
|
||||
|
||||
current_dir = Pathname(request_path).dirname
|
||||
Pathname(full_asset_path).relative_path_from(current_dir).to_s
|
||||
result = Pathname(full_asset_path).relative_path_from(current_dir).to_s
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require 'middleman-core/util'
|
||||
require 'middleman-core/contracts'
|
||||
require 'rack'
|
||||
require 'rack/response'
|
||||
require 'addressable/uri'
|
||||
require 'middleman-core/util'
|
||||
require 'middleman-core/contracts'
|
||||
|
||||
module Middleman
|
||||
module Middleware
|
||||
|
@ -51,10 +52,13 @@ module Middleman
|
|||
|
||||
if path =~ /(^\/$)|(#{@source_exts_regex_text}$)/
|
||||
if body = ::Middleman::Util.extract_response_text(response)
|
||||
|
||||
dirpath = Pathname.new(File.dirname(path))
|
||||
|
||||
rewritten = ::Middleman::Util.rewrite_paths(body, path, @exts) do |asset_path|
|
||||
relative_path = Pathname.new(asset_path).relative?
|
||||
uri = ::Addressable::URI.parse(asset_path)
|
||||
|
||||
relative_path = uri.host.nil?
|
||||
|
||||
full_asset_path = if relative_path
|
||||
dirpath.join(asset_path).to_s
|
||||
|
@ -76,7 +80,7 @@ module Middleman
|
|||
[status, headers, response]
|
||||
end
|
||||
|
||||
Contract IGNORE_DESCRIPTOR => Bool
|
||||
Contract IGNORE_DESCRIPTOR, String => Bool
|
||||
def should_ignore?(validator, value)
|
||||
if validator.is_a? Regexp
|
||||
# Treat as Regexp
|
||||
|
|
|
@ -356,15 +356,10 @@ module Middleman
|
|||
opening_character = $1
|
||||
asset_path = $2
|
||||
|
||||
begin
|
||||
uri = ::Addressable::URI.parse(asset_path)
|
||||
|
||||
if uri.relative? && result = yield(asset_path)
|
||||
"#{opening_character}#{result}"
|
||||
else
|
||||
match
|
||||
end
|
||||
rescue
|
||||
uri = ::Addressable::URI.parse(asset_path)
|
||||
if uri.relative? && result = yield(asset_path)
|
||||
"#{opening_character}#{result}"
|
||||
else
|
||||
match
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue