Exclude Jekyll directory from --watch, but not bui

2019-08-13 00:48发布

I have a very similar issue to Excluding a directory from Jekyll watch, but I thought it was different enough to warrant it's own question.


_config.yml:

exclude: [
  "my_ignored_directory"
]

Using jekyll build --watch, the folder my_ignored_directory will be successfully ignored from the watch task, but it will also not be built.

Is there are way to exclude a folder of my choosing from the --watch task, but not to be excluded from being built?

(Note: there is no error in the console)

1条回答
乱世女痞
2楼-- · 2019-08-13 00:56

The answer is no, because excluded files for watch are : _config.*, destination folder (usually _site) and content of config['exclude'].

See jekyll-watch code

Edit : But ...

We can override Jekyll::Watcher::custom_excludes methods with a plugin.

_plugins/jekyll-watcher-override.rb

require 'jekyll-watch'
module Jekyll
  module Watcher
    # replace old method by new method
    # new method is now :custom_excludes
    # overridden method is now :old_custom_excludes
    alias_method :old_custom_excludes, :custom_excludes
    def custom_excludes(options)
      # if we have an "exclude_from_watch" variable in configuration
      if options['exclude_from_watch'] then
        # merge exclude and exclude_from_watch
        (options['exclude'] << options['exclude_from_watch']).flatten!
      end
      # pass the new option array to overridden method
      old_custom_excludes(options)
    end
  end
end

In _config.yml, just set an exclude_from_watch variable :

exclude_from_watch:
  - css

Now, when you do a jekyll serve any file / folder in exclude_from_watch will be ignored if they change.

查看更多
登录 后发表回答