从--watch中排除Jekyll目录,但不能生成 [英] Exclude Jekyll directory from --watch, but not build
问题描述
我有一个类似于从Jekyll手表中排除目录的问题 ,但我认为这是不同的,以保证它是自己的问题。
_config.yml:
exclude:[
使用
my_ignored_directory
]
jekyll build --watch
,文件夹my_ignored_directory code>将被成功从watch任务中忽略,但它也不会被构建。
是否有办法从我的选择中排除一个我选择的文件夹
- 监视
任务,但不会被排除在构建之外?
(注意:控制台)
解决方案答案是否定的,因为watch的排除文件是:
_config。*
,目标文件夹
(通常_site
)和config ['exclude']
。
请参阅 jekyll-watch code
$ b编辑:但...
我们可以用插件覆盖
Jekyll :: Watcher :: custom_excludes
方法。
_plugins / jekyll-watcher-override.rb
需要'jekyll-watch'
模块Jekyll
模块Watcher
#通过新方法替换旧方法
#现在新方法:custom_excludes
#重写方法现在:old_custom_excludes
alias_method:old_custom_excludes,:custom_excludes
def custom_excludes(选项)
如果我们在配置中有一个exclude_from_watch变量
如果选项['exclude_from_watch']然后
#merge exclude和exclude_from_watch
(options ['exclude']<<选项[ exclude_from_watch])。压扁!
end
#传递新选项数组以重写方法
old_custom_excludes(options)
end
end
end
在_config.yml中,只需设置
exclude_from_watch
变量:exclude_from_watch:
- css
现在,当您执行
jekyll serve
时,exclude_from_watch
中的任何文件/文件夹将被忽略改变。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 foldermy_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)
解决方案Teh answer is no, because excluded files for watch are :
_config.*
,destination folder
(usually_site
) and content ofconfig['exclude']
.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 inexclude_from_watch
will be ignored if they change.这篇关于从--watch中排除Jekyll目录,但不能生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!