summaryrefslogtreecommitdiff
path: root/pictures.rb
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2024-03-04 23:13:40 +0100
committerpdp8 <pdp8@pdp8.info>2024-03-04 23:13:40 +0100
commit0555b2cd77986d916968f1443e375fad005c8d43 (patch)
tree84112db3509f5d9b40fe41abd14fa6bc1c41303d /pictures.rb
parent6b40f3b54efabb740e825ba3d94b5695c2b98ede (diff)
html.rb separated, Makefile for website generation
Diffstat (limited to 'pictures.rb')
-rwxr-xr-xpictures.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/pictures.rb b/pictures.rb
new file mode 100755
index 0000000..e21cb9b
--- /dev/null
+++ b/pictures.rb
@@ -0,0 +1,33 @@
+#!/usr/bin/env ruby
+require 'json'
+require_relative 'lib'
+
+PICTURE_URL = 'https://media.pdp8.info/pictures'
+PICTURE_PATH = '/srv/media/pictures'
+
+html = File.read(File.join(SNIPPETS, 'head.html'))
+html += nav 'pictures'
+
+posts = Dir[File.join('/srv', 'social', 'outbox', 'create', '*.json')].collect { |f| JSON.load_file(f) }.select do |a|
+ a['to'].include?('https://www.w3.org/ns/activitystreams#Public') and a['object']['attachment']
+end.collect { |a| a['object'] }.select { |o| o['attachment'].size == 1 and o['attachment'][0]['mediaType'].match(/image/) }
+
+posts.sort_by { |o| o['published'] }.reverse.each do |object|
+ att = object['attachment'][0]
+ url = att['url']
+ basename = File.basename(url, File.extname(url))
+ next if basename == 'cover'
+
+ www_path = File.join(PICTURE_PATH, 'www', basename + '.webp')
+ www_url = File.join(PICTURE_URL, 'www', basename + '.webp')
+ alt = att['name'] ? att['name'].gsub("'", '&apos;').gsub('"', '&quot;') : ''
+ src_url = File.join(PICTURE_URL, basename + File.extname(url))
+ w, h = `/etc/profiles/per-user/ch/bin/identify -format "%w %h" #{www_path}`.chomp.split(' ')
+ html += "<div class='post'>"
+ html += "<a href='#{src_url}'><img loading='lazy' width='#{w}' height='#{h}' "
+ html += "alt='#{alt}' src='#{www_url}'></a>"
+ html += '</div>'
+end
+
+html += File.read(File.join(SNIPPETS, 'tail.html'))
+print_html 'pictures', html