Exclude Jekyll directory from --watch, but not build

こ雲淡風輕ζ 提交于 2019-12-11 12:17:13

问题


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:


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.



来源:https://stackoverflow.com/questions/36861397/exclude-jekyll-directory-from-watch-but-not-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!