make sitemap ignore list configurable, use it to hide extensionless output files

This commit is contained in:
Thomas Reynolds 2011-12-27 18:47:03 -08:00
parent c7dd4615c7
commit 9afdd5ba4e
2 changed files with 25 additions and 12 deletions

View file

@ -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

View file

@ -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