make sitemap ignore list configurable, use it to hide extensionless output files
This commit is contained in:
parent
c7dd4615c7
commit
9afdd5ba4e
2 changed files with 25 additions and 12 deletions
|
@ -4,6 +4,21 @@ require 'find'
|
||||||
module Middleman::CoreExtensions::Sitemap
|
module Middleman::CoreExtensions::Sitemap
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
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
|
app.send :include, InstanceMethods
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
|
|
|
@ -98,21 +98,15 @@ module Middleman::Sitemap
|
||||||
end
|
end
|
||||||
|
|
||||||
def touch_file(file)
|
def touch_file(file)
|
||||||
return false if file == @source ||
|
return false if file == @source || File.directory?(file)
|
||||||
file.match(/^\./) ||
|
|
||||||
(file.match(/\/\./) && !file.match(/\/\.htaccess/)) ||
|
|
||||||
(file.match(/\/_/) && !file.match(/\/__/)) ||
|
|
||||||
File.directory?(file)
|
|
||||||
|
|
||||||
path = file_to_path(file)
|
|
||||||
|
|
||||||
|
path = file_to_path(file)
|
||||||
return false unless path
|
return false unless path
|
||||||
|
|
||||||
return false if path.match(%r{^layout}) ||
|
return false if @app.ignored_sitemap_matchers.any? do |name, callback|
|
||||||
path.match(%r{^layouts/})
|
callback.call(file, path)
|
||||||
|
end
|
||||||
# @app.logger.debug :sitemap_update, Time.now, path if @app.logging?
|
|
||||||
|
|
||||||
# Add generic path
|
# Add generic path
|
||||||
p = page(path)
|
p = page(path)
|
||||||
p.source_file = File.expand_path(file, @app.root)
|
p.source_file = File.expand_path(file, @app.root)
|
||||||
|
@ -121,6 +115,10 @@ module Middleman::Sitemap
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sitemap_should_ignore?(file, path)
|
||||||
|
@app.sitemap_ignore.every(&:call)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def extensionless_path(file)
|
def extensionless_path(file)
|
||||||
app.cache.fetch(:extensionless_path, file) do
|
app.cache.fetch(:extensionless_path, file) do
|
||||||
|
|
Loading…
Add table
Reference in a new issue