1
Fork 0
blog/ext/post

38 lines
798 B
Text
Raw Normal View History

2011-09-03 00:20:01 +02:00
#!/usr/bin/env ruby
# encoding: utf-8
OUTPUT_DIR = File.expand_path("~/projects/fnordig.de/_posts")
2012-09-16 01:20:35 +02:00
EDITOR = ENV['EDITOR'] || 'vim'
2013-06-02 23:02:56 +02:00
EXTENSION=".md"
2011-09-03 00:20:01 +02:00
HEADER = <<EOF
2017-07-09 14:18:22 +02:00
extends: post.liquid
2016-12-10 14:57:51 +01:00
title: "%s"
2011-09-03 00:20:01 +02:00
date: %s
2017-07-09 14:18:22 +02:00
path: /:year/:month/:day/%s
2011-09-03 00:20:01 +02:00
---
EOF
if ARGV.size == 0
$stderr.puts "usage: #{File.basename($0)} title"
exit 1
end
2017-07-09 14:18:22 +02:00
def slugify(args)
args.map { |arg|
arg.downcase.gsub(/[^a-z0-9]/, '-')
}.join('-').gsub(/--+/, '-').gsub(/-$/, '')
end
now = Time.now
slug = slugify(ARGV)
filename = now.strftime("%Y-%m-%d-") + slug
2011-09-03 00:20:01 +02:00
title = ARGV.join(' ')
file = File.join(OUTPUT_DIR, "#{filename}#{EXTENSION}")
2017-07-09 14:18:22 +02:00
date = now.strftime("%d %b %Y %H:%M:%S %z")
2011-09-03 00:20:01 +02:00
puts "new post: #{title}"
puts "file: #{filename}"
2017-07-09 14:18:22 +02:00
File.open(file, "w"){|f| f.write(HEADER % [title, date, slug]) }
2011-09-28 21:53:50 +02:00
exec EDITOR, '+', file