Skip to content

Instantly share code, notes, and snippets.

@SirRawlins
Last active September 15, 2020 06:22
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save SirRawlins/8684701 to your computer and use it in GitHub Desktop.
Save SirRawlins/8684701 to your computer and use it in GitHub Desktop.
Using Jekyll plugins on GitHub Pages.
# Rquire jekyll to compile the site.
require "jekyll"
# Github pages publishing.
namespace :blog do
#
# Because we are using 3rd party plugins for jekyll to manage the asset pipeline
# and suchlike we are unable to just branch the code, we have to process the site
# localy before pushing it to the branch to publish.
#
# We built this little rake task to help make that a little bit eaiser.
#
# Usaage:
# bundle exec rake blog:publish
desc "Publish blog to gh-pages"
task :publish do
# Compile the Jekyll site using the config.
Jekyll::Site.new(Jekyll.configuration({
"source" => ".",
"destination" => "_site",
"config" => "_config.yml"
})).process
# Get the origin to which we are going to push the site.
origin = `git config --get remote.origin.url`
# Make a temporary directory for the build before production release.
# This will be torn down once the task is complete.
Dir.mktmpdir do |tmp|
# Copy accross our compiled _site directory.
cp_r "_site/.", tmp
# Switch in to the tmp dir.
Dir.chdir tmp
# Prepare all the content in the repo for deployment.
system "git init" # Init the repo.
system "git add . && git commit -m 'Site updated at #{Time.now.utc}'" # Add and commit all the files.
# Add the origin remote for the parent repo to the tmp folder.
system "git remote add origin #{origin}"
# Push the files to the gh-pages branch, forcing an overwrite.
system "git push origin master:refs/heads/gh-pages --force"
end
# Done.
end
end
@meefen
Copy link

meefen commented May 5, 2014

Thanks for the tip! I found it necessary to add the following line to rake:
require 'tmpdir'

Also, I'm new to Jekyll. I found my website still pointing to the master (rather than gh-pages) branch. Any advice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment