generate a .htaccess file specifying the UTF-8 charset to try to workaround badly...
[booh] / bin / booh-backend
index a0045801ce626f02108fdbdb9322b566bf17b532..254a4672f21141468179fa6f8e42104208adb9d0 100755 (executable)
@@ -232,8 +232,8 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
     end
 
     if !$source && $xmldoc
-        $source = from_utf8($xmldoc.root.attributes['source'])
-        $dest = from_utf8($xmldoc.root.attributes['destination'])
+        $source = from_utf8($xmldoc.root.attributes['source']).sub(%r|/$|, '')
+        $dest = from_utf8($xmldoc.root.attributes['destination']).sub(%r|/$|, '')
         $theme ||= $xmldoc.root.attributes['theme']
         $limit_sizes ||= $xmldoc.root.attributes['limit-sizes']
         if $mode == 'use_config' || $mode =~ /^merge_config/
@@ -729,6 +729,17 @@ def walk_source_dir
 
         system("mkdir -p '#{dest_dir}'")
 
+        #- generate .htaccess file
+        if !$forgui
+            ios = File.open("#{dest_dir}/.htaccess", "w")
+            ios.write("AddCharset UTF-8 .html\n")
+            if auth_user_file = xmldir.attributes['password-protect']
+                msg 3, _("\tgenerating password protection file #{dest_dir}/.htaccess")
+                ios.write("AuthType Basic\nAuthName \"protected area\"\nAuthUserFile #{auth_user_file}\nrequire valid-user\n")
+            end
+            ios.close
+        end
+
         #- pass through if there are no images and videos
         if images.size == 0 && videos.size == 0
             if !$forgui
@@ -736,7 +747,7 @@ def walk_source_dir
                 themestuff = Dir.entries("#{$FPATH}/themes/#{$theme}").
                                 find_all { |e| !%w(. .. skeleton_image.html skeleton_thumbnails.html skeleton_index.html metadata CVS).include?(e) }
                 if $mode != 'gen_config'
-                    rightful_images = []
+                    rightful_images = [ '.htaccess' ]
                     if xmldir.attributes['thumbnails-caption']
                         rightful_images << 'thumbnails-thumbnail.jpg'
                     end
@@ -863,7 +874,8 @@ def walk_source_dir
             all_elements = fullscreen_images.collect { |e| e[1] }.flatten.
                      concat(thumbnail_images.collect { |e| e[1] }.flatten).
                      concat(thumbnail_videos.collect { |e| e[1] }.flatten).
-                     concat(videos)
+                     concat(videos).
+                     push('.htaccess')
             to_del = Dir.entries(dest_dir).find_all { |e| !File.directory?("#{dest_dir}/#{e}") && !all_elements.include?(e) && e !~ /^thumbnails-\w+\.jpg/ } - themestuff
             if to_del.size > 0
                 msg 3, _("\tcleaning up: #{to_del.join(', ')}")
@@ -877,14 +889,6 @@ def walk_source_dir
                 end
             }
 
-            #- generate .htaccess file if needed
-            if auth_user_file = xmldir.attributes['password-protect']
-                msg 3, _("\tgenerating password protection file #{dest_dir}/.htaccess")
-                ios = File.open("#{dest_dir}/.htaccess", "w")
-                ios.write("AuthType Basic\nAuthName \"protected area\"\nAuthUserFile #{auth_user_file}\nrequire valid-user\n")
-                ios.close
-            end
-
             msg 3, _("\tgenerating HTML pages...")
 
             #- generate thumbnails.html (page with thumbnails)