diff options
-rw-r--r-- | Makefile | 24 | ||||
-rw-r--r-- | html/style.css | 9 | ||||
-rwxr-xr-x | lib.rb | 2 | ||||
-rwxr-xr-x | pictures.rb | 89 | ||||
-rwxr-xr-x | rss.rb | 43 |
5 files changed, 57 insertions, 110 deletions
@@ -11,15 +11,15 @@ MP3 := $(subst flac,mp3, $(FLAC)) IMG_DIR := $(MEDIA_DIR)/pictures WEBP_DIR := $(IMG_DIR)/webp JPEG_DIR := $(IMG_DIR)/jpeg -THUMB_DIR := $(IMG_DIR)/thumb +# THUMB_DIR := $(IMG_DIR)/thumb TXT_DIR := $(IMG_DIR)/txt JPEG_IMG := $(wildcard $(JPEG_DIR)/*.jpeg) WEBP_IMG := $(subst jpeg,webp, $(JPEG_IMG)) -THUMB_IMG := $(addprefix $(THUMB_DIR)/, $(notdir $(WEBP_IMG))) +# THUMB_IMG := $(addprefix $(THUMB_DIR)/, $(notdir $(WEBP_IMG))) TXT_IMG := $(subst jpeg,txt, $(JPEG_IMG)) -IMG_ALBUMS := $(wildcard $(IMG_DIR)/albums/*) +# IMG_ALBUMS := $(wildcard $(IMG_DIR)/albums/*) VIDEO_DIR := /srv/media/videos VIDEO_WEBM := $(wildcard $(VIDEO_DIR)/*/*.webm) @@ -32,6 +32,9 @@ CLIMBING_WEBM := $(wildcard $(CLIMBING_DIR)/*/*.webm) CLIMBING_MP4 := $(subst webm,mp4, $(CLIMBING_WEBM)) CLIMBING_WEBP := $(subst webm,webp, $(CLIMBING_WEBM)) +OUTBOX_DIR:= /srv/social/outbox +SOCIAL_CREATE := $(subst :,\:,$(wildcard $(OUTBOX_DIR)/create/*.json)) # escape colons + HTML := index.html music.html pictures.html videos.html climbing.html about.html code.html contact.html OTHER := pdp8.png 540px-PDP-8_.jpg style.css sitemap.txt rss.xml @@ -44,18 +47,21 @@ all: test test: $(TEST_HTML) $(TEST_OTHER) -pictures: $(WEBP_IMG) $(THUMB_IMG) +pictures: $(WEBP_IMG) #$(THUMB_IMG) $(TEST_DIR)/rss.xml: $(TEST_HTML) ./rss.rb -$(TEST_DIR)/index.html: $(TEST_DIR)/music.html - cp $< $@ +$(TEST_DIR)/index.html: $(TEST_DIR)/pictures.html $(TEST_DIR)/music.html + cp `ls -t $^ | head -n1` $@ $(TEST_DIR)/music.html: $(MP3) ./music.rb -$(TEST_DIR)/pictures.html: $(IMG_ALBUMS) $(WEBP_IMG) $(THUMB_IMG) +# $(test_dir)/pictures.html: $(img_albums) $(webp_img) $(thumb_img) +# ./pictures.rb + +$(TEST_DIR)/pictures.html: $(SOCIAL_CREATE) ./pictures.rb $(TEST_DIR)/videos.html: $(VIDEO_MP4) $(VIDEO_WEBP) @@ -85,8 +91,8 @@ $(TEST_DIR)/%.txt: ./html/%.txt $(WEBP_DIR)/%.webp: $(JPEG_DIR)/%.jpeg magick $< -resize 1536x1024 -quality 85 $@ -$(THUMB_DIR)/%.webp: $(JPEG_DIR)/%.jpeg - magick $< -resize 150x100 -quality 85 $@ +# $(THUMB_DIR)/%.webp: $(JPEG_DIR)/%.jpeg +# magick $< -resize 150x100 -quality 85 $@ %.webp: %.webm ffmpeg -i $< -loglevel error -vf thumbnail -frames:v 1 -c:v png -f image2pipe - | magick - $@ diff --git a/html/style.css b/html/style.css index da1be1b..eda1548 100644 --- a/html/style.css +++ b/html/style.css @@ -73,7 +73,7 @@ td { img, video { max-height: 80vh; - max-width: 95vw; + max-width: 90vw; object-fit: contain; margin: 0 auto } @@ -100,12 +100,17 @@ footer { .gallery { display: flex; flex-wrap: wrap; + margin: 1em; } -.thumb { +.gallery img { margin: 0.25em; } +/* .thumb { */ +/* margin: 0.25em; */ +/* } */ + .cover { max-height: min(50vh, 90vw); max-width: min(50vh, 90vw); @@ -3,6 +3,8 @@ MEDIA_DIR = '/srv/media' MEDIA_URL = 'https://media.pdp8.info' WWW_DIR = '/srv/www/pdp8-test' +OUTBOX_DIR = '/srv/social/outbox' + SNIPPETS = File.join(File.dirname(__FILE__), 'html') def nav(cat) diff --git a/pictures.rb b/pictures.rb index 71b06d4..89b770c 100755 --- a/pictures.rb +++ b/pictures.rb @@ -1,82 +1,23 @@ #!/usr/bin/env ruby require_relative 'lib' -require 'fileutils' - -PICTURE_PATH = '/srv/media/pictures' -WEBP_PATH = File.join PICTURE_PATH, 'webp' -TXT_PATH = File.join PICTURE_PATH, 'txt' - -ALBUM_PATH = File.join PICTURE_PATH, 'albums' - -PICTURE_URL = File.join MEDIA_URL, 'pictures' -WEBP_URL = File.join PICTURE_URL, 'webp' -THUMB_URL = File.join PICTURE_URL, 'thumb' -JPEG_URL = File.join PICTURE_URL, 'jpeg' - -def meta(img, album) - basename = File.basename(img, File.extname(img)) - path = File.join(WEBP_PATH, basename + '.webp') - { - basename: basename, - webp: File.join(WEBP_URL, basename + '.webp'), - txt: File.join(TXT_PATH, basename + '.txt'), - src: File.join(JPEG_URL, basename + File.extname(img)), - thumb: File.join(THUMB_URL, basename + '.webp'), - href: File.join('/pictures', File.basename(album), - File.basename(img, File.extname(img)) + '.html') - } -end - -albums = Dir[File.join ALBUM_PATH, '*'].sort_by { |a| File.mtime a }.reverse - -albums.each do |album| - www_dir = File.join('/srv/www/pdp8-test/pictures', File.basename(album)) - FileUtils.mkdir_p www_dir - `cd /srv/www/pdp8-test/pictures; git add #{File.basename(album)}` - images = File.readlines(album, chomp: true) - n = images.size - images.each_with_index do |img, i| - before = meta(images[(i - 1) % n], album)[:href] - after = meta(images[(i + 1) % n], album)[:href] - meta = meta img, album - html = File.read(File.join(SNIPPETS, 'head.html')) - html += nav 'pictures' - html += "<div class='slide'>" - html += '<img ' - html += "alt='#{File.read(meta[:txt])}' " if File.exist?(meta[:txt]) - html += "src='#{meta[:webp]}'>" - html += "<div class='slidenav'>" - html += "<a href='#{before}' class='navarrow'>←</a>" - html += "<a href='/pictures.html##{File.basename(album)}'>back</a>" - html += "<a href='#{after}' class='navarrow'>→</a>" - html += '</div>' - html += '</div>' - html += File.read(File.join(SNIPPETS, 'tail.html')) - html_file = File.join(www_dir, File.basename(img, File.extname(img)) + '.html') - File.open(html_file, 'w+') { |f| f.puts html } - puts `tidy -iqm -w 0 #{html_file} 2>&1` - end -end +require 'json' html = File.read(File.join(SNIPPETS, 'head.html')) html += nav 'pictures' -albums.each do |album| - www_dir = File.join('/srv/www/pdp8-test/pictures', File.basename(album)) - FileUtils.mkdir_p www_dir - images = File.readlines(album, chomp: true) - n = images.size - html += "<section id='#{File.basename album}'>" - html += "<h1><a href='#{meta(images.first, - album)[:href]}'>#{File.basename(album).gsub('_', ' ')}</a></h1>\n" - html += "<div class='gallery'>" - images.each_with_index do |img, _i| - meta = meta img, album - html += "<a href='#{meta[:href]}'><img class='thumb' loading='lazy' width='150' height='100' " - html += "alt='#{File.read(meta[:txt])}' " if File.exist?(meta[:txt]) - html += "src='#{meta[:thumb]}'></a>" - end - html += '</div>' - html += '</section>' +html += "<div class='gallery'>" +Dir[File.join(OUTBOX_DIR, 'create', '*.json')] + .collect { |f| JSON.load_file(f) } + .select { |a| a['to'].include?('https://www.w3.org/ns/activitystreams#Public') } + .sort_by { |a| a['published'] }.reverse + .collect { |a| a['object'] } + .collect { |o| o['attachment'] } + .flatten.compact + .select { |a| a['url'] =~ %r{pictures/webp} and a['mediaType'] == 'image/webp' } + .each do |img| + html += "<img loading='lazy' " + alt = img['name'] ? img['name'].gsub("'", ''').gsub('"', '"') : '' + html += "alt='#{alt}' src='#{img['url']}'>" end +html += '</div>' html += File.read(File.join(SNIPPETS, 'tail.html')) print_html 'pictures', html @@ -4,8 +4,6 @@ require 'date' require 'time' require 'json' -# SOCIAL = '/srv/social/outbox/object/note/' - items = [] %w[music videos climbing].each do |cat| Dir[File.join(MEDIA_DIR, cat, '*')].each do |dir| @@ -27,30 +25,25 @@ items = [] end end -Dir[File.join MEDIA_DIR, 'pictures', 'albums', '*'].each do |album| - items << { - title: File.basename(album).sub('_', ' '), - link: File.join('https://pdp8.info', 'pictures.html#' + File.basename(album)), - guid: File.join('https://pdp8.info', 'pictures.html#' + File.basename(album)), - pubDate: File.mtime(album).httpdate - } -end +Dir[File.join(OUTBOX_DIR, 'create', '*.json')] + .collect { |f| JSON.load_file(f) } + .select { |a| a['to'].include?('https://www.w3.org/ns/activitystreams#Public') } + .select { |a| a['object'] and a['object']['attachment'] } + .collect { |a| a['object'] } + .each do |object| + updated = Date.parse object['published'] + object['attachment'].each do |a| + next unless a['url'] =~ %r{pictures/webp} and a['mediaType'] == 'image/webp' -# duplication of music/video posts? -# Dir[File.join(SOCIAL, '*.json')].each do |json| -# note = JSON.parse(File.read(json)) -# next unless note['attributedTo'] == 'https://social.pdp8.info/pdp8' and note['to'].include?('https://www.w3.org/ns/activitystreams#Public') -# -# # TODO: add enclosures for attachments -# # tags -# items << { -# title: note['published'], -# link: 'https://pdp8.info/social/create.html#' + note['published'], -# guid: note['id'], -# description: '<![CDATA[' + note['content'] + ']]>', -# pubDate: Date.parse(note['published']).httpdate -# } -# end + items << { + title: a['name'], + link: a['url'], + guid: a['url'], + description: "<![CDATA[<img alt='#{a['name']}' src=#{a['url']}>]]>", + pubDate: updated.httpdate + } + end +end # jj items.sort_by { |i| DateTime.parse(i[:pubDate]) }.reverse |