Last active
August 29, 2015 14:07
-
-
Save rpk0/7ef3ba85bff2fbbba342 to your computer and use it in GitHub Desktop.
jekyll_create_post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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