我用 rake new_post["title"] 在 _post 目录中生成一个新的 markdown 文件,但我不想在完成之前发布这篇文章。我怎样才能做到这一点?

有帮助吗?

解决方案

添加 published: false 到 Markdown 文件顶部的元数据。

某些旧版本的 Octopress 仍会以预览模式显示帖子。但是当您生成并部署网站时,帖子会带有 published: false 将不会被发布。

其他提示

rake new_post 不会发布该页面。下面给出了相同的源代码。

# 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

对文件进行更改后,您可以致电 rake generate (在公共目录中生成帖子和页面)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top