From c25c9f526428a39e3b1b083321d7308ce4e2faa1 Mon Sep 17 00:00:00 2001 From: danprince Date: Tue, 24 Nov 2015 11:23:10 +0530 Subject: [PATCH 1/5] 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 | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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 From 2c5a24c038a84f0994ba63a65fe9132cd5d6c972 Mon Sep 17 00:00:00 2001 From: danprince Date: Tue, 24 Nov 2015 11:39:38 +0530 Subject: [PATCH 2/5] updates tests to reflect improved regex --- spec/watcher_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/watcher_spec.rb b/spec/watcher_spec.rb index 0b8c9b4..9cfb484 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/, /_site\//, /\.jekyll\-metadata/] } subject { described_class } before(:each) do FileUtils.mkdir(options['destination']) if options['destination'] From cb4d071d11e825d600dc8d448cb574f2312eaa83 Mon Sep 17 00:00:00 2001 From: danprince Date: Tue, 24 Nov 2015 23:22:06 +0530 Subject: [PATCH 3/5] fixes test cases for ignoring custom dest directory --- spec/watcher_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/watcher_spec.rb b/spec/watcher_spec.rb index 9cfb484..1c6a32a 100644 --- a/spec/watcher_spec.rb +++ b/spec/watcher_spec.rb @@ -88,7 +88,7 @@ end context "with a custom destination" do - let(:default_ignored) { [/_config\.yml/, /_dest/, /\.jekyll\-metadata/] } + let(:default_ignored) { [/_config\.yml/, /_dest\//, /\.jekyll\-metadata/] } context "when source is absolute" do context "when destination is absolute" do From 86725d124426904f021e88a9e868c5da7e4b4ffc Mon Sep 17 00:00:00 2001 From: danprince Date: Sat, 28 Nov 2015 15:59:36 +0530 Subject: [PATCH 4/5] apply @envygeeks patch --- spec/watcher_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/watcher_spec.rb b/spec/watcher_spec.rb index 1c6a32a..df43848 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/, /#{Regex.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/, /#{Regex.escape('_dest/')}/, /\.jekyll\-metadata/] } context "when source is absolute" do context "when destination is absolute" do From 9bd588817c5386d41d317aa8aa7b9a6ec675c1bc Mon Sep 17 00:00:00 2001 From: danprince Date: Sat, 28 Nov 2015 16:11:50 +0530 Subject: [PATCH 5/5] fixes typos --- spec/watcher_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/watcher_spec.rb b/spec/watcher_spec.rb index df43848..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/, /#{Regex.escape('_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/, /#{Regex.escape('_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