diff --git a/lib/jekyll/watcher.rb b/lib/jekyll/watcher.rb index c2a0ba8..ae5e384 100644 --- a/lib/jekyll/watcher.rb +++ b/lib/jekyll/watcher.rb @@ -62,13 +62,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'], + 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 @@ -79,12 +87,16 @@ 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 + if 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)) + recovered_path = is_dir ? "#{relative_path}/" : relative_path + + unless recovered_path.start_with?('../') + path_to_ignore = Regexp.new(Regexp.escape(recovered_path)) Jekyll.logger.debug "Watcher:", "Ignoring #{path_to_ignore}" path_to_ignore end diff --git a/spec/watcher_spec.rb b/spec/watcher_spec.rb index 0b8c9b4..b20c19b 100644 --- a/spec/watcher_spec.rb +++ b/spec/watcher_spec.rb @@ -10,7 +10,7 @@ let(:options) { base_opts } let(:site) { instance_double(Jekyll::Site) } - let(:default_ignored) { [/_config\.yml/, /_site/, /\.jekyll\-metadata/] } + let(:default_ignored) { [/_config\.yml/, /#{Regexp.escape('_site/')}/, /\.jekyll\-metadata/] } subject { described_class } before(:each) do FileUtils.mkdir(options['destination']) if options['destination'] @@ -88,7 +88,7 @@ end context "with a custom destination" do - let(:default_ignored) { [/_config\.yml/, /_dest/, /\.jekyll\-metadata/] } + let(:default_ignored) { [/_config\.yml/, /#{Regexp.escape('_dest/')}/, /\.jekyll\-metadata/] } context "when source is absolute" do context "when destination is absolute" do