/
Rakefile
61 lines (52 loc) · 1.6 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
desc 'create new post. args: title, external_url'
# rake sharelink title="New post title goes here" external_url="url-to-share"
task :sharelink do
require 'fileutils'
require 'rubygems'
require 'slugify'
title = ENV['title'] || 'New Title'
external_url = ENV['external_url']
current_time = Time.new
filename = "#{current_time.strftime('%Y-%m-%d')}-#{title.slugify}.md"
dirname = File.join('_posts', current_time.strftime('%Y'), current_time.strftime('%m'))
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
path = File.join(dirname, filename)
post = <<~"YAML"
---
title: "#{title}"
date: "#{current_time.strftime('%Y-%m-%dT%H:%M:%S.%LZ')}"
external_url: "#{external_url}"
category: ""
---
YAML
File.open(path, 'w') do |file|
file.puts post
end
puts "new post generated at #{path}"
system 'code .'
end
desc 'create new post. args: title'
# rake new_article title="New post title goes here"
task :new_article do
require 'fileutils'
require 'rubygems'
require 'slugify'
title = ENV['title'] || 'New Title'
current_time = Time.new
filename = "#{current_time.strftime('%Y-%m-%d')}-#{title.slugify}.md"
dirname = File.join('_posts', current_time.strftime('%Y'), current_time.strftime('%m'))
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
path = File.join(dirname, filename)
post = <<~"YAML"
---
title: "#{title}"
date: "#{current_time.strftime('%Y-%m-%dT%H:%M:%S.%LZ')}"
category: ""
---
YAML
File.open(path, 'w') do |file|
file.puts post
end
puts "new post generated at #{path}"
system 'code .'
end