1
Fork 0
blog/ext/post

41 lines
855 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
2018-12-24 14:29:16 +00:00
---
2018-01-10 11:24:54 +00:00
permalink: "/{{ year }}/{{ month }}/{{ day }}/%s"
2016-12-10 13:57:51 +00:00
title: "%s"
2018-01-10 11:24:54 +00:00
published_date: "%s"
layout: post.liquid
data:
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}")
2018-01-10 11:24:54 +00:00
date = now.strftime("%Y-%m-%d %H:%M:00 %z")
2011-09-02 22:20:01 +00:00
puts "new post: #{title}"
puts "file: #{filename}"
2018-01-10 11:24:54 +00:00
File.open(file, "w"){|f| f.write(HEADER % [slug, title, date]) }
2011-09-28 19:53:50 +00:00
exec EDITOR, '+', file