An interesting look through my jekyll workflow of creating a new entry ala Thug Kitchen
Creating a new post? Lets gather what we will need before we even put pen hand to keyboard:
- today’s date
- post title
YAMLproperties- awkward as fuck file name
Ain’t nobody got time for that.
rake post
task :post do
post__name = ask "New post title:"
template(post__name)
# ...
endThis fucker is so minimal he don’t even need arguments. post__name comes up in this handy ass prompt. Simple as shit command line input, hells yeah. Quicker than you can hit ‘enter’, template(post__name) has already been called to drop some efficiency on your punk ass.
template(post__name)
def template(post__name)
date = Time.new.strftime('%Y-%m-%d')
extension = "md"
dir = "_posts/"
fileName = post__name.downcase.gsub( /[^a-zA-Z0-9_\.]/, '-')
newFile = dir + date + "-#{fileName}." + extension
if File.exists? newFile then
puts "#{newFile} already exists. cheese it!"
return
end
#...Creating files like a fucking bawse. He takes your post__name, drops a fucking downcase on him while making it a valid web address1. Multi-talented shit right there. Don’t even worry about making the same post twice, this crafty fucker has your back.
#...
File.open(newFile, "wb") do |post|
post.puts("---")
post.puts("layout : default")
post.puts("title: #{post__name}")
post.puts("excerpt : !required")
post.puts("comments : true")
post.puts("---")
post.puts("!required intro text")
post.puts("<!-- /intro -->")
post.puts("\n!required content")
end
endWhoa, where are you going? Shit hasn’t even started to get real. Mother effing boilerplate is what’s going on here. Son this function lives for that shit. Gets some scaffolding all up your face, ready for some mad blogging to go down.
Better find that file and open your text editor. Wat, hells no! Back the fuck up now. sh "subl -w #{newFile}:10" opens sublime with your newly created post in a flash. You’re fucking welcome. Write the shit out of that post, save and close. BAM! Instantly back in the terminal. Hardcore shit right there if you ask me.
Back to rake post
#...
isRunSite = ask "Run site too? (y/n):"
if isRunSite.downcase == "y" then
Rake::Task["local"].execute
endAll this and we are only up to the third line of :post. This son of a bitch has one more card to play. Another terminal prompt, answer with a mother fucking yes
and your wish of more automation shall be granted. rake local steps in to build the site for your lazy ass. Evens open the damn browser for you. Respect.
An entire post created by simply runing one rake post2
Efficient. As. Fuck.
-
Literally pulled from David Lynch’s work ↩