Skip to content

Commit 9adb6f6

Browse files
committed
Add _bin/newpost script to bootstrap a new post. Usage: _bin/newpost 'Post Title'
1 parent 00f0efd commit 9adb6f6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

_bin/newpost

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
3+
unless ARGV[0]
4+
puts 'Usage: _bin/newpost "Post Title"'
5+
exit(-1)
6+
end
7+
8+
date_prefix = Time.now.strftime("%Y-%m-%d")
9+
post_name = ARGV.join ' '
10+
permalink = post_name.strip.downcase.gsub(/[^a-zA-Z0-9]/, '-')
11+
filename = "#{date_prefix}-#{permalink}.markdown"
12+
post = File.expand_path("../_posts/#{filename}", File.dirname(__FILE__))
13+
14+
header = <<-END
15+
---
16+
layout: post
17+
title: #{post_name}
18+
author:
19+
---
20+
21+
Body text goes here...
22+
END
23+
24+
File.open(post, 'w') do |f|
25+
f << header
26+
end
27+
28+
system("mate", "-a", post)
29+
exit(0)

0 commit comments

Comments
 (0)