我有一个与从 Jekyll 手表中排除目录非常相似的问题,但我认为它足够不同,足以保证它自己的问题。
_config.yml:
exclude: [
"my_ignored_directory"
]
使用 jekyll build --watch
,监视任务将成功忽略文件夹my_ignored_directory
,但也不会生成该文件夹。
有没有办法从--watch
任务中排除我选择的文件夹,但不排除在构建之外?
(注意:控制台没有错误)
答案是否定的,因为排除的监视文件是:_config.*
,destination folder
(通常_site
)和config['exclude']
的内容。
查看杰基尔手表代码
编辑:但是...
我们可以用插件覆盖Jekyll::Watcher::custom_excludes
方法。
_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
在 _config.yml 中,只需设置一个exclude_from_watch
变量:
exclude_from_watch:
- css
现在,当您执行jekyll serve
时,如果它们发生变化,exclude_from_watch
中的任何文件/文件夹都将被忽略。