summary refs log tree commit diff
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2024-02-12 23:34:55 +0100
committerpdp8 <pdp8@pdp8.info>2024-02-12 23:34:55 +0100
commita0512473ec1c19643dae4889a321602901df79bc (patch)
tree7d9d25eada04e0cf1d81b27ac6049e72f7801d6c
parente4e4dedf8ca423e110787657799137444ca0f8fe (diff)
omit empty objects in outbox
-rw-r--r--helpers.rb58
1 files changed, 30 insertions, 28 deletions
diff --git a/helpers.rb b/helpers.rb
index 4bce51f..7126160 100644
--- a/helpers.rb
+++ b/helpers.rb
@@ -237,35 +237,37 @@ helpers do
       JSON.load_file(f)
     end.select { |a| a['to'].include?('https://www.w3.org/ns/activitystreams#Public') }.sort_by { |a| a['published'] }.reverse.collect { |a| a['object'] }.each do |object|
       object = fetch(object) if object.is_a? String
-      mention = mention object['attributedTo']
-      html += "<div class='post'>"
-      if activity == 'announce'
-        html += "<b><a href='#{object['attributedTo']}' target='_blank'>#{mention}</a></b>&nbsp;"
-      end
-      html += "<em>#{object['published']}</em>
-          #{object['content']}"
-      if object['attachment']
-        object['attachment'].each do |att|
-          w = 1024
-          h = 768
-          case att['mediaType']
-          when /audio/
-            html += "<br><audio controls><source src='#{att['url']}' type='#{att['mediaType']}'></audio>"
-          when /image/
-            if activity == 'create'
-              w, h = `/etc/profiles/per-user/ch/bin/identify -format "%w %h" #{att['url'].sub(
-                'https://media.pdp8.info', '/srv/media'
-              )}`.chomp.split(' ') end
-            html += "<br><a href='#{att['url']}'><img loading='lazy' width='#{w}' height='#{h}' "
-            alt = att['name'] ? att['name'].gsub("'", '&apos;').gsub('"', '&quot;') : ''
-            html += "alt='#{alt}' src='#{att['url']}'></a>"
-          when /video/
-            if activity == 'create'
-              w, h = `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 #{att['url'].sub(
-                'https://media.pdp8.info', '/srv/media'
-              )}`.chomp.split(',')
+      if object
+        mention = mention object['attributedTo']
+        html += "<div class='post'>"
+        if activity == 'announce'
+          html += "<b><a href='#{object['attributedTo']}' target='_blank'>#{mention}</a></b>&nbsp;"
+        end
+        html += "<em>#{object['published']}</em>
+            #{object['content']}"
+        if object['attachment']
+          object['attachment'].each do |att|
+            w = 1024
+            h = 768
+            case att['mediaType']
+            when /audio/
+              html += "<br><audio controls><source src='#{att['url']}' type='#{att['mediaType']}'></audio>"
+            when /image/
+              if activity == 'create'
+                w, h = `/etc/profiles/per-user/ch/bin/identify -format "%w %h" #{att['url'].sub(
+                  'https://media.pdp8.info', '/srv/media'
+                )}`.chomp.split(' ') end
+              html += "<br><a href='#{att['url']}'><img loading='lazy' width='#{w}' height='#{h}' "
+              alt = att['name'] ? att['name'].gsub("'", '&apos;').gsub('"', '&quot;') : ''
+              html += "alt='#{alt}' src='#{att['url']}'></a>"
+            when /video/
+              if activity == 'create'
+                w, h = `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 #{att['url'].sub(
+                  'https://media.pdp8.info', '/srv/media'
+                )}`.chomp.split(',')
+              end
+              html += "<br><video width='#{w}' height='#{h}' controls><source src='#{att['url']}' type='#{att['mediaType']}'></video>"
             end
-            html += "<br><video width='#{w}' height='#{h}' controls><source src='#{att['url']}' type='#{att['mediaType']}'></video>"
           end
         end
       end