Created
          April 24, 2016 10:03 
        
      - 
      
- 
        Save omps/223f8c8e6a1d378f51d27f4d9b55b80c to your computer and use it in GitHub Desktop. 
    rak new_post task
  
        
  
    
      This file contains hidden or 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 rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post") | |
| desc "Begin a new post in #{source_dir}/#{posts_dir}" | |
| task :new_post, :title, :tweet do |t, args| | |
| raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir) | |
| mkdir_p "#{source_dir}/#{posts_dir}" | |
| args.with_defaults(:title => 'new-post', :tweet => '') | |
| title = args.title | |
| filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}" | |
| if File.exist?(filename) | |
| abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n' | |
| end | |
| puts "Creating new post: #{filename}" | |
| open(filename, 'w') do |post| | |
| post.puts "---" | |
| post.puts "layout: post" | |
| post.puts "title: \"#{title.gsub(/&/,'&')}\"" | |
| post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}" | |
| post.puts "comments: true" | |
| post.puts "categories: " | |
| post.puts "---" | |
| end | |
| tweet = args.tweet | |
| if not tweet == '' | |
| # add to twitter status queue | |
| puts 'Adding post to tweet queue, it will be tweeted after deploying.' | |
| open('tweet_queue', 'a') do |file| | |
| file.puts "#{tweet} - #{blog_url}#{Time.now.strftime('%Y/%m/%d')}/#{title.to_url}/" | |
| end | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment