无法以编程方式运行Jekyll构建

时间:2013-11-18 02:20:06

标签: ruby bundler jekyll

我正在尝试以编程方式运行Jekyll构建,但我遇到的问题是,当尝试加载Jekyll网站插件使用的一些宝石时,构建崩溃。

我的代码看起来像这样(为了便于阅读,添加了换行符):

%x(cd #{@config['input_directory']} &&
  bundle install &&
  bundle exec jekyll build --config #{File.join(@config['input_directory'], "_config.yml")} --source #{@config['input_directory']} --destination #{@config['output_directory']} --trace)

当它运行时,我得到一个如下所示的堆栈跟踪:

/_plugins/jekyll_lunr_js_search.rb:80:in `require': cannot load such file -- nokogiri (LoadError)
    from /_plugins/jekyll_lunr_js_search.rb:80:in `<top (required)>'
    from /ruby-1.9.3-p448/gems/jekyll-1.3.0/lib/jekyll/site.rb:77:in `require'
    from /ruby-1.9.3-p448/gems/jekyll-1.3.0/lib/jekyll/site.rb:77:in `block (2 levels) in setup'
    from /ruby-1.9.3-p448/gems/jekyll-1.3.0/lib/jekyll/site.rb:76:in `each'
    from /ruby-1.9.3-p448/gems/jekyll-1.3.0/lib/jekyll/site.rb:76:in `block in setup'
    from /ruby-1.9.3-p448/gems/jekyll-1.3.0/lib/jekyll/site.rb:75:in `each'
    from /ruby-1.9.3-p448/gems/jekyll-1.3.0/lib/jekyll/site.rb:75:in `setup'
    from /ruby-1.9.3-p448/gems/jekyll-1.3.0/lib/jekyll/site.rb:29:in `initialize'
    from /ruby-1.9.3-p448/gems/jekyll-1.3.0/lib/jekyll/commands/build.rb:5:in `new'
    from /ruby-1.9.3-p448/gems/jekyll-1.3.0/lib/jekyll/commands/build.rb:5:in `process'
    from /ruby-1.9.3-p448/gems/jekyll-1.3.0/bin/jekyll:77:in `block (2 levels) in <top (required)>'
    from /ruby-1.9.3-p448/gems/commander-4.1.5/lib/commander/command.rb:180:in `call'
    from /ruby-1.9.3-p448/gems/commander-4.1.5/lib/commander/command.rb:180:in `call'
    from /ruby-1.9.3-p448/gems/commander-4.1.5/lib/commander/command.rb:155:in `run'
    from /ruby-1.9.3-p448/gems/commander-4.1.5/lib/commander/runner.rb:402:in `run_active_command'
    from /ruby-1.9.3-p448/gems/commander-4.1.5/lib/commander/runner.rb:78:in `run!'
    from /ruby-1.9.3-p448/gems/commander-4.1.5/lib/commander/delegates.rb:11:in `run!'
    from /ruby-1.9.3-p448/gems/commander-4.1.5/lib/commander/import.rb:10:in `block in <top (required)>'

input_directory的Gemfile看起来像这样,所以我不确定为什么它无法加载nokogiri。

source 'https://rubygems.org'

gem 'directory_watcher', '= 1.4.1' # http://stackoverflow.com/questions/15591000/jekylls-auto-doesnt-work
gem 'kramdown'
gem 'nokogiri'
gem 'yui-compressor'
gem "jekyll"

group :development do
  gem 'capistrano'
  gem 'rvm-capistrano'
end

欢迎任何指示。我觉得有更好的方法可以通过编程方式进行这个Jekyll构建,这对我来说似乎是最简单的。

1 个答案:

答案 0 :(得分:1)

运行bundle exec jekyll以确保它为Jekyll正确设置gem路径。如果您从使用Bundler本身的应用程序调用该程序,您可能还需要将执行包装在Bundler.with_clean_env的调用中。

完整的命令应如下所示:

Bundler.with_clean_env do
  %x(cd #{@config['input_directory']} &&
    bundle install &&
    bundle exec jekyll build --config #{File.join(@config['input_directory'], "_config.yml")} --source #{@config['input_directory']} --destination #{@config['output_directory']} --trace)
end