个人博客搭建

你的个人小天地

Octopress中的文件使用中文

我不喜欢Octopress把我的文件转义成英文的格式:

2015-12-27-li-yong-octopressda-da-jian-ge-ren-bo-ke.markdown

很明显我是看不懂上面这个文件的意义的,我需要的是中文

我希望创建文章的时候我可以直接指定文章的路径

rake new_post["Octopress中的文件使用中文","octopress"]

最后的代码如下:

# 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, :path] do |t, args|
  if args[:path]
      path = args[:path]
  end
  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}/#{path}/"
  filename = "#{source_dir}/#{posts_dir}/#{path}/#{Time.now.strftime('%Y-%m-%d')}-#{title}.#{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"
    post.puts "categories: "
    post.puts "tags: "
    post.puts "---"
  end
end