diff --git a/README.md b/README.md index 23b46a2a24fb3da51bea9592c2114a0ccedc9485..844835d32464415b04b2c209b93ceb056a6fbfa8 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Add to `_config.yml`: pandoc: skip: false + impose: false output: ./tmp flags: '--smart --bibliography=ref.bib' site_flags: '--toc' @@ -43,6 +44,8 @@ regular jekyll site build. * `outputs` is a hash of output formats (even markdown!). You can add output-specific flags. +* `impose` creates ready to print PDFs if you're creating PDF output. + **IMPORTANT**: If you were using this plugin before 2013-07-17 you have to change your _config.yml syntax, change pandoc.outputs from array to hashes (see the example :) diff --git a/bin/imponer b/bin/imponer new file mode 100755 index 0000000000000000000000000000000000000000..0d5493a2d12475b07d12f97e3fa3c0174bd80cd9 --- /dev/null +++ b/bin/imponer @@ -0,0 +1,39 @@ +#!/usr/bin/env ruby + +file = ARGV.first +exit if not File.exist? file + +# Los temporales tiene un sufijo -tmp +file_tmp = file.gsub(/\.pdf$/, '-tmp.pdf') +# Los definitivos -tmp-imposed +file_imp = file.gsub(/\.pdf$/, '-tmp-imposed.pdf') + +# Cantidad de páginas +pages = `pdfinfo '#{file}' | grep '^Pages:' | cut -d: -f2 | tr -d ' '`.to_i + +# Encontramos el múltiplo de 4 más cercano a la cantidad de páginas +pages4 = ((pages+3)/4)*4.to_i +# y luego el múltiplo de 4 más cercano al dividir la cantidad de páginas +# por dos (porque cada hoja tiene dos mitades del libro) +pages8 = ((pages4/2+3)/4*4).to_i + +# Creamos la imposición de páginas para A5 +`pdfjam --vanilla \ + --outfile "#{File.dirname file}" \ + --paper a5paper \ + --suffix tmp \ + --landscape \ + --signature #{pages4} \ + "#{file}"` + +# Y luego lo dividimos por la mitad y hacemos 2x2 en A4 +`pdfjam --vanilla \ + --outfile "#{File.dirname file}" \ + --paper a4paper \ + --suffix imposed \ + --no-landscape \ + --signature #{pages8} \ + "#{file_tmp}"` + +`rm -v "#{file_tmp}"` +`mv -v "#{file_imp}" "#{file_imp.gsub /-tmp/, ''}"` diff --git a/lib/jekyll-pandoc-multiple-formats.rb b/lib/jekyll-pandoc-multiple-formats.rb index c76f112d9c127482f1df13bb61d52ba44af67cb7..343e1d0861498ace2d4becc7cb092c6cbd8ab3e1 100644 --- a/lib/jekyll-pandoc-multiple-formats.rb +++ b/lib/jekyll-pandoc-multiple-formats.rb @@ -14,7 +14,7 @@ class PandocGenerator < Generator next if site.config['pandoc']['skip'] # If there isn't a config entry for pandoc's output throw it with the rest - base_dir = site.config['pandoc']['output'] || site.source + base_dir = File.join(site.source, site.config['pandoc']['output']) || site.source site.posts.each do |post| @@ -42,7 +42,8 @@ class PandocGenerator < Generator end # The command - pandoc = "pandoc #{flags} #{output_flag} #{extra_flags}" + # Move to the source dir since everything will be relative to # that + pandoc = "pushd \"#{site.config['source']}\" >/dev/null; pandoc #{flags} #{output_flag} #{extra_flags}; popd >/dev/null" # Inform what's being done puts pandoc @@ -62,11 +63,21 @@ class PandocGenerator < Generator # Skip failed files next if not File.exist? filename_with_path + # If output is PDF, we also create the imposed PDF + if output == 'pdf' and site.config['pandoc']['impose'] + Open3::popen3("imponer '#{filename_with_path}'") do |stdin, stdout, stderr| + STDERR.print stderr.read + STDOUT.print stdout.read + end + + site.static_files << StaticFile.new(site, base_dir, output, filename.gsub(/\.pdf$/, '-imposed.pdf')) + end + # Add them to the static files list site.static_files << StaticFile.new(site, base_dir, output, filename) end end - end + end end end @@ -97,7 +108,7 @@ module JekyllPandocMultipleFormats flags = "#{@config['pandoc']['flags']} #{@config['pandoc']['site_flags']}" output = '' - Open3::popen3("pandoc -t html5 #{flags}") do |stdin, stdout, stderr| + Open3::popen3("pushd \"#{@config['source']}\" >/dev/null; pandoc -t html5 #{flags}; popd >/dev/null") do |stdin, stdout, stderr| stdin.puts content stdin.close diff --git a/lib/jekyll-pandoc-multiple-formats/version.rb b/lib/jekyll-pandoc-multiple-formats/version.rb index 4ef8299e59e0574dfa9134db18c814207e5bcd0a..fedb2ef8dd7c619fb12351cde6c297aab4948164 100644 --- a/lib/jekyll-pandoc-multiple-formats/version.rb +++ b/lib/jekyll-pandoc-multiple-formats/version.rb @@ -1,3 +1,3 @@ module JekyllPandocMultipleFormats - VERSION = "0.0.5" + VERSION = "0.0.6" end