Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/jekyll/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/watcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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
Expand Down