Class: Jekyll::Commands::Build
- Inherits:
-
Jekyll::Command
- Object
- Jekyll::Command
- Jekyll::Commands::Build
- Defined in:
- lib/jekyll/commands/build.rb
Class Method Summary collapse
-
.build(site, options) ⇒ Object
Private: Build the site from source into destination.
- .process(options) ⇒ Object
-
.watch(site, options) ⇒ Object
Private: Watch for file changes and rebuild the site.
Methods inherited from Jekyll::Command
Class Method Details
.build(site, options) ⇒ Object
Private: Build the site from source into destination.
site - A Jekyll::Site instance options - A Hash of options passed to the command
Returns nothing.
17 18 19 20 21 22 23 24 25 |
# File 'lib/jekyll/commands/build.rb', line 17 def self.build(site, ) source = ['source'] destination = ['destination'] Jekyll.logger.info "Source:", source Jekyll.logger.info "Destination:", destination print Jekyll.logger.formatted_topic "Generating..." self.process_site(site) puts "done." end |
.process(options) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/jekyll/commands/build.rb', line 4 def self.process() site = Jekyll::Site.new() self.build(site, ) self.watch(site, ) if ['watch'] end |
.watch(site, options) ⇒ Object
Private: Watch for file changes and rebuild the site.
site - A Jekyll::Site instance options - A Hash of options passed to the command
Returns nothing.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/jekyll/commands/build.rb', line 33 def self.watch(site, ) require 'listen' source = ['source'] destination = ['destination'] begin dest = Pathname.new(destination).relative_path_from(Pathname.new(source)).to_s ignored = Regexp.new(Regexp.escape(dest)) rescue ArgumentError # Destination is outside the source, no need to ignore it. ignored = nil end Jekyll.logger.info "Auto-regeneration:", "enabled" listener = Listen::Listener.new(source, :ignore => ignored) do |modified, added, removed| t = Time.now.strftime("%Y-%m-%d %H:%M:%S") n = modified.length + added.length + removed.length print Jekyll.logger.formatted_topic("Regenerating:") + "#{n} files at #{t} " self.process_site(site) puts "...done." end listener.start unless ['serving'] trap("INT") do listener.stop puts " Halting auto-regeneration." exit 0 end loop { sleep 1000 } end end |