TL;DR
require 'jekyll'
conf = Jekyll.configuration({
'source' => 'path/to/source',
'destination' => 'path/to/destination'
})
Jekyll::Site.new(conf).process
でもどうやって分かったの?
ソースコードを見てこれを理解しました。実行するjekyll build
と、ソース ファイルに入りますbin/jekyll
。ここで興味深い部分は
command :build do |c|
# ommitted
c.action do |args, options|
options = normalize_options(options.__hash__)
options = Jekyll.configuration(options)
Jekyll::Commands::Build.process(options)
end
end
うーん、実際の作業は で行われているように見えるJekyll::Commands::Build.process
ので、 でそのメソッドを見てみましょうlib/jekyll/commands/build.rb
。
def self.process(options)
site = Jekyll::Site.new(options)
self.build(site, options)
# other stuff
end
繰り返しますが、実際の魔法は別の場所で発生Jekyll::Commands::Build.build
します。lib/jekyll/commands/build.rb
def self.build(site, options)
# some logging going on here
self.process_site(site)
end
これは、 で定義されprocess_site
たスーパークラスに由来するというクラス メソッドを呼び出します。Jekyll::Command
lib/jekyll/command.rb
def self.process_site(site)
site.process
rescue Jekyll::FatalException => e
# some error handling
end
したがって、実際には を呼び出したいと思いprocess
ますJekyll::Site
。Jekyll::Site
まだわかっていないことの 1 つは、インスタンスのオプションを指定する方法です。詳しく見てみましょうlib/jekyll/site.rb
def initialize(config)
# more options ...
self.source = File.expand_path(config['source'])
self.dest = File.expand_path(config['destination'])
# more options ...
end
したがって、目的のディレクトリを指す'source'
およびキーを含むハッシュを提供する必要があるようです。'destination'
残りの構成は、Jekyll.configuration
前に で見た方法でJekyll によって生成されbin/jekyll
ます。それはそれについてです。あとは部品を組み立てるだけです ;-)