summaryrefslogtreecommitdiff
path: root/pictures.rb
blob: 33c7ec61158741aa29276d8f2214ef0132b74519 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env ruby
require 'json'
require_relative 'lib'

PICTURE_PATH = '/srv/media/pictures'
WEBP_PATH = File.join PICTURE_PATH, 'webp'
TXT_PATH = File.join PICTURE_PATH, 'txt'

COLLECTION_PATH = File.join PICTURE_PATH, 'collections'

PICTURE_URL = 'https://media.pdp8.info/pictures'
WEBP_URL = File.join PICTURE_URL, 'webp'
JPEG_URL = File.join PICTURE_URL, 'jpeg'

html = File.read(File.join(SNIPPETS, 'head.html'))
html += nav 'pictures'

Dir[File.join COLLECTION_PATH, '*']
  .sort_by { |c| File.mtime c }
  .reverse.each do |collection|
  html += "<div class='post'>"
  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

html += File.read(File.join(SNIPPETS, 'tail.html'))
print_html 'pictures', html