-
-
Save tnull/34ebd2ea9efcf5209857 to your computer and use it in GitHub Desktop.
Small ruby script to create a new jekyll post, open the editor, start 'jekyll serve' and open the localhost site in a browser.
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
#!/usr/bin/env ruby | |
unless ARGV[0] | |
puts 'Usage: newpost "the post title"' | |
exit(-1) | |
end | |
jekyll_site_prefix = "." | |
editor = "open -a Byword" | |
date_now = Time.now | |
date_prefix = date_now.strftime("%Y-%m-%d") | |
date_header = date_now.strftime("%Y-%m-%d %H:%M:%S") | |
post_title = ARGV.join(" ") | |
post_filename = date_prefix + "-" + post_title.strip.downcase.gsub(/ /, '-') | |
post_filepath = "#{jekyll_site_prefix}/_posts/#{post_filename}.md" | |
header = <<-END | |
--- | |
layout: post | |
title: "#{post_title}" | |
date: #{date_header} | |
--- | |
END | |
File.open(post_filepath, 'w') do |f| | |
f << header | |
end | |
system("touch #{post_filepath}") | |
system(editor + " #{post_filepath}") | |
system("jekyll serve -s #{jekyll_site_prefix}") | |
system("open http://localhost:4000") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment