mph.paste.lol / omgpost.rb · 1 year ago·

!/usr/bin/env ruby

- requires the slugify gem - gem install slugify

- opens the file in your default editor as set by macOS, not your shell

- does nothing to keep the slug length reasonable, so your film review of

"The Assassination of Jesse James by the Coward Robert Ford" is going to have a long

slug.

- hpost.rb --help for help on the options

require 'optparse' require 'slugify' require 'date'

Where's your post directory?

site_posts_dir = "~/src/simple/content/posts/"

options = {}

OptionParser.new do |parser| parser.on("-t", "--title TITLE", "The title of the post in quotes.") do |o| options[:title] = o end

parser.on("-T", "--tags TAGS", "Comma-delimited tags for the post, e.g. 'banana,apple,pear'") do |o| options[:tags] = o end

parser.on("-h", "--help", "Get help.") do |o| puts parser exit(0) end

end.parse!

date = Date.today.strftime("%Y-%m-%d") long_date = Time.now.strftime("%Y-%m-%d %H:%M%p") slug = options[:title].slugify filename = date + '-' + slug + '.md' file_path = File.expand_path(site_posts_dir + filename)

if File.exists?(file_path) abort("*** Error: #{file_path} already exists. Exiting.") end

post = <<-POST

Date: #{long_date} Tags: #{options[:tags]}

#{options[:title]}

POST

File.write(file_path, post)

open #{file_path}