Browse Source

fix: bring back photo log header

Lukasz Badura 5 months ago
parent
commit
483e376df9
3 changed files with 17 additions and 13 deletions
  1. 12 6
      lib/fotos/html_generator.rb
  2. 4 6
      lib/fotos/thumbnail.rb
  3. 1 1
      templates/_month.html.erb

+ 12 - 6
lib/fotos/html_generator.rb

@@ -7,43 +7,49 @@ module Fotos
 
     def initialize(options)
       @source_dir = Fotos::SourceDirectory.new(options[:source])
+      @dest_dir = Fotos::SourceDirectory.new(options[:dest])
       @generate_thumbnails = options[:thumbnails]
     end
 
     def call
+      html_output = []
+      html_output << render_period(@source_dir.dates)
       @source_dir.files_by_date.each do |date, assets|
-        puts "<h2 id=\"#{date}\">#{date} <small><a href=\"#toc\">top</a></small></h2>"
+        html_output << "<h2 id=\"#{date}\">#{date} <small><a href=\"#toc\">top</a></small></h2>"
         assets.reject(&:is_thumbnail?).each do |asset|
           if File.exist?(asset.thumbnail_path)
-            puts "<a href=\"#{asset.path}\"><img src=\"#{asset.thumbnail_path}\" /></a>"
+            html_output << "<a href=\"#{asset.path}\"><img src=\"#{asset.thumbnail_path}\" /></a>"
           else
             if @generate_thumbnails
               Fotos::Thumbnail.new(asset).create
               redo
             end
-            puts "<a href=\"#{asset.dirname}/#{asset.file_name}\"><img src=\"#{asset.path}\" /></a>"
+            html_output << "<a href=\"#{asset.dirname}/#{asset.file_name}\"><img src=\"#{asset.path}\" /></a>"
           end
         end
       end
 
-      render_template('footer')
+      html_output << render_template('footer')
+      puts html_output.join("\n")
     end
 
     private
     def render_period(dates)
+      output = []
       dates.group_by(&:year).each do |year, y_dates|
         puts "<h2>#{year}</h2>"
         y_dates.group_by(&:month).each do |month, m_dates|
           month_name = MONTHS[month - 1]
-          render_template('month', month: month_name, m_dates: m_dates)
+          output << render_template('month', month: month_name, m_dates: m_dates)
         end
       end
+      output.join("\n")
     end
 
     def render_template(name, context = {})
       path = Pathname.new(__FILE__).join('..', '..', '..', 'templates', "_#{name}.html.erb")
       template = ERB.new(File.read(path))
-      puts template.result_with_hash(context)
+      template.result_with_hash(context)
     end
 
   end

+ 4 - 6
lib/fotos/thumbnail.rb

@@ -6,12 +6,10 @@ module Fotos
     end
 
     def create
-      if File.exist?(@asset.thumbnail_path)
-      else
-        ImageScience.with_image(@asset.file_path) do |img|
-          img.thumbnail(250) do |thumb|
-            thumb.save(@asset.thumbnail_path)
-          end
+      return if File.exist?(@asset.thumbnail_path)
+      ImageScience.with_image(@asset.file_path) do |img|
+        img.thumbnail(250) do |thumb|
+          thumb.save(@asset.thumbnail_path)
         end
       end
     end

+ 1 - 1
templates/_month.html.erb

@@ -1,7 +1,7 @@
 <div>
   <p><%= month %>:
     <% m_dates.each do |d| %>
-      <a href="#<%= d.strftime(DATE_FORMAT) %>"><%= d.strftime('%d.%m') %></a>
+      <a href="#<%= d.strftime(Fotos::DATE_FORMAT) %>"><%= d.strftime('%d.%m') %></a>
     <% end %>
   </p>
 </div>