1
Fork 0
blog/ext/post

39 lines
810 B
Plaintext
Raw Normal View History

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
2017-07-09 12:18:22 +00:00
extends: post.liquid
2016-12-10 13:57:51 +00:00
title: "%s"
2011-09-02 22:20:01 +00:00
date: %s
2017-07-09 12:18:22 +00:00
path: /:year/:month/:day/%s
2018-01-08 10:20:34 +00:00
route: blog
2011-09-02 22:20:01 +00:00
---
EOF
if ARGV.size == 0
$stderr.puts "usage: #{File.basename($0)} title"
exit 1
end
2017-07-09 12:18:22 +00: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-02 22:20:01 +00:00
title = ARGV.join(' ')
file = File.join(OUTPUT_DIR, "#{filename}#{EXTENSION}")
2017-07-09 12:18:22 +00:00
date = now.strftime("%d %b %Y %H:%M:%S %z")
2011-09-02 22:20:01 +00:00
puts "new post: #{title}"
puts "file: #{filename}"
2017-07-09 12:18:22 +00:00
File.open(file, "w"){|f| f.write(HEADER % [title, date, slug]) }
2011-09-28 19:53:50 +00:00
exec EDITOR, '+', file