From bb964cf58cf29857f9c989a329fe42d86d635d14 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 23 Apr 2018 21:50:35 +0530 Subject: [PATCH 1/3] Ignore directories rather than all similar paths --- lib/jekyll/watcher.rb | 1 + spec/watcher_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/watcher.rb b/lib/jekyll/watcher.rb index 4c368de..ca7ec2c 100644 --- a/lib/jekyll/watcher.rb +++ b/lib/jekyll/watcher.rb @@ -103,6 +103,7 @@ def listen_ignore_paths(options) next unless absolute_path.exist? begin relative_path = absolute_path.relative_path_from(source).to_s + relative_path = File.join(relative_path, "") if absolute_path.directory? unless relative_path.start_with?("../") path_to_ignore = Regexp.new(Regexp.escape(relative_path)) Jekyll.logger.debug "Watcher:", "Ignoring #{path_to_ignore}" diff --git a/spec/watcher_spec.rb b/spec/watcher_spec.rb index 31e290f..bd9bb15 100644 --- a/spec/watcher_spec.rb +++ b/spec/watcher_spec.rb @@ -12,7 +12,7 @@ let(:options) { base_opts } let(:site) { instance_double(Jekyll::Site) } - let(:default_ignored) { [%r!_config\.yml!, %r!_site!, %r!\.jekyll\-metadata!] } + let(:default_ignored) { [%r!_config\.yml!, %r!_site/!, %r!\.jekyll\-metadata!] } subject { described_class } before(:each) do FileUtils.mkdir(options["destination"]) if options["destination"] @@ -125,7 +125,7 @@ end context "with a custom destination" do - let(:default_ignored) { [%r!_config\.yml!, %r!_dest!, %r!\.jekyll\-metadata!] } + let(:default_ignored) { [%r!_config\.yml!, %r!_dest/!, %r!\.jekyll\-metadata!] } context "when source is absolute" do context "when destination is absolute" do From 32a45ab301ed5c06d63a740a772a48ea0cf1ef1c Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 23 Apr 2018 23:50:05 +0530 Subject: [PATCH 2/3] anchor paths in regexes for more specificity --- lib/jekyll/watcher.rb | 4 ++-- spec/watcher_spec.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/jekyll/watcher.rb b/lib/jekyll/watcher.rb index c168e19..8b7a3db 100644 --- a/lib/jekyll/watcher.rb +++ b/lib/jekyll/watcher.rb @@ -105,14 +105,14 @@ def listen_ignore_paths(options) relative_path = absolute_path.relative_path_from(source).to_s relative_path = File.join(relative_path, "") if absolute_path.directory? unless relative_path.start_with?("../") - path_to_ignore = Regexp.new(Regexp.escape(relative_path)) + path_to_ignore = %r!^#{Regexp.escape(relative_path)}! Jekyll.logger.debug "Watcher:", "Ignoring #{path_to_ignore}" path_to_ignore end rescue ArgumentError # Could not find a relative path end - end.compact + [%r!\.jekyll\-metadata!] + end.compact + [%r!^\.jekyll\-metadata!] end private diff --git a/spec/watcher_spec.rb b/spec/watcher_spec.rb index bd9bb15..52515fd 100644 --- a/spec/watcher_spec.rb +++ b/spec/watcher_spec.rb @@ -12,7 +12,7 @@ let(:options) { base_opts } let(:site) { instance_double(Jekyll::Site) } - let(:default_ignored) { [%r!_config\.yml!, %r!_site/!, %r!\.jekyll\-metadata!] } + let(:default_ignored) { [%r!^_config\.yml!, %r!^_site/!, %r!^\.jekyll\-metadata!] } subject { described_class } before(:each) do FileUtils.mkdir(options["destination"]) if options["destination"] @@ -119,13 +119,13 @@ after(:each) { FileUtils.rm(excluded_absolute) } it "ignores the excluded files" do - expect(ignored).to include(%r!README\.md!) - expect(ignored).to include(%r!LICENSE!) + expect(ignored).to include(%r!^README\.md!) + expect(ignored).to include(%r!^LICENSE!) end end context "with a custom destination" do - let(:default_ignored) { [%r!_config\.yml!, %r!_dest/!, %r!\.jekyll\-metadata!] } + let(:default_ignored) { [%r!^_config\.yml!, %r!^_dest/!, %r!^\.jekyll\-metadata!] } context "when source is absolute" do context "when destination is absolute" do From e8ad23dd8572617dc465ee38a353849ec84d632c Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 23 Apr 2018 23:55:44 +0530 Subject: [PATCH 3/3] test if specific paths get ignored or not --- spec/spec_helper.rb | 9 +++++++++ spec/watcher_spec.rb | 24 ++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e681284..557e28b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -73,4 +73,13 @@ def source_dir(*files) def dest_dir(*files) source_dir("_site", *files) end + + def ignore_path?(patterns, path) + path = path.to_s + patterns.each do |pattern| + return true if path =~ pattern + next + end + false + end end diff --git a/spec/watcher_spec.rb b/spec/watcher_spec.rb index 52515fd..97b3ff9 100644 --- a/spec/watcher_spec.rb +++ b/spec/watcher_spec.rb @@ -107,6 +107,10 @@ it "ignores config.yml, .jekyll-metadata, and _site by default" do expect(ignored).to eql(default_ignored) + expect(ignore_path?(ignored, "_site/foo.html")).to eql(true) + expect(ignore_path?(ignored, "_sitemapper/foo.html")).to eql(false) + expect(ignore_path?(ignored, "bar/_site/foo.html")).to eql(false) + expect(ignore_path?(ignored, "bar/_site-mapper.html")).to eql(false) end context "with something excluded" do @@ -119,8 +123,8 @@ after(:each) { FileUtils.rm(excluded_absolute) } it "ignores the excluded files" do - expect(ignored).to include(%r!^README\.md!) - expect(ignored).to include(%r!^LICENSE!) + expect(ignore_path?(ignored, "README.md")).to eql(true) + expect(ignore_path?(ignored, "LICENSE")).to eql(true) end end @@ -132,6 +136,10 @@ let(:options) { base_opts.merge("destination" => source_dir("_dest")) } it "ignores the destination" do expect(ignored).to eql(default_ignored) + expect(ignore_path?(ignored, "_dest/foo.html")).to eql(true) + expect(ignore_path?(ignored, "_destination/foo.html")).to eql(false) + expect(ignore_path?(ignored, "bar/_dest/foo.html")).to eql(false) + expect(ignore_path?(ignored, "bar/_dest-nation.html")).to eql(false) end end @@ -139,6 +147,10 @@ let(:options) { base_opts.merge("destination" => "spec/test-site/_dest") } it "ignores the destination" do expect(ignored).to eql(default_ignored) + expect(ignore_path?(ignored, "_dest/foo.html")).to eql(true) + expect(ignore_path?(ignored, "_destination/foo.html")).to eql(false) + expect(ignore_path?(ignored, "bar/_dest/foo.html")).to eql(false) + expect(ignore_path?(ignored, "bar/_dest-nation.html")).to eql(false) end end end @@ -155,6 +167,10 @@ let(:options) { base_opts.merge("destination" => source_dir("_dest")) } it "ignores the destination" do expect(ignored).to eql(default_ignored) + expect(ignore_path?(ignored, "_dest/foo.html")).to eql(true) + expect(ignore_path?(ignored, "_destination/foo.html")).to eql(false) + expect(ignore_path?(ignored, "bar/_dest/foo.html")).to eql(false) + expect(ignore_path?(ignored, "bar/_dest-nation.html")).to eql(false) end end @@ -162,6 +178,10 @@ let(:options) { base_opts.merge("destination" => "spec/test-site/_dest") } it "ignores the destination" do expect(ignored).to eql(default_ignored) + expect(ignore_path?(ignored, "_dest/foo.html")).to eql(true) + expect(ignore_path?(ignored, "_destination/foo.html")).to eql(false) + expect(ignore_path?(ignored, "bar/_dest/foo.html")).to eql(false) + expect(ignore_path?(ignored, "bar/_dest-nation.html")).to eql(false) end end end