summaryrefslogtreecommitdiff
path: root/pictures.rb
diff options
context:
space:
mode:
Diffstat (limited to 'pictures.rb')
-rwxr-xr-xpictures.rb40
1 files changed, 22 insertions, 18 deletions
diff --git a/pictures.rb b/pictures.rb
index e21cb9b..33c7ec6 100755
--- a/pictures.rb
+++ b/pictures.rb
@@ -2,30 +2,34 @@
require 'json'
require_relative 'lib'
-PICTURE_URL = 'https://media.pdp8.info/pictures'
PICTURE_PATH = '/srv/media/pictures'
+WEBP_PATH = File.join PICTURE_PATH, 'webp'
+TXT_PATH = File.join PICTURE_PATH, 'txt'
-html = File.read(File.join(SNIPPETS, 'head.html'))
-html += nav 'pictures'
+COLLECTION_PATH = File.join PICTURE_PATH, 'collections'
-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/) }
+PICTURE_URL = 'https://media.pdp8.info/pictures'
+WEBP_URL = File.join PICTURE_URL, 'webp'
+JPEG_URL = File.join PICTURE_URL, 'jpeg'
-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'
+html = File.read(File.join(SNIPPETS, 'head.html'))
+html += nav 'pictures'
- www_path = File.join(PICTURE_PATH, 'www', basename + '.webp')
- www_url = File.join(PICTURE_URL, 'www', basename + '.webp')
- alt = att['name'] ? att['name'].gsub("'", ''').gsub('"', '"') : ''
- 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(' ')
+Dir[File.join COLLECTION_PATH, '*']
+ .sort_by { |c| File.mtime c }
+ .reverse.each do |collection|
html += "<div class='post'>"
- html += "<a href='#{src_url}'><img loading='lazy' width='#{w}' height='#{h}' "
- html += "alt='#{alt}' src='#{www_url}'></a>"
+ html += "<h1>#{collection.gsub('_', ' ')}</h1>\n"
+ File.readlines(collection, chomp: true).each do |line|
+ basename = File.basename(line, File.extname(line))
+ path = File.join(WEBP_PATH, basename + '.webp')
+ url = File.join(WEBP_URL, basename + '.webp')
+ alt = File.read(File.join(TXT_PATH, basename, '.txt'))
+ src = File.join(JPEG_URL, basename + File.extname(url))
+ w, h = `/etc/profiles/per-user/ch/bin/identify -format "%w %h" #{path}`.chomp.split(' ')
+ html += "<a href='#{src}'><img loading='lazy' width='#{w}' height='#{h}' "
+ html += "alt='#{alt}' src='#{url}'></a>"
+ end
html += '</div>'
end