This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Rakefile
87 lines (74 loc) · 2.17 KB
/
Rakefile
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
84
85
86
87
task :default => :local
desc "Builds the website"
task :build do
system("jekyll")
`mv _site/blog.html _site/blog/index.html`
end
#
desc "Build and refreshes the web page in Firefox"
task :local => :build do
puts %x[rsync -q -acvrz --delete _site/ ~/Sites/]
# %x[osascript -e 'open location "http://localhost/"']
%x[
# Check if Firefox is running, if so refresh
ps -xc|grep -sqi firefox && osascript <<'APPLESCRIPT'
tell app "Firefox" to activate
tell app "System Events"
if UI elements enabled then
keystroke "r" using command down
-- Fails if System Preferences > Universal access > "Enable access for assistive devices" is not on
--else
--tell app "Firefox" to Get URL "JavaScript:window.location.reload();" inside window 1
-- Fails if Firefox is set to open URLs from external apps in new tabs.
end if
end tell
APPLESCRIPT
]
end
desc "Commit the changes to the site"
task :commit => :build do
puts %x[rsync -q -acvrz --exclude .git --delete _site/ _compiled/]
puts %x[./compress.rb]
puts %x[cd _compiled; git add .; git commit -am "`date +%F_%H-%M_%s`"; ]
end
task :send => [:remove_cache, :ssend] do
end
desc "Send the changes to the server and open the webpage"
task :ssend => :commit do
puts %x[cd _compiled; git push origin master]
%x[osascript -e 'open location "http://bilalh.github.com"']
end
desc "Remove the cache"
task :remove_cache do
`rm _cache/*`
end
desc "Makes a new post"
task :new do
throw "No title given" unless ARGV[1]
title = ""
ARGV[1..ARGV.length - 1].each { |v| title += " #{v}" }
title.strip!
now = Time.now
path = "_posts/#{now.strftime('%F')}-#{title.downcase.gsub(/[\s\.]/, '-').gsub(/[^\w\d\-]/, '')}.md"
File.open(path, "w") do |f|
f.puts "---"
f.puts "layout: post"
f.puts "title: #{title}"
f.puts "date: #{now.strftime('%F %T')}"
f.puts "category: "
f.puts "tags:"
f.puts " - "
f.puts "---"
f.puts ""
f.puts ""
end
`mate #{path}`
exit
end
task :css do
require "sass"
contents = IO.read("css/site.scss").gsub(/^\-{3}\n.*?\-{3}/, "")
File.open("_site/site.css", "w") do |f|
f.write Sass::Engine.new(contents, :syntax => :scss, :style => :compressed).render
end
end