futurist-fieldguide/doku2tex.rb

49 lines
1.3 KiB
Ruby
Raw Normal View History

2015-06-17 13:20:41 +00:00
#!/usr/local/bin/ruby
#
# dokuwiki -> pdf conversion for futurist fieldguide
require "slop"
opts = Slop.parse do |o|
o.string '-f','--file', 'source file basename'
o.bool '-v', '--verbose', 'enable verbose mode'
o.bool '-g', '--git', 'commit new files to git repo'
end
repo="/home/nik/pandoc/futurist-fieldguide/"
doku="/var/www/libarynth/dokuwiki/data/pages/futurist_fieldguide/"
user="www-data"
#file=ARGV[0] # dokuwiki pagenme as argument (no opts)
file = opts[:file]
puts file
# parse dokuwiki -> html
`php /var/www/libarynth/dokuwiki/bin/dokucli.php < #{doku}/#{file}.txt > /tmp/#{file}.html`
# convert html -> pdf with pandoc
# extra html step to create self-contained (local) images
`pandoc /tmp/#{file}.html --self-contained -o /tmp/#{file}.html`
`pandoc /tmp/#{file}.html -S --template=#{repo}/pandoc/templates/fieldguide.tex \
--include-in-header=#{repo}/pandoc/header.tex \
--metadata=title-meta:#{file} \
--latex-engine=xelatex -o #{repo}/print/#{file}.tex`
# merge single pdfs with 'assemble.rb'
# gittery
# - assuming the script is run in #{repo} and has origin ssh://git@repo.fo.am:foam/futurist-fieldguide.git
# - otherwise perhaps https://github.com/schacon/ruby-git
if opts.git?
`git add -A`
`git commit -m "#{file}"`
`git pull --commit`
`git push`
end