From 023ea9f34ef87d0103a1122aacfc94d27c003ed8 Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Mon, 8 Apr 2013 00:50:58 -0700 Subject: [PATCH] Process resources for asset_hash extension in a specific order. This makes sure static assets (images, fonts) get their paths modified before assets that include them (css, js). --- .../lib/middleman-more/extensions/asset_hash.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/middleman-more/lib/middleman-more/extensions/asset_hash.rb b/middleman-more/lib/middleman-more/extensions/asset_hash.rb index 354ee81e..2390e1f4 100644 --- a/middleman-more/lib/middleman-more/extensions/asset_hash.rb +++ b/middleman-more/lib/middleman-more/extensions/asset_hash.rb @@ -35,7 +35,18 @@ module Middleman # Update the main sitemap resource list # @return [void] def manipulate_resource_list(resources) - resources.each do |resource| + # Process resources in order: binary images and fonts, then SVG, then JS/CSS. + # 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 + 0 + elsif %w(.js .css).include? a.ext + 1 + else + -1 + end + end.each do |resource| next unless @exts.include? resource.ext next if @ignore.any? { |ignore| Middleman::Util.path_match(ignore, resource.destination_path) }