Class: PDFThumbnail::Generator
- Inherits:
-
Jekyll::Generator
- Object
- Jekyll::Generator
- PDFThumbnail::Generator
- Includes:
- PDFThumbnail
- Defined in:
- lib/jekyll-pdf-thumbnail.rb
Overview
The PDF thumbnail generator
Constant Summary
Constants included from PDFThumbnail
Instance Method Summary collapse
Methods included from PDFThumbnail
#_dest_filename, #_must_create?
Instance Method Details
#generate(site) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jekyll-pdf-thumbnail.rb', line 34 def generate(site) # Ensure the cache dir exists full_cache_path = File.join(site.source, CACHE_DIR) FileUtils.mkdir_p(full_cache_path) site.static_files.each do |static_file| if static_file.extname.downcase == ".pdf" full_pdf_path = File.join(site.source, static_file.relative_path) thumb = _dest_filename(full_pdf_path) full_thumb_path = File.join(full_cache_path, thumb) rel_thumb_path = File.join(CACHE_DIR, thumb) if _must_create?(full_pdf_path, full_thumb_path) puts "Creating thumbnail of' #{static_file.relative_path}' to '#{rel_thumb_path}'" PDFToImage.open(full_pdf_path).first.resize('50%').save(full_thumb_path) site.static_files << Jekyll::StaticFile.new(site, site.source, CACHE_DIR, thumb) end end end end |