deploy_dir="_deploy"# deploy directory (for Github pages deployment)stash_dir="_stash"# directory to stash posts for speedy generationposts_dir="_posts"# directory for blog filesorg_posts_dir="org_posts"themes_dir=".themes"# directory for blog filesnew_post_ext="org"# default new post file extension when using the new_post tasknew_page_ext="markdown"# default new page file extension when using the new_page taskserver_port="4000"# port for preview server eg. localhost:4000# open ,使用系统默认编辑器# open -a Mou,使用Mou打开# open -a Byword,使用Byword打开# subl, 使用Sublime Text2打开editor="~/bin/em"# Emacs wrapper
theme=args.theme||'classic'puts"## Copying "+theme+" theme into ./#{source_dir} and ./sass"mkdir_psource_dircp_r"#{themes_dir}/#{theme}/source/.",source_dirmkdir_p"sass"cp_r"#{themes_dir}/#{theme}/sass/.","sass"mkdir_p"#{source_dir}/#{posts_dir}"mkdir_p"#{source_dir}/#{org_posts_dir}"mkdir_ppublic_dir
在 task :new_post, :title do |t, args| 语句之下,添加新建文档目录和新建文章的语句:
task:new_post,:titledo|t,args|raise"### You haven't set anything up yet. First run `rake install` to set up an Octopress theme."unlessFile.directory?(source_dir)mkdir_p"#{source_dir}/#{posts_dir}"mkdir_p"#{source_dir}/#{org_posts_dir}"args.with_defaults(:title=>'new-post')title=args.titlefilename="#{source_dir}/#{org_posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"ifFile.exist?(filename)abort("rake aborted!")ifask("#{filename} already exists. Do you want to overwrite?",['y','n'])=='n'end
desc"Begin a new post in #{source_dir}/#{org_posts_dir}"task:new_post,:titledo|t,args|raise"### You haven't set anything up yet. First run `rake install` to set up an Octopress theme."unlessFile.directory?(source_dir)mkdir_p"#{source_dir}/#{posts_dir}"mkdir_p"#{source_dir}/#{org_posts_dir}"args.with_defaults(:title=>'new-post')title=args.titlefilename="#{source_dir}/#{org_posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"ifFile.exist?(filename)abort("rake aborted!")ifask("#{filename} already exists. Do you want to overwrite?",['y','n'])=='n'endputs"Creating new post: #{filename}"open(filename,'w')do|post|post.puts"#+BEGIN_HTML"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"---"post.puts"#+END_HTML"endif#{editor}system"sleep 1; #{editor}#{filename}"endend