add regexp support for option 'include','exclude'

This commit is contained in:
xiaojian cai 2013-01-06 21:23:31 +08:00
parent dd0e208daa
commit 44822a252e
1 changed files with 8 additions and 4 deletions

View File

@ -22,8 +22,8 @@ module Jekyll
self.lsi = config['lsi'] self.lsi = config['lsi']
self.pygments = config['pygments'] self.pygments = config['pygments']
self.permalink_style = config['permalink'].to_sym self.permalink_style = config['permalink'].to_sym
self.exclude = config['exclude'] || [] self.exclude = (config['exclude'] || []).map { |e| Regexp.new("^#{e}$") }
self.include = config['include'] || [] self.include = (config['include'] || []).map { |e| Regexp.new("^#{e}$") }
self.future = config['future'] self.future = config['future']
self.limit_posts = config['limit_posts'] || nil self.limit_posts = config['limit_posts'] || nil
@ -318,15 +318,19 @@ module Jekyll
# Returns the Array of filtered entries. # Returns the Array of filtered entries.
def filter_entries(entries) def filter_entries(entries)
entries.reject do |e| entries.reject do |e|
unless self.include.include?(e) unless regexp_include?(self.include, e)
['.', '_', '#'].include?(e[0..0]) || ['.', '_', '#'].include?(e[0..0]) ||
e[-1..-1] == '~' || e[-1..-1] == '~' ||
self.exclude.include?(e) || regexp_include?(self.exclude, e) ||
File.symlink?(e) File.symlink?(e)
end end
end end
end end
def regexp_include?(exps, e)
!(exps.index { |exp| !exp.match(e).nil? }).nil?
end
# Get the implementation class for the given Converter. # Get the implementation class for the given Converter.
# #
# klass - The Class of the Converter to fetch. # klass - The Class of the Converter to fetch.