@@ -51,8 +51,10 @@ def jekyll(command = 'build', source = SOURCE_DIR, destination = OUTPUT_DIR, *ar
5151
5252 amended_config = "#{ SOURCE_DIR } /_config_amended.yml"
5353 File . write ( amended_config , YAML . dump ( @config_data ) )
54- system ( "set -x; bundle exec jekyll #{ command } --source #{ source } --destination #{ destination } #{ args . join ( ' ' ) } --config #{ amended_config } #{ verbose_mode } " )
54+ status = system ( "set -x; bundle exec jekyll #{ command } --source #{ source } --destination #{ destination } #{ args . join ( ' ' ) } --config #{ amended_config } #{ verbose_mode } " )
5555 FileUtils . rm ( amended_config )
56+
57+ status
5658end
5759
5860desc 'Stash all directories but one in a temporary location. Run a preview server on localhost:4000.'
@@ -95,13 +97,14 @@ task :preview, :filename do |_t, args|
9597 # put our file list index in place
9698 File . write ( 'index.markdown' , preview_index )
9799
100+ # Trap SIGINT, so user can stop jekyll with Ctrl+C
101+ original_handler = trap ( 'INT' ) { puts "\n (SIGINT received – waiting for Jekyll to shut down...)" }
102+
98103 # Run our preview server, watching ... watching ...
99104 jekyll ( 'serve' , SOURCE_DIR , PREVIEW_DIR )
100-
101- # When we kill it with a ctl-c ...
102- puts "\n \n *** Shut down the server."
103-
105+ ensure
104106 # Clean up after ourselves (in a separate task in case something goes wrong and we need to do it manually)
107+ trap ( 'INT' , original_handler ) if original_handler # Restore original SIGINT handler
105108 Rake ::Task [ 'unpreview' ] . invoke
106109end
107110
@@ -207,7 +210,10 @@ task :generate do
207210
208211 system ( "mkdir -p #{ OUTPUT_DIR } " )
209212 system ( "rm -rf #{ OUTPUT_DIR } /*" )
210- jekyll
213+
214+ # Call jekyll and fail if it's failed
215+ # Shall we `ensure` the cleanup below or keep it as is for debugging?
216+ raise 'Jekyll failed' unless jekyll ( 'build' )
211217
212218 # Rake::Task['symlink_latest_versions'].invoke
213219
259265
260266desc 'Serve generated output on port 9292'
261267task :serve do
262- system ( 'rackup' )
268+ raise 'rackup failed' unless system ( 'rackup' )
263269end
264270
265271desc 'Generate docs and serve locally'
0 commit comments