-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
31 lines (29 loc) · 903 Bytes
/
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
task :default => :new
require 'fileutils'
desc "创建新 post"
task :new do
puts "请输入要创建的 post URL:"
@url = STDIN.gets.chomp
puts "请输入 post 标题:"
@name = STDIN.gets.chomp
puts "请输入 post 标签:"
@tag = STDIN.gets.chomp
@slug = "#{@url}"
@slug = @slug.downcase.strip.gsub(' ', '-')
@date = Time.now.strftime("%F")
@post_name = "_posts/#{@date}-#{@slug}.md"
if File.exist?(@post_name)
abort("文件名已经存在!创建失败")
end
FileUtils.touch(@post_name)
open(@post_name, 'a') do |file|
file.puts "---"
file.puts "layout: post"
file.puts "title: #{@name}"
file.puts "author: BadReese"
file.puts "date: #{Time.now}"
file.puts "categories: blogs"
file.puts "tag: #{@tag}"
file.puts "---"
end
end