【问题标题】:Exclude Jekyll directory from --watch, but not build从 --watch 中排除 Jekyll 目录,但不构建
【发布时间】:2016-04-26 09:53:53
【问题描述】:

我有一个与 Excluding a directory from Jekyll watch 非常相似的问题,但我认为它的不同足以保证它自己的问题。


_config.yml:

exclude: [
  "my_ignored_directory"
]

使用jekyll build --watch,文件夹my_ignored_directory将被成功地从监视任务中忽略,但它也不会被构建。

有没有办法从--watch 任务中排除我选择的文件夹,但不排除在构建之外?

(注意:控制台没有错误)

【问题讨论】:

    标签: html command-line-interface jekyll


    【解决方案1】:

    答案是否定的,因为 watch 的排除文件是:_config.*destination folder(通常是_site)和config['exclude'] 的内容。

    jekyll-watch code

    编辑:但是...

    我们可以用插件覆盖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 中的任何文件/文件夹如果发生更改将被忽略。

    【讨论】:

    • Booooooo Jekyll! - 谢谢,我想可能是这样。
    • 哦哦。我一定会调查的
    • 这似乎只适用于前几次刷新,然后jekyll-watch 再次开始拾取被忽略的目录。 Jekyll 能否以某种方式再次重新加载手表并覆盖覆盖?
    猜你喜欢
    • 2011-08-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    • 2011-11-26
    • 1970-01-01
    • 2018-01-08
    • 1970-01-01
    相关资源
    最近更新 更多