forked from toin0u/sbin.dk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
71 lines (66 loc) · 2.16 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
# rake -T to show available tasks
# Usage: rake
desc "Show available commands (tasks)"
task :default do
puts "server: build files and launch local dev server"
puts "release: push repository to VPS"
puts "publish: push repository to Github"
puts "post [new post name]: create a new post file like YYYY-MM-DD-new-post-name.md"
end
# Usage: rake server
desc "Build files and launch local dev server"
task :server do
puts "Building files and launching local dev server..."
sh "jekyll server --watch"
end
# Usage: rake release
desc "Push repository to VPS"
task :release => :publish do
puts "Pushing repository to VPS..."
sh "git push deploy master"
end
# Usage: rake publish
desc "Push repository to Github"
task :publish do
puts "Pushing repository to Github..."
sh "git push origin master"
end
# Usage: rake post "New post name"
desc "Create a new post file like YYYY-MM-DD-new-post-name.md"
task :post do
# get last argument as title which is a task
title = ARGV.last
# title task will do nothing
task title.to_sym do ; end
dirname = File.join(".", "_posts")
if not FileTest.directory?(dirname)
abort("rake aborted: #{dirname} directory is not found!")
end
date = Time.now.strftime('%F')
fulldate = Time.now.strftime('%F %T')
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
filename = "#{date}-#{slug}.md"
fullpath = File.join(dirname, filename)
if File.exist?(fullpath)
abort("rake aborted: #{fullpath} already exists!")
end
puts "Creating a new post file called #{filename} with YAML front matter..."
File.open(fullpath, 'w') do |post|
post.puts "---"
post.puts "layout: post"
post.puts "change_frequency: weekly"
post.puts "priority: 0.8"
post.puts "published: true"
post.puts "comments: true"
post.puts "date: #{fulldate}"
post.puts "title: #{title}"
post.puts "summary: "
post.puts "category: "
post.puts "tags: "
post.puts "redirects:"
post.puts "---"
post.puts ""
end
puts "Opening #{fullpath} in Sublime Text 2..."
sh "subl #{fullpath}"
end