diff options
Diffstat (limited to 'Rakefile')
-rw-r--r-- | Rakefile | 106 |
1 files changed, 79 insertions, 27 deletions
@@ -1,5 +1,6 @@ require "rubygems" require "bundler/setup" +require "stringex" ## -- Rsync Deploy config -- ## # Be sure your public key is listed in your server's ~/.ssh/authorized_keys file @@ -10,16 +11,18 @@ deploy_default = "rsync" # This will be configured for you when you run config_deploy deploy_branch = "gh-pages" -## -- Misc Configs, you probably have no reason to changes these -- ## +## -- Misc Configs -- ## -public_dir = "public" # compiled site directory -source_dir = "source" # source file directory -deploy_dir = "_deploy" # deploy directory (for Github pages deployment) -stash_dir = "_stash" # directory to stash posts for speedy generation -posts_dir = "_posts" # directory for blog files -themes_dir = ".themes" # directory for blog files -new_post_ext = "markdown" # default new post file extension when using the new_post task -new_page_ext = "markdown" # default new page file extension when using the new_page task +public_dir = "public" # compiled site directory +source_dir = "source" # source file directory +blog_index_dir = 'source' # directory for your blog's index page (if you put your index in source/blog/index.html, set this to 'source/blog') +deploy_dir = "_deploy" # deploy directory (for Github pages deployment) +stash_dir = "_stash" # directory to stash posts for speedy generation +posts_dir = "_posts" # directory for blog files +themes_dir = ".themes" # directory for blog files +new_post_ext = "markdown" # default new post file extension when using the new_post task +new_page_ext = "markdown" # default new page file extension when using the new_page task +server_port = "4000" # port for preview server eg. localhost:4000 desc "Initial setup for Octopress: copies the default theme into the path of Jekyll's generator. Rake install defaults to rake install[classic] to install a different theme run rake install[some_theme_name]" @@ -41,30 +44,62 @@ end desc "Generate jekyll site" task :generate do + raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir) puts "## Generating Site with Jekyll" system "jekyll" end desc "Watch the site and regenerate when it changes" task :watch do - system "trap 'kill $jekyllPid $compassPid' Exit; jekyll --auto & jekyllPid=$!; compass watch & compassPid=$!; wait" + raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir) + puts "Starting to watch source with Jekyll and Compass." + jekyllPid = spawn("jekyll --auto") + compassPid = spawn("compass watch") + + trap("INT") { + Process.kill(9, jekyllPid) + Process.kill(9, compassPid) + exit 0 + } + + Process.wait end desc "preview the site in a web browser" task :preview do - system "trap 'kill $jekyllPid $compassPid' Exit; jekyll --auto --server & jekyllPid=$!; compass watch & compassPid=$!; wait" + raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir) + puts "Starting to watch source with Jekyll and Compass. Starting Rack on port #{server_port}" + jekyllPid = spawn("jekyll --auto") + compassPid = spawn("compass watch") + rackupPid = spawn("rackup --port #{server_port}") + + trap("INT") { + Process.kill(9, jekyllPid) + Process.kill(9, compassPid) + Process.kill(9, rackupPid) + exit 0 + } + + Process.wait end # usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post") desc "Begin a new post in #{source_dir}/#{posts_dir}" task :new_post, :title do |t, args| + raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir) require './plugins/titlecase.rb' + mkdir_p "#{source_dir}/#{posts_dir}" args.with_defaults(:title => 'new-post') title = args.title - filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.downcase.gsub(/&/,'and').gsub(/[,'":\?!\(\)\[\]]/,'').gsub(/[\W\.]/, '-').gsub(/-+$/,'')}.#{new_post_ext}" + filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}" + if File.exist?(filename) + puts "### #{filename} Already exists. Overwrite? y/n:" + response = $stdin.gets.chomp.downcase + next unless response == 'y' + end puts "Creating new post: #{filename}" open(filename, 'w') do |post| - system "mkdir -p #{source_dir}/#{posts_dir}"; + system "mkdir -p #{source_dir}/#{posts_dir}/"; post.puts "---" post.puts "layout: post" post.puts "title: \"#{title.gsub(/&/,'&').titlecase}\"" @@ -78,6 +113,7 @@ end # usage rake new_page[my-new-page] or rake new_page[my-new-page.html] or rake new_page (defaults to "new-page.markdown") desc "Create a new page in #{source_dir}/(filename)/index.#{new_page_ext}" task :new_page, :filename do |t, args| + raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir) require './plugins/titlecase.rb' args.with_defaults(:filename => 'new-page') page_dir = source_dir @@ -88,6 +124,11 @@ task :new_page, :filename do |t, args| filename = "#{name}.#{extension}" mkdir_p page_dir file = page_dir + filename + if File.exist?(file) + puts "### #{file} Already exists. Overwrite? y/n:" + response = $stdin.gets.chomp.downcase + next unless response == 'y' + end puts "Creating new page: #{file}" open(file, 'w') do |page| page.puts "---" @@ -121,7 +162,7 @@ end desc "Clean out caches: _code_cache, _gist_cache, .sass-cache" task :clean do - system "rm -rf _code_cache/** _gist_cache/** .sass-cache/**" + rm_rf ["_code_cache/**", "_gist_cache/**", ".sass-cache/**", "source/stylesheets/screen.css"] end desc "Move sass to sass.old, install sass theme updates, replace sass/custom with sass.old/custom" @@ -129,11 +170,11 @@ task :update_style, :theme do |t, args| theme = args.theme || 'classic' if File.directory?("sass.old") puts "removed existing sass.old directory" - system "rm -r sass.old" + rm_r "sass.old", :secure=>true end - system "mv sass sass.old" + mv "sass", "sass.old" puts "## Moved styles into sass.old/" - system "mkdir -p sass; cp -R #{themes_dir}/"+theme+"/sass/ sass/" + cp_r "#{themes_dir}/"+theme+"/sass/", "sass" cp_r "sass.old/custom/.", "sass/custom" puts "## Updated Sass ##" end @@ -142,14 +183,15 @@ desc "Move source to source.old, install source theme updates, replace source/_i task :update_source, :theme do |t, args| theme = args.theme || 'classic' if File.directory?("#{source_dir}.old") - puts "removed existing #{source_dir}.old directory" - system "rm -r #{source_dir}.old" + puts "## Removed existing #{source_dir}.old directory" + rm_r "#{source_dir}.old", :secure=>true end - system "mv #{source_dir} #{source_dir}.old" - puts "moved #{source_dir} into #{source_dir}.old/" - system "mkdir -p #{source_dir}; cp -R #{themes_dir}/"+theme+"/source/. #{source_dir}" - system "cp -Rn #{source_dir}.old/. #{source_dir}" - system "cp -Rf #{source_dir}.old/_includes/custom/. #{source_dir}/_includes/custom/" + cp_r "#{source_dir}/.", "#{source_dir}.old" + puts "## Copied #{source_dir} into #{source_dir}.old/" + cp_r "#{themes_dir}/"+theme+"/source/.", source_dir, :remove_destination=>true + cp_r "#{source_dir}.old/_includes/custom/.", "#{source_dir}/_includes/custom/", :remove_destination=>true + mv "#{source_dir}/index.html", "#{blog_index_dir}", :force=>true if blog_index_dir != source_dir + cp "#{source_dir}.old/index.html", source_dir if blog_index_dir != source_dir puts "## Updated #{source_dir} ##" end @@ -158,7 +200,17 @@ end ############## desc "Default deploy task" -task :deploy => "#{deploy_default}" do +multitask :deploy => [:copydot, "#{deploy_default}"] do +end + +desc "copy dot files for deployment" +task :copydot do + exclusions = [".", "..", ".DS_Store"] + Dir["#{source_dir}/.*"].each do |file| + if !File.directory?(file) && !exclusions.include?(file) + cp(file, "#{public_dir}"); + end + end end desc "Deploy website via rsync" @@ -168,7 +220,7 @@ task :rsync do end desc "deploy public directory to github pages" -task :push do +multitask :push do puts "## Deploying branch to Github Pages " (Dir["#{deploy_dir}/*"]).each { |f| rm_rf(f) } system "cp -R #{public_dir}/* #{deploy_dir}" @@ -251,6 +303,6 @@ end desc "list tasks" task :list do - puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).to_sentence}" + puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).join(', ')}" puts "(type rake -T for more detail)\n\n" end |