-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrakefile
executable file
·39 lines (36 loc) · 1.22 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
def edit_config(name, value)
config = File.read('_config.yml')
regexp = Regexp.new('(^\s*' + name + '\s*:\s*)(\S+)(\s*)$')
config.sub!(regexp,'\1'+value+'\3')
File.open('_config.yml', 'w') {|f| f.write(config)}
end
namespace :env do
desc 'Sets the configuration for development mode.'
task :dev do
edit_config 'url', 'http://localhost:4000'
end
desc 'Sets the configuration for production mode.'
task :prod do
edit_config 'url', ''
end
end
# adapted from https://github.com/imathis/octopress/blob/master/Rakefile
# usage rake new_post['My New Post'] or rake new_post (defaults to "My New Post")
desc "Draft a new post"
task :new, :title do |t, args|
args.with_defaults(title: 'My New Post')
title = args.title
filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title.downcase.gsub(/&/,'and').gsub(/[,'":\?!\(\)\[\]]/,'').gsub(/[\W\.]/, '-').gsub(/-+$/,'')}.md"
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: post"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "date: #{Time.now.strftime('%Y-%m-%d')}"
post.puts "author: "
post.puts "category: "
post.puts "tags: []"
post.puts "comments: true"
post.puts "---"
end
end