imathis / octopress

Octopress is an obsessively designed framework for Jekyll blogging. It’s easy to configure and easy to deploy. Sweet huh?
http://github.com/imathis/octopress
9.32k stars 2.62k forks source link

Can't preview drafts #1599

Open guhehehe opened 10 years ago

guhehehe commented 10 years ago

I can't preview the posts with published set to false. What I did is described below:

  1. set published: false in the yaml front matter of my post.
  2. run rake preview.
  3. go to localhost:4000, the post with published set to false didn't show up.

I search around and seems like rake preview should be able to preview the drafts, but I don't know why it wasn't working for me.

Kernald commented 10 years ago

Probably related to 52f911964577623b2091d306957397ef3b8ccf2d which deleted plugins/preview_unpublished.rb, as Jekyll seems to be supporting drafts now: https://github.com/mrtazz/jekyll/commit/81e4e1d8f4a0bcba46380b719c7afa1fa2261955 . Not sure how to use this from Octopress right now, however.

parkr commented 10 years ago

Try setting unpublished: true in your _config.yml.

guhehehe commented 10 years ago

@parkr Setting unpublished: true seems to generate and display all unpublished posts, I want to work on drafts and preview them locally but not get deployed. It seems like setting published: false in the front matter will prevent the post from being generated, and so it can't get either previewed and deployed

parkr commented 10 years ago

Then it sounds like a perfect candidate for drafts. You can read up on how to use them in the jekyll docs

rcmdnk commented 10 years ago

Why don't we simply implement --unpublished to preview task like

 jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build --watch --unpublished")

at L84 of octopress/Rakefile (and L68 for watch task)?

It works same as before for me.

Inaddition, "OCTOPRESS_ENV" doesn't work w/o plugins/preview_unpublished.rb, therefore we can remove it or we should use it correctly to make .preview-mode file as treated in deploy task.

dgmstuart commented 9 years ago

If this is the case then the docs on blogging are incorrect and should be updated. Here's the source: https://github.com/imathis/octopress/blob/site-2.1/source/docs/blogging/index.markdown

...but I'm not sure what it should say...

@parkr @Kernald I'm not convinced Jekyll's drafts work in Octopress: rake preview --drafts and rake generate --drafts both claim that --drafts is an invalid flag. Is that because the flag gets passed to rake itself rather than the rake task?

Is there some other way of passing that flag through to jekyll?

Or perhaps @imathis can recommend some other way of previewing drafts?

On the positive site, I do think it makes more sense to not show draft posts in a preview by default: it worried me the first time I previewed my blog and a bunch of drafts showed up!

dgmstuart commented 9 years ago

Oh, and here's the Jekyll docs page about drafts: http://jekyllrb.com/docs/drafts/

dhfromkorea commented 5 years ago

It's quite late but I have been using this hot fix. Not elegant but should do the job for those who remain on Octopress 2. Just need to modify your Rakefile.

desc "Default deploy task"
task :deploy do
  # Check if preview posts exist, which should not be published
  if File.exists?(".preview-mode")
    puts "## Found posts in preview mode, regenerating files ..."
    File.delete(".preview-mode")
    Rake::Task[:generate].execute
  end
  Rake::Task[:copydot].invoke(source_dir, public_dir)

  # exclude drafts in public/ before deployment
  # we compare each post in source/_drafts/ against one in public/
  Dir.foreach("#{args.source}/_drafts") do |item|
    file_ext = File.extname(item) 
    puts "draft file candidate: #{file_ext}"
    if file_ext == ".markdown" or file_ext == ".md"
        file_base = File.basename(item, file_ext) 
        puts "removing a draft: #{public_dir}/#{file_base}"
        rm_rf("#{public_dir}/#{file_base}")
    end
  end
  Rake::Task["#{deploy_default}"].execute
end