summaryrefslogtreecommitdiff
path: root/helpers.rb
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2024-02-10 00:09:34 +0100
committerpdp8 <pdp8@pdp8.info>2024-02-10 00:09:34 +0100
commite4e4dedf8ca423e110787657799137444ca0f8fe (patch)
treed3bd95af4c58e76ca97b961f6e03e28376d8d6bb /helpers.rb
parent4586c63bd86fe3dad403086b15d5b74b6d67fc92 (diff)
outbox moved to website
Diffstat (limited to 'helpers.rb')
-rw-r--r--helpers.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/helpers.rb b/helpers.rb
index 292c71d..4bce51f 100644
--- a/helpers.rb
+++ b/helpers.rb
@@ -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 += "&nbsp;<a class='item' href='/#{c}.html'>#{c}</a>"
+ end
+ html += "&nbsp;<a class='item current' href='/social/create.html'>social</a>"
+ html += "&nbsp;<a class='item' href='/rss.xml'>rss</a>"
+ html += "&nbsp;<a id='menu' href='#' onclick='show_vertical_menu()'>&equiv;</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&nbsp;|&nbsp;<a href='/social/announce.html'>boosts</a>"
+ elsif activity == 'announce'
+ "<a href='/social/create.html'>posts</a>&nbsp;|&nbsp;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>&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
+ 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