Skip to content

Instantly share code, notes, and snippets.

@ksaynice
Created December 4, 2017 09:07
Show Gist options
  • Save ksaynice/f35213076bac29750242c20e95bd2880 to your computer and use it in GitHub Desktop.
Save ksaynice/f35213076bac29750242c20e95bd2880 to your computer and use it in GitHub Desktop.
Rake task to publish jekyll site to github page (master branch OR gh-pages with site namespace)
require "rubygems"
require "tmpdir"
require "bundler/setup"
require "jekyll"
# Change your GitHub reponame
GITHUB_REPONAME = "ksaynice/some_repo_name"
# desc "Generate blog files"
# task :generate do
# Jekyll::Site.new(Jekyll.configuration({
# "source" => ".",
# "destination" => "_site"
# })).process
# end
#
#
# desc "Generate and publish blog to gh-pages"
# task :publish => [:generate] do
# Dir.mktmpdir do |tmp|
# cp_r "_site/.", tmp
#
# pwd = Dir.pwd
# Dir.chdir tmp
#
# system "git init"
# system "git add ."
# message = "Site updated at #{Time.now.utc}"
# system "git commit -m #{message.inspect}"
# system "git remote add origin git@github.com:#{GITHUB_REPONAME}.git"
# system "git push origin master --force"
#
# Dir.chdir pwd
# end
# end
namespace :site do
desc "Generate blog files"
task :generate do
Jekyll::Site.new(Jekyll.configuration({
"source" => ".",
"destination" => "_site"
})).process
end
desc "Generate and publish blog to gh-pages"
task :publish => [:generate] do
Dir.mktmpdir do |tmp|
cp_r "_site/.", tmp
pwd = Dir.pwd
Dir.chdir tmp
system "git init"
system "git add ."
message = "Site updated at #{Time.now.utc}"
system "git commit -m #{message.inspect}"
system "git remote add origin git@github.com:#{GITHUB_REPONAME}.git"
system "git push origin master:refs/heads/gh-pages --force"
Dir.chdir pwd
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment