]> git.draconx.ca Git - homepage.git/blobdiff - Rules
Ensure ASCII-armoured keyrings are text items.
[homepage.git] / Rules
diff --git a/Rules b/Rules
index f3f1f0a197c6f67c3dec7d13a593beef126cf1da..c753c3867415af50d3e5ffc6eb3049e9b7a47d5f 100644 (file)
--- a/Rules
+++ b/Rules
@@ -1,6 +1,6 @@
 #!/usr/bin/env ruby
 #
-# Copyright © 2018-2020 Nick Bowler
+# Copyright © 2018-2022 Nick Bowler
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 preprocess do
+    system("git", "submodule", "update", "--init")
+
     # Remove dead annex keys from processing
     @items.delete_if do |item|
-      l = File.readlink(item.raw_filename)
-      true if !File.exists?(item.raw_filename) and l =~ %r{/annex/objects/}
+        l = File.readlink(item.raw_filename)
+        true if !File.exists?(item.raw_filename) and l =~ %r{/annex/objects/}
     rescue Errno::EINVAL
     end
 
@@ -36,6 +38,38 @@ preprocess do
             item[:gitrev] = commit if item_source(item)
         end
     end
+
+    @items.find_all('/weblog/*.md').each do |item|
+        item[:kind] ||= 'article'
+    end
+
+    @items.each do |item|
+        item[:created_at] ||=
+            item[:published] || File.stat(item.raw_filename).mtime
+        item[:updated_at] ||=
+            item[:updated] || File.stat(item.raw_filename).mtime
+    end
+
+    archivedirs = {}
+    @items.find_all('/archive/**/*').each do |item|
+        dir = File.dirname(item.identifier)
+        while dir != "/"
+            archivedirs[dir] = true
+            dir = File.dirname(dir)
+        end
+    end
+
+    archivedirs.keys.sort_by{ |s| -s.length }.each do |dir|
+        attrs = {
+            pattern: "#{dir}/*{,/index.lst}",
+            title: "Index of #{dir}",
+            gitrev: commit,
+        }
+
+        @items.create("", attrs, "#{dir}/index.lst")
+    end
+
+    create_wkd_items(@items["/pubring.gpg"])
 end
 
 postprocess do
@@ -56,8 +90,11 @@ postprocess do
 
     # Register URLs for git-annex keys
     unless (uribase = ENV['ANNEX_URI_BASE'].to_s.chomp("/")).empty?
-        Open3.popen2("git", "annex", "registerurl") do |stdin, stdout, result|
+        Open3.popen2("git", "-c", "core.bare=false", "annex", "registerurl") do
+        |stdin, stdout, result|
             @items.each do |item|
+                next if item.raw_filename.nil?
+
                 l = File.readlink(item.raw_filename)
                 next unless l =~ %r{/annex/objects/}
 
@@ -65,6 +102,7 @@ postprocess do
 
                 # Find output reps corresponding to this key, if any
                 item.reps.each do |rep|
+                    next if rep.raw_path.nil?
                     next unless
                         FileUtils.identical?(item.raw_filename, rep.raw_path)
 
@@ -93,6 +131,16 @@ postprocess do
     end
 end
 
+compile '/**/index.lst' do
+    layout '/listing.erb'
+    layout '/default.xml'
+    layout '/default.xsl'
+    layout '/embed-svg.xsl'
+    filter :relativize_paths, type: :xml
+    filter :xhtml_compat, fix_doctype: true
+    write item.identifier.without_ext + ".xhtml"
+end
+
 compile '/license/gpl*.md' do
     filter :kramdown, auto_ids: false, header_offset: -1
     layout '/default.xml'
@@ -100,7 +148,6 @@ compile '/license/gpl*.md' do
     layout '/default.xsl'
     filter :relativize_paths, type: :xml
     filter :xhtml_compat
-    filter :remove_wj
     write to_xhtml
 end
 
@@ -112,7 +159,6 @@ compile '/**/*.md' do
     layout '/default.xsl'
     filter :relativize_paths, type: :xml
     filter :xhtml_compat
-    filter :remove_wj
     write to_xhtml
 end
 
@@ -123,7 +169,6 @@ compile '/license/cc*.sgml' do
     layout '/default.xsl', "section-links": "yes"
     filter :relativize_paths, type: :xml
     filter :xhtml_compat
-    filter :remove_wj
     write to_xhtml
 end
 
@@ -133,13 +178,23 @@ compile '/license/cc*.xhtml' do
     layout '/default.xsl', "section-links": "yes"
     filter :relativize_paths, type: :xml
     filter :xhtml_compat
-    filter :remove_wj
     write to_xhtml
 end
 
 compile '/images/*.jpg', rep: :large do
-    filter :imgresize, width: 1200, height: 1200
-    write item.identifier.without_ext + '-t1200.' + item.identifier.ext
+    w, h = FastImage.size(item.raw_filename)
+    filename = item.identifier.without_ext + '-t1200.' + item.identifier.ext
+    filter :imgresize, width: [w, 1200].min, height: [h, 1200].min, cache: filename
+    write filename
+end
+
+compile '/images/*.jpg', rep: :medium do
+    w, h = FastImage.size(item.raw_filename)
+    filename = item.identifier.without_ext + '-t800.' + item.identifier.ext
+    if w > 900 or h > 900
+        filter :imgresize, width: 800, height: 800, cache: filename
+        write filename
+    end
 end
 
 compile '/images/*.jpg', rep: :info do
@@ -149,7 +204,6 @@ compile '/images/*.jpg', rep: :info do
     layout '/default.xsl'
     filter :relativize_paths, type: :xml
     filter :xhtml_compat
-    filter :remove_wj
     write to_xhtml
 end
 
@@ -164,9 +218,32 @@ compile '/**/*.scss' do
     write @item.identifier.without_ext + '.css'
 end
 
+compile '/gpg/*' do
+    filter :wkd_export_armor
+    write "/pubring/" + @item.identifier.components.last + ".asc"
+end
+
+compile '/gpg/*', rep: :hu do
+    filter :wkd_export
+    write "/pubring/wkd/" + @item[:wkd_hash]
+end
+
+compile '/*.gpg' do
+end
+
+compile '/**/*.svg' do
+    filter :scour, comment_stripping: true
+    write @item.identifier.to_s
+end
+
+compile '/icons/**/*.svg', rep: :icon32 do
+    filter :svg2png, width: 32, height: 32
+    write @item.identifier.without_ext + "-32.png"
+end
+
 compile '/**/*' do
-  filter :copybin if @item.binary?
-  write @item.identifier.to_s
+    filter :copybin if @item.binary?
+    write @item.identifier.to_s
 end
 
 layout '/**/*.xsl', :xsl