diff options
Diffstat (limited to 'helpers.rb')
-rw-r--r-- | helpers.rb | 58 |
1 files changed, 30 insertions, 28 deletions
@@ -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> " - 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("'", ''').gsub('"', '"') : '' - 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> " + 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("'", ''').gsub('"', '"') : '' + 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 |