-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrakefile
153 lines (146 loc) · 5.09 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# adapted from https://github.com/imathis/octopress/blob/master/Rakefile
# usage rake new_post['My New Post'] or rake new_post (defaults to "My New Post")
desc "Start a new post"
task :new, :title do |t, args|
args.with_defaults(:title => 'My New Post')
title = args.title
# filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title.gsub(/&/,'and').gsub(/[,'":\?!\(\)\[\]]/,'').gsub(/[\W\.]/, '-').gsub(/-+$/,'')}.md"
filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title}.md"
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts ""
post.puts "layout: post"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "description: "
post.puts "headline: "
post.puts "modified: #{Time.now.strftime('%Y-%m-%d')}"
post.puts "category: iOS之路"
post.puts "tags: []"
# post.puts "image: "
# post.puts " feature: "
post.puts "imagefeature: "
post.puts "comments: true"
post.puts "mathjax: "
post.puts ""
post.puts "---"
post.puts ""
post.puts ""
post.puts ""
post.puts ""
post.puts ""
post.puts ""
post.puts "原创作品,欢迎转载,转载请声明出处:<http://www.真无聊.com>"
post.puts " "
post.puts "友情链接联系:[email protected]"
post.puts " "
post.puts "交流QQ群:271568188"
end
end
desc "Start a new quote"
task :newquote, :title do |t, args|
args.with_defaults(:title => 'My New quote')
title = args.title
# filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title.downcase.gsub(/&/,'and').gsub(/[,'":\?!\(\)\[\]]/,'').gsub(/[\W\.]/, '-').gsub(/-+$/,'')}.md"
filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title}.md"
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: post"
post.puts "type: quote"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "description: "
post.puts "headline: "
post.puts "modified: #{Time.now.strftime('%Y-%m-%d')}"
post.puts "category: quotes"
post.puts "tags: []"
post.puts "image: "
post.puts " feature: "
post.puts "comments: false"
post.puts "mathjax: "
post.puts "---"
end
end
desc "Start a new status"
task :newstatus, :title do |t, args|
args.with_defaults(:title => 'My New Post')
title = args.title
# filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title.downcase.gsub(/&/,'and').gsub(/[,'":\?!\(\)\[\]]/,'').gsub(/[\W\.]/, '-').gsub(/-+$/,'')}.md"
filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title}.md"
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: post"
post.puts "type: status"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "description: "
post.puts "headline: "
post.puts "modified: #{Time.now.strftime('%Y-%m-%d')}"
post.puts "category: status"
post.puts "tags: []"
post.puts "image: "
post.puts " feature: "
post.puts "comments: false"
post.puts "mathjax: "
post.puts "---"
end
end
# adapted from https://github.com/imathis/octopress/blob/master/Rakefile
# usage rake new_post['My New Post'] or rake new_post (defaults to "My New Post")
desc "Start a new page"
task :newpage, :title do |t, args|
args.with_defaults(:title => 'My New page')
title = args.title
# filename = "#{title.downcase.gsub(/&/,'and').gsub(/[,'":\?!\(\)\[\]]/,'').gsub(/[\W\.]/, '-').gsub(/-+$/,'')}.md"
filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title}.md"
puts "Creating new page: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: page"
post.puts "permalink: #{title.downcase.gsub(/&/,'and').gsub(/[,'":\?!\(\)\[\]]/,'').gsub(/[\W\.]/, '-').gsub(/-+$/,'')}/index.html"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "description: "
post.puts "headline: "
post.puts "modified: #{Time.now.strftime('%Y-%m-%d')}"
post.puts "tags: []"
post.puts "image: "
post.puts " feature: "
post.puts "comments: true"
post.puts "mathjax: "
post.puts "---"
end
end
require 'yaml'
# Load the configuration file
CONFIG = YAML.load_file("_config.yml")
# rake deploy["Commit message"]
desc "Deploy the site to a remote git repo"
task :deploy, :message do |t, args|
message = args[:message]
branch = CONFIG["branch"]
if message.nil? or message.empty?
raise "Please add a commit message."
end
if branch.nil? or branch.empty?
raise "Please add a branch."
else
Rake::Task[:build].invoke
execute("git add .")
execute("git commit -m \"#{message}\"")
puts "提交到 Github..."
# execute("git push origin #{branch}")
execute("git push gh gh-pages")
puts "提交到 codingNet..."
execute("git push codingNet gh-pages")
puts "提交完成!"
end
end
# rake build
desc "Build the site"
task :build do
execute("jekyll build")
end
# Execute a system command
def execute(command)
system "#{command}"
end