summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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