This repository was archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
83 lines (66 loc) · 2.18 KB
/
Rakefile
File metadata and controls
83 lines (66 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Require jekyll to compile the site.
require "jekyll"
require 'time'
ENV["JEKYLL_ENV"] = 'production'
# Github pages publishing.
namespace :site 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 site:publish
desc "Publish site to master"
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/master --force"
end
# Done.
end
desc 'create a new draft post'
task :post do
title = ENV['TITLE']
slug = "#{Date.today}-#{title.downcase.gsub(/[^\w]+/, '-')}"
file = File.join(
File.dirname(__FILE__),
'_posts',
slug + '.md'
)
File.open(file, "w") do |f|
f << <<-EOS.gsub(/^ /, '')
---
layout: post
title: #{title}
date: #{Time.now.strftime('%Y-%m-%d %H:%M')}
published: false
categories:
---
EOS
end
system ("#{ENV['EDITOR']} #{file}")
end
end
task default: ["site:publish"]