Skip to content

Instantly share code, notes, and snippets.

@rpk0 rpk0/create_post_md.rb
Last active Aug 29, 2015

Embed
What would you like to do?
jekyll_create_post
require 'slop'
require 'date'
opts = Slop.parse( help: true, ignore_case: true) do
banner 'Usage: create_post.rb [options]'
on '-v', 'Print the version' do
puts "Version 1.0.1"
end
on :n, :title=, 'Title', as: String
on :c, :category=, 'Category', as: String
on :t, :tags=, 'Tags', as: Array, delimiter: ' - '
end
opts = opts.to_hash
tags = opts[:tags].first.scan(/[^,\.]+/)
slug = "#{Date.today}-#{opts[:title].downcase.gsub(/[^\w]+/, '-')}"
file = File.join(
File.dirname(__FILE__),
# '_posts',
slug + '.markdown'
)
File.open(file, "w") do |f|
f << <<-EOS.gsub(/^ /, '')
---
layout: post_layout
title: #{opts[:title]}
avatar:
category: #{opts[:category]}
tags: [#{tags.join(' - ')}]
path: posts
---
EOS
end
system ("#{ENV['EDITOR']} #{file}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.