-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
49 lines (40 loc) · 1.23 KB
/
Rakefile
File metadata and controls
49 lines (40 loc) · 1.23 KB
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
require 'rake'
require 'date'
require 'pathname'
require 'fileutils'
require 'active_support/all'
namespace :post do
desc "Create a new post template"
task :new do
unless ENV["TITLE"]
raise "ERROR: e.g. rake post:new TITLE='post file name'"
end
title = ENV['TITLE']
date = ENV['DATE'] || Date.today.to_s
filename = "#{date}-#{title.downcase.gsub(/\s+/, "-")}.markdown"
directory = File.expand_path('_posts/', File.dirname(__FILE__))
post_path = File.join(directory, filename)
if File.exist?(post_path)
raise "ERROR: post file '#{post_path}' already exists"
end
File.write post_path, <<-EOF.strip_heredoc
---
layout: post
title: "#{title}"
date: #{date} 23:00:00 +0800
---
EOF
puts "Created #{post_path}"
end
desc "handle images CND of post"
task :image_cdn do
directory = File.expand_path('_posts/', File.dirname(__FILE__))
if ENV['FILENAME']
post_path = File.join(directory, ENV['FILENAME'])
text = File.read(post_path)
new_contents = text.gsub(ENV['IMG_SRC'], ENV['IMG_DIST'])
File.open(post_path, "w") { |file| file.puts new_contents }
puts "Image link replaced #{post_path}"
end
end
end