From 79b577b42f316eddc71e029e01417a3bdd43e86c Mon Sep 17 00:00:00 2001
From: fauno <fauno@endefensadelsl.org>
Date: Wed, 21 Feb 2018 14:57:09 -0300
Subject: [PATCH] localized covers_dir and better error reporting

---
 README.md                                     |  5 +++-
 .../pandoc_file.rb                            | 23 +++++++++++++++----
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index 492099a..7a21854 100644
--- a/README.md
+++ b/README.md
@@ -87,7 +87,10 @@ regular jekyll site build.
 * `sheetsize` is the page size for ready the print PDF.  You can also
   use this option on the front matter.
 
-* `covers_dir` the directory where covers are stored
+* `covers_dir` the directory where covers are stored.  If you have a
+  `lang` defined, it will append the language to the `covers_dir` when
+  looking for a category/full site cover, so you can have localized
+  covers.
 
 * `signature` is the amount of pages per fold on the imposition version.
   Specify `0` for a single fold of all the pages.  You can also use this
diff --git a/lib/jekyll-pandoc-multiple-formats/pandoc_file.rb b/lib/jekyll-pandoc-multiple-formats/pandoc_file.rb
index aefcbd6..a320c44 100644
--- a/lib/jekyll-pandoc-multiple-formats/pandoc_file.rb
+++ b/lib/jekyll-pandoc-multiple-formats/pandoc_file.rb
@@ -186,8 +186,8 @@ module Jekyll
       # Move to the source dir since everything will be relative to that
       Dir::chdir(@site.config['source']) do
         # Do the stuff
-        puts command
-        Open3::popen3(command) do |stdin, stdout, stderr, thread|
+        Jekyll.logger.debug command
+        e = Open3::popen3(command) do |stdin, stdout, stderr, thread|
           stdin.puts yaml_metadata
           stdin.puts content
           stdin.close
@@ -196,6 +196,8 @@ module Jekyll
           # Wait for the process to finish
           thread.value
         end
+
+        Jekyll.logger.warn 'Pandoc:', "Failed generating #{path}" if e.to_i > 0
       end
 
       File.exists?(path)
@@ -205,11 +207,19 @@ module Jekyll
     #
     # It assumes covers are in PNG format
     def cover
+      cover_path = [ @site.config['source'] ]
       if single_post? && single_post.data['cover']
-        File.join(@site.config['source'], single_post.data['cover'])
+        cover_path << single_post.data['cover']
+      elsif site_lang?
+        cover_path << @config['covers_dir']
+        cover_path << site_lang
+        cover_path << "#{@slug}.png"
       else
-        File.join(@site.config['source'], @config['covers_dir'], "#{@slug}.png")
+        cover_path << @config['covers_dir']
+        cover_path << "#{@slug}.png"
       end
+
+      File.join(cover_path)
     end
 
     # Returns a PDF cover
@@ -296,7 +306,10 @@ module Jekyll
     end
 
     def has_cover?
-      File.exists? cover
+      e = File.exists? cover
+      Jekyll.logger.warn "Cover:", "#{cover} missing for #{relative_path}" unless e
+
+      e
     end
 
     def papersize
-- 
GitLab