|
|
@@ -0,0 +1,111 @@ |
|
|
require 'stringex' |
|
|
|
|
|
POSTS_DIR = '_posts' |
|
|
BUILD_DIR = '_site' |
|
|
DEPLOY_DIR = '_deploy' |
|
|
DEPLOY_BRANCH = 'master' |
|
|
|
|
|
desc "Build the site" |
|
|
task :build do |
|
|
sh "jekyll build" |
|
|
end |
|
|
|
|
|
desc "Start web server to preview site" |
|
|
task :preview do |
|
|
sh "jekyll serve --drafts --watch" |
|
|
end |
|
|
|
|
|
desc 'Create a new draft' |
|
|
task :new_draft, :title do |t, args| |
|
|
title = args[:title] || 'New Draft' |
|
|
filename = File.join('_drafts', "#{title.to_url}.md") |
|
|
|
|
|
puts "==> Creating new draft: #{filename}" |
|
|
open(filename, 'w') do |f| |
|
|
f << "---\n" |
|
|
f << "layout: post\n" |
|
|
f << "title: \"#{title.to_html(true)}\"\n" |
|
|
f << "tags:\n" |
|
|
f << "---\n" |
|
|
f << "\n" |
|
|
f << "Add awesome content here.\n" |
|
|
end |
|
|
end |
|
|
|
|
|
desc 'Create a new post' |
|
|
task :new_post, :title do |t, args| |
|
|
title = args[:title] || 'New Post' |
|
|
timestamp = Time.now.strftime('%Y-%m-%d') |
|
|
filename = File.join(POSTS_DIR, "#{timestamp}-#{title.to_url}.md") |
|
|
|
|
|
puts "==> Creating new post: #{filename}" |
|
|
open(filename, 'w') do |f| |
|
|
f << "---\n" |
|
|
f << "layout: post\n" |
|
|
f << "title: \"#{title.to_html(true)}\"\n" |
|
|
f << "tags:\n" |
|
|
f << "---\n" |
|
|
f << "\n" |
|
|
f << "Add awesome post content here.\n" |
|
|
end |
|
|
end |
|
|
|
|
|
desc 'Create a new page' |
|
|
task :new_page, :title do |t, args| |
|
|
title = args[:title] || 'New Page' |
|
|
filename = File.join(title.to_url, 'index.md') |
|
|
|
|
|
puts "==> Creating new page: #{filename}" |
|
|
mkdir_p title.to_url |
|
|
open(filename, 'w') do |f| |
|
|
f << "---\n" |
|
|
f << "layout: page\n" |
|
|
f << "title: \"#{title.to_html(true)}\"\n" |
|
|
f << "---\n" |
|
|
f << "\n" |
|
|
f << "Add awesome page content here.\n" |
|
|
end |
|
|
end |
|
|
|
|
|
def git(*args) |
|
|
sh 'git', *args |
|
|
end |
|
|
|
|
|
desc 'Deploy the site via Git' |
|
|
task :deploy => :build do |
|
|
repo_url = `git config jekyll.deployurl`.chomp |
|
|
if repo_url.empty? |
|
|
abort 'error: set git repo url via `git config jekyll.deployurl` first' |
|
|
end |
|
|
|
|
|
if File.directory?(DEPLOY_DIR) |
|
|
rm_rf Dir["#{DEPLOY_DIR}/*"] |
|
|
else |
|
|
mkdir_p DEPLOY_DIR |
|
|
end |
|
|
|
|
|
if File.directory?(File.join(DEPLOY_DIR, '.git')) |
|
|
puts "==> Updating Git repository in #{DEPLOY_DIR} ..." |
|
|
cd DEPLOY_DIR do |
|
|
git 'fetch', '--prune' |
|
|
git 'reset', '--hard', "origin/#{DEPLOY_BRANCH}" |
|
|
end |
|
|
else |
|
|
puts "==> Cloning Git repository into #{DEPLOY_DIR} ..." |
|
|
git 'clone', '--branch', DEPLOY_BRANCH, repo_url, DEPLOY_DIR |
|
|
end |
|
|
|
|
|
puts "==> Copying files from #{BUILD_DIR} to #{DEPLOY_DIR} ..." |
|
|
cp_r Dir["#{BUILD_DIR}/*"], DEPLOY_DIR |
|
|
|
|
|
cd DEPLOY_DIR do |
|
|
puts '==> Pushing changes to remote Git repository...' |
|
|
git 'add', '--all' |
|
|
git 'commit', '--message', "Site updated at #{Time.now}" |
|
|
git 'push', 'origin', DEPLOY_BRANCH |
|
|
end |
|
|
|
|
|
puts '==> Site successfully deployed.' |
|
|
end |
|
|
|
|
|
task :default => :preview |