aboutsummaryrefslogtreecommitdiff
path: root/Rakefile
diff options
context:
space:
mode:
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile133
1 files changed, 93 insertions, 40 deletions
diff --git a/Rakefile b/Rakefile
index 95e95c7a..d4dcb549 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,7 +5,9 @@ require "stringex"
## -- Rsync Deploy config -- ##
# Be sure your public key is listed in your server's ~/.ssh/authorized_keys file
ssh_user = "user@domain.com"
+ssh_port = "22"
document_root = "~/website.com/"
+rsync_delete = true
deploy_default = "rsync"
# This will be configured for you when you run config_deploy
@@ -49,6 +51,7 @@ 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 "compass compile --css-dir #{source_dir}/stylesheets"
system "jekyll"
end
@@ -56,7 +59,8 @@ desc "Watch the site and regenerate when it changes"
task :watch 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 "Starting to watch source with Jekyll and Compass."
- jekyllPid = Process.spawn("jekyll --auto")
+ system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css")
+ jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll --auto")
compassPid = Process.spawn("compass watch")
trap("INT") {
@@ -71,7 +75,8 @@ desc "preview the site in a web browser"
task :preview 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 "Starting to watch source with Jekyll and Compass. Starting Rack on port #{server_port}"
- jekyllPid = Process.spawn("jekyll --auto")
+ system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css")
+ jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll --auto")
compassPid = Process.spawn("compass watch")
rackupPid = Process.spawn("rackup --port #{server_port}")
@@ -87,7 +92,6 @@ end
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
@@ -97,10 +101,9 @@ task :new_post, :title do |t, args|
end
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
- system "mkdir -p #{source_dir}/#{posts_dir}/";
post.puts "---"
post.puts "layout: post"
- post.puts "title: \"#{title.gsub(/&/,'&').titlecase}\""
+ post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
post.puts "comments: true"
post.puts "categories: "
@@ -112,16 +115,22 @@ end
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
- if args.filename =~ /(^.+\/)?([\w_-]+)(\.)?(.+)?/
- page_dir += $4 ? "/#{$1}" : "/#{$1}#{$2}/"
- name = $4 ? $2 : "index"
- extension = $4 || "#{new_page_ext}"
- filename = "#{name}.#{extension}"
+ page_dir = [source_dir]
+ if args.filename.downcase =~ /(^.+\/)?(.+)/
+ filename, dot, extension = $2.rpartition('.').reject(&:empty?) # Get filename and extension
+ title = filename
+ page_dir.concat($1.downcase.sub(/^\//, '').split('/')) unless $1.nil? # Add path to page_dir Array
+ if extension.nil?
+ page_dir << filename
+ filename = "index"
+ end
+ extension ||= new_page_ext
+ page_dir = page_dir.map! { |d| d = d.to_url }.join('/') # Sanitize path
+ filename = filename.downcase.to_url
+
mkdir_p page_dir
- file = page_dir + filename
+ file = "#{page_dir}/#{filename}.#{extension}"
if File.exist?(file)
abort("rake aborted!") if ask("#{file} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
end
@@ -129,7 +138,7 @@ task :new_page, :filename do |t, args|
open(file, 'w') do |page|
page.puts "---"
page.puts "layout: page"
- page.puts "title: \"#{$2.gsub(/[-_]/, ' ').titlecase}\""
+ page.puts "title: \"#{title}\""
page.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
page.puts "comments: true"
page.puts "sharing: true"
@@ -156,9 +165,9 @@ task :integrate do
FileUtils.mv Dir.glob("#{source_dir}/#{stash_dir}/*.*"), "#{source_dir}/#{posts_dir}/"
end
-desc "Clean out caches: _code_cache, _gist_cache, .sass-cache"
+desc "Clean out caches: .pygments-cache, .gist-cache, .sass-cache"
task :clean do
- rm_rf ["_code_cache/**", "_gist_cache/**", ".sass-cache/**", "source/stylesheets/screen.css"]
+ rm_rf [".pygments-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"
@@ -182,12 +191,14 @@ task :update_source, :theme do |t, args|
puts "## Removed existing #{source_dir}.old directory"
rm_r "#{source_dir}.old", :secure=>true
end
+ mkdir "#{source_dir}.old"
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
+ cp "#{source_dir}.old/favicon.png", source_dir
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
+ cp "#{source_dir}.old/index.html", source_dir if blog_index_dir != source_dir && File.exists?("#{source_dir}.old/index.html")
puts "## Updated #{source_dir} ##"
end
@@ -197,44 +208,53 @@ end
desc "Default deploy task"
task :deploy do
- [:copydot, "#{deploy_default}"].each { |t| Rake::Task[t].execute }
+ # Check if preview posts exist, which should not be published
+ if File.exists?(".preview-mode")
+ puts "## Found posts in preview mode, regenerating files ..."
+ File.delete(".preview-mode")
+ Rake::Task[:generate].execute
+ end
+
+ Rake::Task[:copydot].invoke(source_dir, public_dir)
+ Rake::Task["#{deploy_default}"].execute
end
desc "Generate website and deploy"
-task :gen_deploy do
- [:integrate, :generate, :deploy].each { |t| Rake::Task[t].execute }
+task :gen_deploy => [:integrate, :generate, :deploy] 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, file.gsub(/#{source_dir}/, "#{public_dir}"));
- end
+task :copydot, :source, :dest do |t, args|
+ FileList["#{args.source}/**/.*"].exclude("**/.", "**/..", "**/.DS_Store", "**/._*").each do |file|
+ cp_r file, file.gsub(/#{args.source}/, "#{args.dest}") unless File.directory?(file)
end
end
desc "Deploy website via rsync"
task :rsync do
+ exclude = ""
+ if File.exists?('./rsync-exclude')
+ exclude = "--exclude-from '#{File.expand_path('./rsync-exclude')}'"
+ end
puts "## Deploying website via Rsync"
- ok_failed system("rsync -avz --delete #{public_dir}/ #{ssh_user}:#{document_root}")
+ ok_failed system("rsync -avze 'ssh -p #{ssh_port}' #{exclude} #{"--delete" unless rsync_delete == false} #{public_dir}/ #{ssh_user}:#{document_root}")
end
desc "deploy public directory to github pages"
multitask :push do
puts "## Deploying branch to Github Pages "
(Dir["#{deploy_dir}/*"]).each { |f| rm_rf(f) }
- system "cp -R #{public_dir}/* #{deploy_dir}"
+ Rake::Task[:copydot].invoke(public_dir, deploy_dir)
puts "\n## copying #{public_dir} to #{deploy_dir}"
+ cp_r "#{public_dir}/.", deploy_dir
cd "#{deploy_dir}" do
system "git add ."
system "git add -u"
puts "\n## Commiting: Site updated at #{Time.now.utc}"
message = "Site updated at #{Time.now.utc}"
- system "git commit -m '#{message}'"
+ system "git commit -m \"#{message}\""
puts "\n## Pushing generated #{deploy_dir} website"
- system "git push origin #{deploy_branch}"
+ system "git push origin #{deploy_branch} --force"
puts "\n## Github Pages deploy complete"
end
end
@@ -274,25 +294,58 @@ task :set_root_dir, :dir do |t, args|
end
end
-desc "Setup _deploy folder and deploy branch"
-task :config_deploy, :branch do |t, args|
- puts "!! Please provide a deploy branch, eg. rake init_deploy[gh-pages] !!" unless args.branch
- puts "## Creating a clean #{args.branch} branch in ./#{deploy_dir} for Github pages deployment"
+desc "Set up _deploy folder and deploy branch for Github Pages deployment"
+task :setup_github_pages, :repo do |t, args|
+ if args.repo
+ repo_url = args.repo
+ else
+ repo_url = get_stdin("Enter the read/write url for your repository: ")
+ end
+ user = repo_url.match(/:([^\/]+)/)[1]
+ branch = (repo_url.match(/\/[\w-]+.github.com/).nil?) ? 'gh-pages' : 'master'
+ project = (branch == 'gh-pages') ? repo_url.match(/\/([^\.]+)/)[1] : ''
+ unless `git remote -v`.match(/origin.+?octopress.git/).nil?
+ # If octopress is still the origin remote (from cloning) rename it to octopress
+ system "git remote rename origin octopress"
+ if branch == 'master'
+ # If this is a user/organization pages repository, add the correct origin remote
+ # and checkout the source branch for committing changes to the blog source.
+ system "git remote add origin #{repo_url}"
+ puts "Added remote #{repo_url} as origin"
+ system "git config branch.master.remote origin"
+ puts "Set origin as default remote"
+ system "git branch -m master source"
+ puts "Master branch renamed to 'source' for committing your blog source files"
+ else
+ unless !public_dir.match("#{project}").nil?
+ system "rake set_root_dir[#{project}]"
+ end
+ end
+ end
+ url = "http://#{user}.github.com"
+ url += "/#{project}" unless project == ''
+ jekyll_config = IO.read('_config.yml')
+ jekyll_config.sub!(/^url:.*$/, "url: #{url}")
+ File.open('_config.yml', 'w') do |f|
+ f.write jekyll_config
+ end
+ rm_rf deploy_dir
+ mkdir deploy_dir
cd "#{deploy_dir}" do
- system "git symbolic-ref HEAD refs/heads/#{args.branch}"
- system "rm .git/index"
- system "git clean -fdx"
+ system "git init"
system "echo 'My Octopress Page is coming soon &hellip;' > index.html"
system "git add ."
- system "git commit -m 'Octopress init'"
+ system "git commit -m \"Octopress init\""
+ system "git branch -m gh-pages" unless branch == 'master'
+ system "git remote add origin #{repo_url}"
rakefile = IO.read(__FILE__)
- rakefile.sub!(/deploy_branch(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_branch\\1=\\2\\3#{args.branch}\\3")
+ rakefile.sub!(/deploy_branch(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_branch\\1=\\2\\3#{branch}\\3")
rakefile.sub!(/deploy_default(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_default\\1=\\2\\3push\\3")
File.open(__FILE__, 'w') do |f|
f.write rakefile
end
end
- puts "## Deployment configured. Now you can deploy to the #{args.branch} branch with `rake deploy` ##"
+ puts "\n---\n## Now you can deploy to #{url} with `rake deploy` ##"
end
def ok_failed(condition)