2011-09-02 22:20:01 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
OUTPUT_DIR = File.expand_path("~/projects/fnordig.de/_posts")
|
2012-09-15 23:20:35 +00:00
|
|
|
EDITOR = ENV['EDITOR'] || 'vim'
|
2013-06-02 21:02:56 +00:00
|
|
|
EXTENSION=".md"
|
2011-09-02 22:20:01 +00:00
|
|
|
HEADER = <<EOF
|
|
|
|
---
|
|
|
|
layout: post
|
2016-12-10 13:57:51 +00:00
|
|
|
title: "%s"
|
2011-09-02 22:20:01 +00:00
|
|
|
date: %s
|
|
|
|
---
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
if ARGV.size == 0
|
|
|
|
$stderr.puts "usage: #{File.basename($0)} title"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
filename = Time.now.strftime("%Y-%m-%d-") + ARGV.map { |arg|
|
2014-03-17 13:08:11 +00:00
|
|
|
arg.downcase.gsub(/[^a-z0-9]/, '-')
|
2014-11-05 13:54:20 +00:00
|
|
|
}.join('-').gsub(/--+/, '-').gsub(/-$/, '')
|
2011-09-02 22:20:01 +00:00
|
|
|
title = ARGV.join(' ')
|
|
|
|
file = File.join(OUTPUT_DIR, "#{filename}#{EXTENSION}")
|
|
|
|
date = Time.now.strftime("%d.%m.%Y %H:%M")
|
|
|
|
|
|
|
|
puts "new post: #{title}"
|
|
|
|
puts "file: #{filename}"
|
|
|
|
File.open(file, "w"){|f| f.write(HEADER % [title, date]) }
|
2011-09-28 19:53:50 +00:00
|
|
|
exec EDITOR, '+', file
|