Source

leafstorm.us / Rakefile

Full commit
require 'nanoc3/tasks'
require 'time'

def require_env (var)
  if !ENV[var]
    $stderr.puts "Error: Please provide #{var}=value on the command line."
    exit 1
  end
  ENV[var]
end


namespace :create do
  desc "Creates a new article"
  task :article do
    title = require_env 'title'
    slug = require_env 'slug'
    
    site = Nanoc3::Site.new(".")
    
    content = <<CONTENT
---
title: #{title}
slug: #{slug}
created_at: #{Time.now.to_s}
kind: article
tags: []
summary: ""

---

(New blog article)
CONTENT
    
    path = File.join("content", "articles", "#{slug}.md")
    File.open(path, 'w') { |io| io.write(content) }
    
    $stderr.puts "New article saved to #{path}"
  end
end