Edit Rakefile of Octopress: Add 2nd Argument to New_post[]

I write a dialy everyday that is ‘30 days challengs’.

I wanna write a post more easily for me because to write a 1 line post is too complicated for me.

So, I added a 2nd argument for new_post command and add it main paragraph automaticly.

Like this!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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, :oneline_dialy do |t, args|
# Added a 2nd argument"oneline_dialy"

  # for debug
  puts args.oneline_dialy

  if args.title
    title = args.title
  else
    title = get_stdin("Enter a title for your post: ")
  end
  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}"
  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:%S %z')}"
    post.puts "comments: true"
    if args.oneline_dialy
      post.puts "categories: 30daysChallenge20140207"
      post.puts "---"
      post.puts args.oneline_dialy
    else
      post.puts "categories: "
      post.puts "---"
    end

  end
end

But idk this is a BEAUTIFUL CODE. I dont suppose so :(

Copyright © 2014 - Remicck. Powered by Octopress