Last active
October 5, 2017 00:42
-
-
Save lucca65/7d8692788932a935e881 to your computer and use it in GitHub Desktop.
Simple Rakefile to be used with Jekyll to easily generate new drafts for your blog. used on http://atomicbit.io/ruby/jekyll/2015/04/24/rakefile-for-new-posts-in-jekyll.html
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 'date' | |
desc 'Create a new draft post' | |
task :post do | |
STDOUT.puts('Whats the title of your post?') | |
title = STDIN.gets.chomp | |
if title.nil? || title.empty? | |
STDOUT.puts('No post name? Aborting...') | |
next | |
end | |
slug = "#{Date.today}-#{title.downcase.gsub(/[^\w]+/, '-')}" | |
file = File.join( | |
File.dirname(__FILE__), | |
'_posts', | |
slug + '.markdown' | |
) | |
File.open(file, 'w') do |f| | |
f << <<-EOS.gsub(/^ /, '') | |
--- | |
layout: post | |
title: #{title} | |
published: false | |
categories: | |
--- | |
EOS | |
end | |
system("#{ENV['EDITOR']} #{file}") | |
puts("Post #{title} created successfully!") | |
end | |
desc 'List all draft posts' | |
task :drafts do | |
puts `find ./_posts -type f -exec grep -H 'published: false' {} \\;` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment