Created
March 13, 2012 23:43
-
-
Save zaiste/2032721 to your computer and use it in GitHub Desktop.
Blog Post using Nanoc command
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
usage 'create:post [options]' | |
aliases :cp | |
summary 'create a new blog post' | |
description '' | |
flag :h, :help, 'show help for this command' do |value, cmd| | |
puts cmd.help | |
exit 0 | |
end | |
run do |opts, args, cmd| | |
title = args.first | |
puts "Creating a blog post with a name '#{title}'. Stand by..." | |
date = Time.now | |
#strftime("%Y_%m") | |
filename, path = calc_path(title, date) | |
template = <<TEMPLATE | |
--- | |
created_at: #{date} | |
kind: article | |
publish: true | |
title: "#{title}" | |
--- | |
TODO: Add content to `#{path}.` | |
TEMPLATE | |
File.open(path, 'w') { |f| f.write(template) } | |
puts "\t[ok] Edit #{path}" | |
end | |
def calc_path(title, date) | |
filename = "#{date.strftime('%Y-%m')}_#{title.split.join('_')}.md" | |
path = "content/blog/#{filename}" | |
[filename, path] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment