diff options
Diffstat (limited to 'helpers.rb')
-rw-r--r-- | helpers.rb | 64 |
1 files changed, 64 insertions, 0 deletions
@@ -215,4 +215,68 @@ helpers do return [file, object] if object['id'] == id end end + + def outbox_html(activity) + html = File.read('/home/ch/src/publish/html/head.html') + html += '<nav>' + html += "<a id='logo' href='/about.html'><img src='/pdp8.png' alt='pdp8'></a>" + %w[music pictures videos climbing code contact].each do |c| + html += " <a class='item' href='/#{c}.html'>#{c}</a>" + end + html += " <a class='item current' href='/social/create.html'>social</a>" + html += " <a class='item' href='/rss.xml'>rss</a>" + html += " <a id='menu' href='#' onclick='show_vertical_menu()'>≡</a>" + html += "</nav><div class='post'><h1><a href='https://social.pdp8.info/pdp8'>@pdp8@social.pdp8.info</a></h1><h2>" + html += if activity == 'create' + "posts | <a href='/social/announce.html'>boosts</a>" + elsif activity == 'announce' + "<a href='/social/create.html'>posts</a> | boosts" + end + html += '</h2></div>' + Dir[File.join(SOCIAL_DIR, 'outbox', activity, '*.json')].collect do |f| + 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(',') + end + html += "<br><video width='#{w}' height='#{h}' controls><source src='#{att['url']}' type='#{att['mediaType']}'></video>" + end + end + end + html += '</div>' + end + html += File.read('/home/ch/src/publish/html/tail.html') + %w[pdp8 pdp8-test].each do |d| + outdir = "/srv/www/#{d}/social" + out = File.join(outdir, activity + '.html') + File.open(out, 'w+') { |f| f.puts(html) } + puts `/etc/profiles/per-user/ch/bin/tidy -iqm -w 0 #{out} 2>&1` + end + end end |