]> git.draconx.ca Git - homepage.git/commitdiff
Compress all output files for a rep.
authorNick Bowler <nbowler@draconx.ca>
Sun, 3 Apr 2022 01:41:21 +0000 (21:41 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sun, 3 Apr 2022 01:41:21 +0000 (21:41 -0400)
An item rep may be written to multiple places, and currently only
one of them gets compressed by the gzip rule.

Unfortunately while nanoc maintains a complete output list internally,
it is not exposed in the documented API.  But it's not too hard to pull
out the guts and get the full list in order to compress everything.

Rules

diff --git a/Rules b/Rules
index 225615397cbbaf6eb696e07f4622179692543e10..365e83a6fcb3d31fa7c07bcb282de5896e837fcf 100644 (file)
--- a/Rules
+++ b/Rules
@@ -75,16 +75,17 @@ end
 
 postprocess do
     # Gzip all text items for nginx http_static
-    if !ENV['GZIP_SITE'].to_s.empty?
+    gzip_site = !ENV['GZIP_SITE'].to_s.empty?
+    if gzip_site
         reps = @items.flat_map(&:reps).each do |rep|
-            file = rep.raw_path
-            next if !file or rep.binary?
-
-            if system("gzip", "-ck9", file, [:out]=>[file + ".gz.tmp", "wb"])
-                system("touch", "-r", file, file + ".gz.tmp")
-                File.rename(file + ".gz.tmp", file + ".gz")
-            else
-                File.unlink(file + ".gz.tmp")
+            next if rep.binary?
+            rep.instance_variable_get(:@item_rep).raw_paths[:last].each do |f|
+                if system("gzip", "-nck9", f, [:out]=>["#{f}.gz.tmp", "wb"])
+                    system("touch", "-r", f, "#{f}.gz.tmp")
+                    File.rename("#{f}.gz.tmp", "#{f}.gz")
+                else
+                    File.unlink("#{f}.gz.tmp")
+                end
             end
         end
     end
@@ -222,8 +223,8 @@ end
 compile '/gpg/*' do
     filter :wkd_export_armor
     write "/pubring/#{@item.identifier.components.last}.asc"
-    write "/pubring/#{@item[:id64]}.asc" if item[:id64]
-    write "/pubring/#{@item[:id32]}.asc" if item[:id32]
+    write "/pubring/#{@item[:id64]}.asc" if @item[:id64]
+    write "/pubring/#{@item[:id32]}.asc" if @item[:id32]
 end
 
 compile '/gpg/*', rep: :hu do
@@ -232,9 +233,7 @@ compile '/gpg/*', rep: :hu do
         write "/pubring/wkd/" + @item[:wkd_hash]
     end
 end
-
-compile '/*.gpg' do
-end
+ignore '/*.gpg'
 
 compile '/**/*.svg' do
     filter :scour, comment_stripping: true