Question

I use rake new_post["title"] to generate a new markdown file in _post dir, but I do not want to publish this post before I finished it. How can I do this?

Was it helpful?

Solution

Add published: false to the metadata at the top of your markdown file.

Some older versions of Octopress will still display the posts in preview mode. But when you generate and deploy the site, the posts with published: false will not be published.

OTHER TIPS

rake new_post will not publish the page. Given below is the source code for the same.

# 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 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')
  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
end

Once you have made your changes to your file, you can call rake generate (Generates posts and pages into the public directory) .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top