Get relative paths of directories to ignore

Use `Pathname#realpath` to get absolute paths so that
`Pathname#relative_path_from` will not raise an exception. Also add the
config files to this list.
This commit is contained in:
Ivan Tse 2014-05-28 01:16:34 -04:00
parent 6ba077cf37
commit c4434f27af
1 changed files with 12 additions and 6 deletions

View File

@ -58,13 +58,19 @@ module Jekyll
source = options['source']
destination = options['destination']
config_files = Configuration[options].config_files(options)
paths = config_files + Array(destination)
ignored = []
begin
dest = Pathname.new(destination).relative_path_from(Pathname.new(source)).to_s
ignored = Regexp.new(Regexp.escape(dest))
rescue ArgumentError
# Destination is outside the source, no need to ignore it.
ignored = nil
source_abs = Pathname.new(source).realpath
paths.each do |p|
path_abs = Pathname.new(p).realpath
begin
rel_path = path_abs.relative_path_from(source_abs).to_s
ignored << Regexp.new(Regexp.escape(rel_path)) unless rel_path.start_with?('../')
rescue ArgumentError
# Could not find a relative path
end
end
listener = Listen.to(