diff --git a/lib/jekyll/watcher.rb b/lib/jekyll/watcher.rb index d76ed0f..ea49ad6 100644 --- a/lib/jekyll/watcher.rb +++ b/lib/jekyll/watcher.rb @@ -107,15 +107,16 @@ def listen_ignore_paths(options) 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)) + 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 def sleep_forever diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 206b589..14d9e76 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 924aee9..bf6837e 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"] @@ -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,19 +123,23 @@ 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 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 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-sité/_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-sité/_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