-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRakefile
More file actions
37 lines (34 loc) · 954 Bytes
/
Rakefile
File metadata and controls
37 lines (34 loc) · 954 Bytes
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
require 'fileutils'
require "pry"
require 'active_support'
require 'active_support/all'
namespace :post do
desc 'Usage: rake post:new["My awesome title"]'
task :new, [:title] do |t, args|
date = Date.today.strftime("%Y-%m-%d")
file_name = [date, args[:title]].join("-").parameterize
file_name = "#{file_name}.markdown"
file_path = File.join(File.dirname(__FILE__), "_posts", file_name)
if File.exist?(file_path)
puts "[SKIPPED] File already exists: #{file_path}"
else
# FileUtils.touch(file_path)
File.open(file_path, "w") do |file|
file.write(new_post_template(args[:title], DateTime.now))
end
puts "New post created: #{file_path}"
end
end
end
def new_post_template(title, date_time)
if date_time.respond_to?(:strftime)
date_time = date_time.strftime("%Y-%m-%d %H:%M:%S %z")
end
<<-TEMPLATE
---
layout: post
title: "#{title}"
date: #{date_time}
---
TEMPLATE
end