Browse code

Set flag in preview mode and re-generate files before deployment if necessary

Frederic Hemberger authored on 29/11/2011 at 14:13:50
Showing 2 changed files
... ...
@@ -200,6 +200,13 @@ end
200 200
 
201 201
 desc "Default deploy task"
202 202
 task :deploy do
203
+  # Check if preview posts exist, which should not be published
204
+  if File.exists?(".preview-mode")
205
+    puts "## Found posts in preview mode, regenerating files ..."
206
+    File.delete(".preview-mode")
207
+    Rake::Task[:generate].execute
208
+  end
209
+
203 210
   Rake::Task[:copydot].invoke(source_dir, public_dir)
204 211
   Rake::Task["#{deploy_default}"].execute
205 212
 end
... ...
@@ -24,8 +24,11 @@ module Jekyll
24 24
 
25 25
           # Monkeypatch:
26 26
           # On preview environment (localhost), publish all posts
27
-          if ENV.has_key?('OCTOPRESS_ENV') && ENV['OCTOPRESS_ENV'] == 'preview'
27
+          if ENV.has_key?('OCTOPRESS_ENV') && ENV['OCTOPRESS_ENV'] == 'preview' && post.data.has_key?('published') && post.data['published'] == false
28 28
             post.published = true
29
+            # Set preview mode flag (if necessary), `rake generate` will check for it
30
+            # to prevent pushing preview posts to productive environment
31
+            File.open(".preview-mode", "w") {}
29 32
           end
30 33
 
31 34
           if post.published && (self.future || post.date <= self.time)