Skip to content

Instantly share code, notes, and snippets.

@lucca65
Last active October 5, 2017 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucca65/7d8692788932a935e881 to your computer and use it in GitHub Desktop.
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
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