Sha256: f3f2a2782d81b5ec19aee3529e18df643cbe79f2a0cfa37f3298dba71df2be42

Contents?: true

Size: 1.76 KB

Versions: 6

Compression:

Stored size: 1.76 KB

Contents

#!/usr/bin/env ruby

$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])

help = <<HELP
Jekyll is a blog-aware, static site generator.

Basic Command Line Usage:
  jekyll                                                   # . -> ./_site
  jekyll <path to write generated site>                    # . -> <path>
  jekyll <path to source> <path to write generated site>   # <path> -> <path>
    
  Options:
HELP

require 'optparse'
require 'jekyll'

options = {}

opts = OptionParser.new do |opts|
  opts.banner = help

  opts.on("--auto", "Auto-regenerate") do
    options[:auto] = true
  end
  
  opts.on("--lsi", "Use LSI for better related posts") do
    Jekyll.lsi = true
  end
  
  opts.on("--pygments", "Use pygments to highlight code") do
    Jekyll.pygments = true
  end
end

opts.parse!

def clean(dest)
  FileUtils.rm_rf(dest)
  FileUtils.mkdir_p(dest)
end

def globs(source)
  Dir.chdir(source) do
    dirs = Dir['*'].select { |x| File.directory?(x) }
    dirs -= ['_site']
    dirs = dirs.map { |x| "#{x}/**/*" }
    dirs += ['*']
  end
end

source = nil
destination = nil

case ARGV.size
  when 0
    source = '.'
    destination = File.join('.', '_site')
  when 1
    source = '.'
    destination = ARGV[0]
  when 2
    source = ARGV[0]
    destination = ARGV[1]
  else
    puts "Invalid options. Run `jekyll --help` for assistance."
    exit(1)
end

if options[:auto]
  puts "Auto-regenerating enabled: #{source} -> #{destination}"
  
  dw = DirectoryWatcher.new(source)
  dw.interval = 1
  dw.glob = globs(source)
  
  dw.add_observer do |*args|
    t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
    puts "[#{t}] regeneration: #{args.size} files changed"
    Jekyll.process(source, destination)
  end
  
  dw.start
  
  loop { sleep 1000 }
else
  Jekyll.process(source, destination)
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
mojombo-jekyll-0.1.5 bin/jekyll
mojombo-jekyll-0.1.6 bin/jekyll
mojombo-jekyll-0.2.0 bin/jekyll
jekyll-0.1.5 bin/jekyll
jekyll-0.2.0 bin/jekyll
jekyll-0.1.6 bin/jekyll