From 1b15afbc3628cd0d1f9acce9b6806b08d323e914 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 26 Apr 2010 12:17:35 +0300 Subject: [PATCH] made the auto:blog task actually work --- Rakefile | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 22ffaf9..0f54d32 100644 --- a/Rakefile +++ b/Rakefile @@ -107,8 +107,25 @@ namespace :auto do system "jekyll source/site public --auto" end desc "Auto-rebuild blog when files are changed." - task :blog do - system "jekyll source/blog public/blog --auto" + task :blog => "build" do + require 'directory_watcher' + + puts "Auto-regenerating enabled: #{BLOG_SRC} -> #{BLOG_DEST}" + + dw = DirectoryWatcher.new(BLOG_SRC) + dw.interval = 1 + dw.glob = globs(BLOG_SRC) + + dw.add_observer do |*args| + t = Time.now.strftime("%Y-%m-%d %H:%M:%S") + puts "[#{t}] regeneration: #{args.size} files changed" + Rake::Task['build'].invoke + @blog.process + end + + dw.start + + loop { sleep 500 } end end @@ -167,3 +184,12 @@ def generate_index(posts, file, options = {}) end.join("\n") file.puts(output) 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