Skip to content

Commit 6714e5c

Browse files
committed
Set flag in preview mode and re-generate files before deployment if necessary
1 parent f1ebf35 commit 6714e5c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ end
200200

201201
desc "Default deploy task"
202202
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+
203210
Rake::Task[:copydot].invoke(source_dir, public_dir)
204211
Rake::Task["#{deploy_default}"].execute
205212
end

plugins/preview_unpublished.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ def read_posts(dir)
2424

2525
# Monkeypatch:
2626
# 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
2828
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") {}
2932
end
3033

3134
if post.published && (self.future || post.date <= self.time)

0 commit comments

Comments
 (0)