Module: PDFThumbnail

Included in:
Filters, Generator
Defined in:
lib/jekyll-pdf-thumbnail.rb

Defined Under Namespace

Modules: Filters Classes: Generator

Constant Summary collapse

CACHE_DIR =
"/assets/pdf_thumbnails/"
HASH_LENGTH =
32

Instance Method Summary collapse

Instance Method Details

#_dest_filename(src_path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jekyll-pdf-thumbnail.rb', line 11

def _dest_filename(src_path)
  # Generates a thumbnail name using the SHA256 digest of the PDF file
  #
  # Example:
  #   >> _dest_filename("sample_1.pdf")
  #   => a35383ccca791ba6aa67ab3acde65287.png
  #
  # Arguments:
  #   src_path: (String)
  hash = Digest::SHA256.file(src_path)
  short_hash = hash.hexdigest()[0, HASH_LENGTH]
  "#{short_hash}.png"
end

#_must_create?(src_path, dest_path) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/jekyll-pdf-thumbnail.rb', line 25

def _must_create?(src_path, dest_path)
  # Returns true if dest_path doesn't exists or src_path is newer than dest_path
  !File.exist?(dest_path) || File.mtime(dest_path) <= File.mtime(src_path)
end