-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRakefile
84 lines (76 loc) · 2.01 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
require "rubygems"
require "bundler/setup"
require "stringex"
# Variables
posts_dir = "_posts"
new_post_ext = "md"
#######################
# Working with Jekyll #
#######################
namespace :site do
# rake build
desc "Build the site with Jekyll"
task :build do
puts "## Generating Site with Jekyll"
system "jekyll build"
end
# rake watch
desc "Start this site's Jekyll server"
task :watch do
system "jekyll serve -w"
end
# rake preview
desc "Preview the site in your default browser"
task :preview do
port = 4000
Thread.new do
puts "Launching browser for preview..."
sleep 5
system("#{open_command} http://localhost:#{port}/")
end
Rake::Task["site:watch"].invoke
end
end
namespace :theme do
# usage rake new_post[my-new-post] or rake new_post['my new post']
desc "Create a new theme in #{posts_dir}"
task :new, :title do |t, args|
if args.title
title = args.title
else
title = get_stdin("Enter a title for your post: ")
end
filename = "#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
end
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: theme"
post.puts "thumbnail: /public/thumbnails/"
post.puts "title: #{title.gsub(/&/,'&')}"
post.puts "tags: "
post.puts "author: "
post.puts "author_url: "
post.puts "package_url: "
post.puts "package_name: "
post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}"
post.puts "---"
end
end
end
# Get the "open" command for rake preview
def open_command
if RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
"start"
elsif RbConfig::CONFIG["host_os"] =~ /darwin/
"open"
else
"xdg-open"
end
end
def get_stdin(message)
print message
STDIN.gets.chomp
end