diff --git a/lib/middleman/core_extensions/sitemap.rb b/lib/middleman/core_extensions/sitemap.rb index 482f882e..e6e55ff5 100644 --- a/lib/middleman/core_extensions/sitemap.rb +++ b/lib/middleman/core_extensions/sitemap.rb @@ -4,6 +4,21 @@ require 'find' module Middleman::CoreExtensions::Sitemap class << self def registered(app) + app.set :ignored_sitemap_matchers, { + # dotfiles and folders in the root + :root_dotfiles => proc { |file, path| file.match(/^\./) }, + + # Files starting with an dot, but not .htaccess + :source_dotfiles => proc { |file, path| + (file.match(/\/\./) && !file.match(/\/\.htaccess/)) + }, + + # Files starting with an underscore, but not a double-underscore + :partials => proc { |file, path| (file.match(/\/_/) && !file.match(/\/__/)) }, + + # Files without any output extension (layouts, partials) + :extentionless => proc { |file, path| !path.match(/\./) }, + } app.send :include, InstanceMethods end alias :included :registered diff --git a/lib/middleman/sitemap/store.rb b/lib/middleman/sitemap/store.rb index 3c2688c3..3b90991d 100644 --- a/lib/middleman/sitemap/store.rb +++ b/lib/middleman/sitemap/store.rb @@ -98,21 +98,15 @@ module Middleman::Sitemap end def touch_file(file) - return false if file == @source || - file.match(/^\./) || - (file.match(/\/\./) && !file.match(/\/\.htaccess/)) || - (file.match(/\/_/) && !file.match(/\/__/)) || - File.directory?(file) - - path = file_to_path(file) + return false if file == @source || File.directory?(file) + path = file_to_path(file) return false unless path - return false if path.match(%r{^layout}) || - path.match(%r{^layouts/}) - - # @app.logger.debug :sitemap_update, Time.now, path if @app.logging? - + return false if @app.ignored_sitemap_matchers.any? do |name, callback| + callback.call(file, path) + end + # Add generic path p = page(path) p.source_file = File.expand_path(file, @app.root) @@ -121,6 +115,10 @@ module Middleman::Sitemap true end + def sitemap_should_ignore?(file, path) + @app.sitemap_ignore.every(&:call) + end + protected def extensionless_path(file) app.cache.fetch(:extensionless_path, file) do