middleman/middleman — pull request #528 by rumpuslabs (2012-07-11 06:37:20+00:00)
Title: Sitemap patches

Two small patches :-

First is a simple optimisation that I noticed while poking around in the code, there's no need to call `Hash#[]` before `Hash#delete` because `Hash#delete` will return the deleted object.

Second is the more significant (controversial?) patch, to regenerate the lookup cache between each sitemap extension so that later extensions can access the metadata of proxied pages generated by earlier extensions.

The problem occurs when an extension calls `Resource#metadata` within `manipulate_resource_list`:
```
Sitemap::Store#rebuild_resource_list!
-> MyExtension#manipulate_resource_list
-> Resource#metadata
-> Resource#source_file
-> Proxies::ResourceInstanceMethods#get_source_file
-> Sitemap::Store#find_resource_by_path
```

`find_resource_by_path` fails because `rebuild_resource_list!` cleared out `@_lookup_cache` before it started:
```
middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb:60:in `get_source_file': Path blog/tags/example.html proxies to unknown file blog/tag.html:[] (RuntimeError)
```

There will be a performance cost proportional to the number of sitemap extensions but it allows an extension to e.g. check the page's front matter when deciding what to do, even if the page is a proxy. There may be a better way to do this that doesn't involve the performance hit but I couldn't see it.