Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
Work around astefanutti/decktape#220 in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
DanySK committed Aug 25, 2020
1 parent 4363e35 commit ddb96d5
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions slides/makepdf.rb
@@ -1,5 +1,19 @@
#!/usr/bin/env ruby

# Configuration options
website_address = 'http://localhost:1313/Course-Laboratory-of-Software-Systems/' # always add the trailing slash
decktape_options = '-s 1440x900 -p 20'

# Workaround for decktape bug
puts 'Working around bug: https://github.com/astefanutti/decktape/issues/220'
puts 'By replacing max vieport relative sizes 95/80 with 120/140'

shortcode_path = 'layouts/shortcodes/image.html'
custom_image_shortcode = File.read(shortcode_path)
replace_width = custom_image_shortcode.gsub(/}}\s*95\s*{{/, '}}120{{')
replace_both = replace_width.gsub(/}}\s*80\s*{{/, '}}140{{')
File.open(shortcode_path, 'w') { | file | file.puts replace_both }

log_file_name = "hugo.log"
`touch #{log_file_name}`
log_file = File.open(log_file_name, "r")
Expand All @@ -20,18 +34,19 @@
end
puts "Generation complete!"

def generate_slides(target)
def generate_slides(decktape_command, target)
proposed_name = target&.gsub('/', '-') || ""
pdf_name = proposed_name&.empty? ? "00-introduction" : proposed_name
puts "Using decktape to generate #{pdf_name}.pdf from /#{target}"
`decktape -s 1440x900 http://localhost:1313/Course-Laboratory-of-Software-Systems/#{target} #{pdf_name}.pdf`
`#{decktape_command}#{target} #{pdf_name}.pdf`
end

decktape_command_base = "decktape #{decktape_options} #{website_address}"
for pack in contents
generate_slides pack
generate_slides(decktape_command_base, pack)
end
# Site has been generated and is being served. Launch decktape
`decktape http://localhost:1313/Course-Laboratory-of-Software-Systems/ slides.pdf`
puts `#{decktape_command_base} slides.pdf`
# Terminate the server
Process.kill("TERM", server)
begin
Expand All @@ -40,3 +55,8 @@ def generate_slides(target)
puts "The server terminated before I could wait for it."
end
File.delete(log_file)

# Undo the bug workaround
puts 'Undoing the bug workaround'
File.open(shortcode_path, 'w') { | file | file.puts custom_image_shortcode }
puts 'Done.'

0 comments on commit ddb96d5

Please sign in to comment.