Skip to content
Snippets Groups Projects
Commit abac1ec6 authored by fauno's avatar fauno
Browse files

Merge branch 'release/0.0.6'

parents a238e6ea e50a0b47
No related branches found
No related tags found
No related merge requests found
......@@ -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 :)
......
#!/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/, ''}"`
......@@ -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,6 +63,16 @@ 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
......@@ -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
......
module JekyllPandocMultipleFormats
VERSION = "0.0.5"
VERSION = "0.0.6"
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment