Skip to content

Commit

Permalink
adds conditional for recovering dir paths fixes #22
Browse files Browse the repository at this point in the history
The process of creating a relative path from an absolute one seems to
strip the trailing slash, identifying a path as a directory not a file.

When this is converted into a Regex for adding to the ignore list, it
also ignores files that start with the same name as ignored directories.

This fix simply checks whether there was originally a trailing slash,
then adds it again before it is converted into a regular expression.
  • Loading branch information
danprince authored and DirtyF committed Aug 23, 2018
1 parent dd0b1fd commit e498edb
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions lib/jekyll/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,21 @@ def config_files(options)
end

def to_exclude(options)
# prepending a slash to the destination directory will ensure that
# other files starting with _site aren't also ignored by Listen
destination = "#{options['destination']}/"

[
config_files(options),
options["destination"],
custom_excludes(options),
destination,
custom_excludes(options)
].flatten
end

def has_trailing_slash(path)
path[-1] == '/'
end

# Paths to ignore for the watch option
#
# options - A Hash of options passed to the command
Expand All @@ -95,14 +103,19 @@ def listen_ignore_paths(options)
paths = to_exclude(options)

paths.map do |p|
is_dir = has_trailing_slash(p)
absolute_path = Pathname.new(p).expand_path
next unless absolute_path.exist?
begin
relative_path = absolute_path.relative_path_from(source).to_s
unless relative_path.start_with?("../")
path_to_ignore = Regexp.new(Regexp.escape(relative_path))
Jekyll.logger.debug "Watcher:", "Ignoring #{path_to_ignore}"
path_to_ignore
begin
relative_path = absolute_path.relative_path_from(source).to_s
recovered_path = is_dir ? "#{relative_path}/" : relative_path
unless recovered_path.start_with?('../')
path_to_ignore = Regexp.new(Regexp.escape(recovered_path))
path_to_ignore
Jekyll.logger.debug "Watcher:", "Ignoring #{path_to_ignore}"
end
rescue ArgumentError
# Could not find a relative path
end
rescue ArgumentError
# Could not find a relative path
Expand Down

0 comments on commit e498edb

Please sign in to comment.