diff --git a/middleman-core/lib/middleman-core/sitemap/page.rb b/middleman-core/lib/middleman-core/sitemap/page.rb index a3e1b3f9..e2470716 100644 --- a/middleman-core/lib/middleman-core/sitemap/page.rb +++ b/middleman-core/lib/middleman-core/sitemap/page.rb @@ -113,18 +113,6 @@ module Middleman::Sitemap store.ignore(self.path) end - # If this is a template, refresh contents - # @return [void] - def touch - template.touch if template? - end - - # If this is a template, remove contents - # @return [void] - def delete - template.delete if template? - end - # Render this page # @return [String] def render(*args, &block) @@ -250,6 +238,26 @@ module Middleman::Sitemap return [] unless parent parent.children.reject { |p| p == self } end + + # A cache for extensions and internals to use to store + # information about this page. The cache is cleared whenever + # the page changes. + # @return [Middleman::Cache] + def cache + @cache ||= Middleman::Cache.new + end + + # Clear out the cache whenever this page changes + # @return [void] + def touch + cache.clear + end + + # Clear the cache if the file is deleted + # @return [void] + def delete + cache.clear + end protected diff --git a/middleman-core/lib/middleman-core/sitemap/template.rb b/middleman-core/lib/middleman-core/sitemap/template.rb index aea97518..87a52a87 100644 --- a/middleman-core/lib/middleman-core/sitemap/template.rb +++ b/middleman-core/lib/middleman-core/sitemap/template.rb @@ -31,22 +31,10 @@ module Middleman::Sitemap # Simple aliases delegate :path, :source_file, :store, :app, :ext, :to => :page - # Clear internal frontmatter cache for file if it changes - # @return [void] - def touch - app.cache.remove(:metadata, source_file) - end - - # Clear internal frontmatter cache for file if it is deleted - # @return [void] - def delete - app.cache.remove(:metadata, source_file) - end - # Get the metadata for both the current source_file and the current path # @return [Hash] def metadata - metadata = app.cache.fetch(:metadata, source_file) do + metadata = @page.cache.fetch(:metadata) do data = { :options => {}, :locals => {}, :page => {}, :blocks => [] } app.provides_metadata.each do |callback, matcher| @@ -104,4 +92,4 @@ module Middleman::Sitemap result end end -end \ No newline at end of file +end diff --git a/middleman-more/lib/middleman-more/extensions/asset_hash.rb b/middleman-more/lib/middleman-more/extensions/asset_hash.rb index abba4ffc..3461fc36 100755 --- a/middleman-more/lib/middleman-more/extensions/asset_hash.rb +++ b/middleman-more/lib/middleman-more/extensions/asset_hash.rb @@ -8,7 +8,7 @@ module Middleman::Extensions app.after_configuration do sitemap.reroute do |destination, page| if exts.include? page.ext - app.cache.fetch(:asset_hash, page.path) do + page.cache.fetch(:asset_hash) do digest = Digest::SHA1.file(page.source_file).hexdigest[0..7] destination.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" } end