Browse Source

feat: optionally generate thumbnails

Lukasz Badura 5 months ago
parent
commit
e51207f1d0
2 changed files with 6 additions and 0 deletions
  1. 1 0
      bin/fotos
  2. 5 0
      lib/fotos/html_generator.rb

+ 1 - 0
bin/fotos

@@ -15,6 +15,7 @@ when 'extract'
 when 'build'
   parser.on('-s [PATH]', '--source', 'Input directory with image directories')
   parser.on('-d [PATH]', '--dest', 'Output directory for html and images')
+  parser.on('-t', '--thumbnails', 'Automatically generate missing thumbnails')
   options = {dest: '.'}
   parser.parse!(into: options)
   Fotos::HtmlGenerator.new(options).call

+ 5 - 0
lib/fotos/html_generator.rb

@@ -7,6 +7,7 @@ module Fotos
 
     def initialize(options)
       @source_dir = Fotos::SourceDirectory.new(options[:source])
+      @generate_thumbnails = options[:thumbnails]
     end
 
     def call
@@ -16,6 +17,10 @@ module Fotos
           if File.exist?(file.thumbnail_path)
             puts "<a href=\"#{file.dir_name}/#{file.file_name}\"><img src=\"#{file.thumbnail_path}\" /></a>"
           else
+            if @generate_thumbnails
+              Fotos::Thumbnail.new(file.file_path).create
+              redo
+            end
             puts "<a href=\"#{file.dir_name}/#{file.file_name}\"><img src=\"#{file.file_path}\" /></a>"
           end
         end