-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
59 lines (52 loc) · 1.53 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
require 'date'
# def optional_text(condition,truthy,falsey)
# (condition ? truthy : falsey).strip
# end
namespace :new do
desc "Interactively create a new post"
task :post do
print "Post title: "
title = STDIN.gets.chomp
print "Post category (default: posted): "
category = STDIN.gets.chomp
category = category.empty? ? "posted" : category
puts "Title is '#{title}' and category is '#{category}'"
slug = title.downcase.gsub(/\s/,'-').gsub(/[^\w-]/,'').gsub(/[-]{2,}/,'-')
file_name = "#{Date.today.strftime("%F")}-#{slug}.md"
puts "File name: #{file_name}"
File.open("_posts/#{file_name}","w") do |f|
f.write <<~YML.chomp
---
title: #{title}
description: >
DESCRIPTIVELY DESCRIBE THIS POST
date: #{Time.now.strftime("%F %T %z")}
category: #{category}
---
YML
end
end
desc "Interactively create a new link"
task :link do
print "Link title: "
title = STDIN.gets.chomp
slug = title.downcase.gsub(/\s/,'-').gsub(/[^\w-]/,'').gsub(/[-]{2,}/,'-')
print "Link URL: "
link = STDIN.gets.chomp
file_name = "#{Date.today.strftime("%F")}-#{slug}.md"
puts "File name: #{file_name}"
File.open("_posts/#{file_name}","w") do |f|
f.write <<~YML.chomp
---
title: #{title}
description: >
DESCRIPTIVELY DESCRIBE THIS LINK
link: #{link}
date: #{Time.now.strftime("%F %T %z")}
category: linked
---
> Quoted material...
YML
end
end
end