From e498edb3cd922273c2c48729992eef738306494b Mon Sep 17 00:00:00 2001 From: danprince Date: Tue, 24 Nov 2015 11:23:10 +0530 Subject: [PATCH] adds conditional for recovering dir paths fixes #22 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. --- lib/jekyll/watcher.rb | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/jekyll/watcher.rb b/lib/jekyll/watcher.rb index b172a3a..ea3b593 100644 --- a/lib/jekyll/watcher.rb +++ b/lib/jekyll/watcher.rb @@ -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 @@ -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