1
votes

I would like to write a Jekyll plugin that makes all posts available in PDF format by utilizing Kramdown's LaTeX export capabilities. For each post in Markdown format, I'd like to end up with the normal .html post along with a .tex file containing the LaTeX markup and finally a .pdf.

Following the documentation for creating plugins, I see two ways of approaching the problem, either with a Converter or with a Generator.

Converter plugins seem to run after the built-in Converters, so the .markdown files have all been converted to .html by the time they reach the Converter.

When I try to implement a Generator, I am able to use fileutils to write a file successfully, but by the end of Jekyll's cycle, that file has been removed. It seems there's a StaticFile class which you can use to register new output files with Jekyll, but I cannot find any real guidance on how to use it.

2

2 Answers

1
votes

If you take a look at the ThumbGenerator class in this: https://github.com/matthewowen/jekyll-slideshow/blob/master/_plugins/jekyll_slideshow.rb you'll seen a similar example. This particular plugin makes thumbnail sized versions of all images in the site. Hopefully it gives a useful guide to how you can interact with Jekyll's StaticFile class (though I'm not a Ruby pro, so forgive any poor style).

Unfortunately, there isn't really documentation for this - I gleaned it from reading through the source.

I wrote this a few months ago and don't particularly remember the details (which is why I gave an example rather than a workthrough), but if this doesn't get you on the right track let me know and I'll try to help.

0
votes

I try to do the same but with direct html->pdf conversion. It did not work inside a gitlab-ci pipeline at this time, nonetheless it work on my workstation (see here) with a third possibility : a hook !

(here with pdfkit)

require 'pdfkit'

module Jekyll

  Jekyll::Hooks.register :site, :post_write do |post|

      post.posts.docs.each do |post|
          filename = post.site.dest + post.id + ".pdf"
          dirname = File.dirname(filename)
          Dir.mkdir(dirname) unless File.exists?(dirname)

          kit = PDFKit.new(post.content, :page_size => 'Letter')
          kit.stylesheets << './css/bootstrap.min.css'
          kit.to_file(filename)
      end
  end

end