From 0555b2cd77986d916968f1443e375fad005c8d43 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Mon, 4 Mar 2024 23:13:40 +0100 Subject: html.rb separated, Makefile for website generation --- Makefile | 95 ++++++++++++++++++++++++++++++++++++++------------------- climbing.rb | 28 +++++++++++++++++ file.rb | 12 ++++++++ html/head.html | 1 - html/style.css | 2 +- lib.rb | 38 +++++++++++++++++++++++ music.rb | 51 +++++++++++++++++++++++++++++++ music2social.rb | 33 ++++++++++++++++++++ pictures.rb | 33 ++++++++++++++++++++ social.rb | 33 -------------------- videos.rb | 34 +++++++++++++++++++++ 11 files changed, 293 insertions(+), 67 deletions(-) create mode 100755 climbing.rb create mode 100755 file.rb create mode 100755 lib.rb create mode 100755 music.rb create mode 100755 music2social.rb create mode 100755 pictures.rb delete mode 100755 social.rb create mode 100755 videos.rb diff --git a/Makefile b/Makefile index 5acb8ec..7c04719 100644 --- a/Makefile +++ b/Makefile @@ -1,49 +1,80 @@ -media_dir = /srv/media +MEDIA_DIR := /srv/media +TEST_DIR := /srv/www/pdp8-test +PUB_DIR := /srv/www/pdp8 -music_dir = $(media_dir)/music -flac = $(wildcard $(music_dir)/*/*.flac) -mp3 := $(subst flac,mp3,$(flac)) +MUSIC_DIR := $(MEDIA_DIR)/music +FLAC := $(wildcard $(MUSIC_DIR)/*/*.flac) +MP3 := $(subst flac,mp3,$(FLAC)) -img_dir = $(media_dir)/pictures -src_dir = $(img_dir)/src -thumb_dir = $(img_dir)/thumb -www_dir = $(img_dir)/www -img = $(wildcard $(src_dir)/*.jpeg) -img_thumb := $(subst $(src_dir), $(thumb_dir), $(subst jpeg,webp, $(img))) -img_www := $(subst $(src_dir), $(www_dir), $(subst jpeg,webp, $(img))) +IMG_DIR := $(MEDIA_DIR)/pictures +WWW_DIR := $(IMG_DIR)/www +IMG := $(wildcard $(SRC_DIR)/*.jpeg) +IMG_WWW := $(subst $(SRC_DIR), $(WWW_DIR), $(subst jpeg,webp, $(IMG))) -video_dir = /srv/media/videos -video_webm = $(wildcard $(video_dir)/*/*.webm) -video_mp4 := $(subst webm,mp4, $(video_webm)) -video_webp := $(subst webm,webp, $(video_webm)) -video_png := $(subst webm,png, $(video_webm)) +VIDEO_DIR := /srv/media/videos +VIDEO_WEBM := $(wildcard $(VIDEO_DIR)/*/*.webm) +VIDEO_MP4 := $(subst webm,mp4, $(VIDEO_WEBM)) +VIDEO_WEBP := $(subst webm,webp, $(VIDEO_WEBM)) +VIDEO_PNG := $(subst webm,png, $(VIDEO_WEBM)) -climbing_dir = /srv/media/climbing -climbing_webm = $(wildcard $(climbing_dir)/*.webm) -climbing_mp4 := $(subst webm,mp4, $(climbing_webm)) -climbing_webp := $(subst webm,webp, $(climbing_webm)) +CLIMBING_DIR := /srv/media/climbing +CLIMBING_WEBM := $(wildcard $(CLIMBING_DIR)/*.webm) +CLIMBING_MP4 := $(subst webm,mp4, $(CLIMBING_WEBM)) +CLIMBING_WEBP := $(subst webm,webp, $(CLIMBING_WEBM)) -all: music pictures videos climbing +HTML := index.html music.html pictures.html videos.html climbing.html about.html code.html contact.html social/create.html social/announce.html +OTHER := pdp8.png 540px-PDP-8_.jpg style.css robots.txt sitemap.txt rss.xml -music: $(mp3) +TEST_HTML := $(addprefix $(TEST_DIR)/, $(HTML)) +TEST_OTHER := $(addprefix $(TEST_DIR)/, $(OTHER)) +PUB_HTML := $(addprefix $(PUB_DIR)/, $(HTML)) -pictures: $(img_www) $(img_thumb) +all: test + cd $(TEST_DIR); git commit -am "$$(date)"; git push; cd $(PUB_DIR); git pull -videos: $(video_mp4) $(video_webp) +test: $(TEST_HTML) $(TEST_OTHER) -climbing: $(climbing_mp4) $(climbing_webp) +$(TEST_DIR)/rss.xml: $(TEST_HTML) + ./rss.rb -%.mp3: %.flac - ffmpeg -i $< -y -vsync 0 -ab 256k -map_metadata 0 -id3v2_version 3 $@ +$(TEST_DIR)/index.html: $(TEST_DIR)/music.html + cp $< $@ + +$(TEST_DIR)/music.html: $(MP3) + ./music.rb + +$(TEST_DIR)/pictures.html: /srv/social/outbox/create/ $(IMG_WWW) + ./pictures.rb + +$(TEST_DIR)/videos.html: $(VIDEO_MP4) $(VIDEO_WEBP) + ./videos.rb + +$(TEST_DIR)/climbing.html: $(CLIMBING_MP4) $(CLIMBING_WEBP) + ./climbing.rb + +$(TEST_DIR)/%.html: ./html/%.html + ./file.rb $< + +$(TEST_DIR)/%.png: ./html/%.png + cp $< $@ + +$(TEST_DIR)/%.jpg: ./html/%.jpg + cp $< $@ + +$(TEST_DIR)/%.css: ./html/%.css + cp $< $@ + +$(TEST_DIR)/%.txt: ./html/%.txt + cp $< $@ + +%.MP3: %.FLAC + ffmpeg -i $< -y -vsync 0 -ab 256k -MAP_METADATA 0 -ID3V2_VERSION 3 $@ %.webp: %.webm - ffmpeg -i $< -hide_banner -loglevel error -vf thumbnail -frames:v 1 -c:v png -f image2pipe - | convert - $@ + ffmpeg -i $< -HIDE_BANNER -loglevel error -vf thumbnail -frames:v 1 -c:v png -f image2pipe - | convert - $@ -$(www_dir)/%.webp: $(src_dir)/%.jpeg +$(WWW_DIR)/%.webp: $(IMG_DIR)/%.jpeg convert $< -resize 1536x1024 -quality 85 $@ -$(thumb_dir)/%.webp: $(src_dir)/%.jpeg - convert $< -resize 150x100 -quality 85 $@ - %.mp4: %.webm ffmpeg -i $< -vf scale=1280:-2 -c:v h264 -c:a aac -b:a 128k -strict -2 -movflags faststart $@ diff --git a/climbing.rb b/climbing.rb new file mode 100755 index 0000000..6705aba --- /dev/null +++ b/climbing.rb @@ -0,0 +1,28 @@ +#!/usr/bin/env ruby +require_relative 'lib' + +html = File.read(File.join(SNIPPETS, 'head.html')) +html += nav 'climbing' +Dir[File.join(MEDIA_DIR, 'climbing', '*.txt')].collect do |txt| + lines = File.read(txt).lines.collect { |l| l.chomp } + { date: lines.shift, + text: lines.join('
'), + mp4: txt.sub(MEDIA_DIR, MEDIA_URL).sub('.txt', '.mp4'), + webm: txt.sub(MEDIA_DIR, MEDIA_URL).sub('.txt', '.webm'), + webp: txt.sub(MEDIA_DIR, MEDIA_URL).sub('.txt', '.webp') } +end.sort_by { |m| m[:date] }.reverse.each do |post| + w, h = `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 #{post[:webm]}`.chomp.split(',') + html += '
' + html += "

#{post[:date]}

" + html += "

+ " + html += post[:text] + html += '

' +end +html += '

 © pdp8 Creative Commons Attribution 4.0 International License' +html += File.read(File.join(SNIPPETS, 'tail.html')) +print_html 'climbing', html diff --git a/file.rb b/file.rb new file mode 100755 index 0000000..d9bfe78 --- /dev/null +++ b/file.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +require_relative 'lib' + +path = ARGV[0] +basename = File.basename(path, File.extname(path)) +html = File.read(File.join(SNIPPETS, 'head.html')) +html += nav basename +html += "

" +html += File.read(path) +html += '
' +html += File.read(File.join(SNIPPETS, 'tail.html')) +print_html basename, html diff --git a/html/head.html b/html/head.html index 78f38da..daf67fa 100644 --- a/html/head.html +++ b/html/head.html @@ -6,7 +6,6 @@ pdp8 - diff --git a/html/style.css b/html/style.css index dbf2307..8478ca3 100644 --- a/html/style.css +++ b/html/style.css @@ -157,4 +157,4 @@ audio::-webkit-media-controls-panel { #prev:active, #next:active { color: black; -} \ No newline at end of file +} diff --git a/lib.rb b/lib.rb new file mode 100755 index 0000000..3a94d39 --- /dev/null +++ b/lib.rb @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby + +MEDIA_DIR = '/srv/media' +MEDIA_URL = 'https://media.pdp8.info' +WWW_DIR = '/srv/www/pdp8-test' +SNIPPETS = File.join(File.dirname(__FILE__), 'html') + +def nav(cat) + html = '' + html +end + +def file_html(basename) + path = File.join(SNIPPETS, basename + '.html') + html = File.read(File.join(SNIPPETS, 'head.html')) + html += nav basename + html += "
" + html += File.read(path) + html += '
' + html += File.read(File.join(SNIPPETS, 'tail.html')) + print_html basename, html +end + +def print_html(basename, html) + out = File.join(WWW_DIR, basename + '.html') + puts out + File.open(out, 'w+') { |f| f.puts html } + puts `tidy -iqm -w 0 #{out} 2>&1` +end diff --git a/music.rb b/music.rb new file mode 100755 index 0000000..e86e0c5 --- /dev/null +++ b/music.rb @@ -0,0 +1,51 @@ +#!/usr/bin/env ruby + +require_relative 'lib' + +music = Dir[File.join(MEDIA_DIR, 'music', '20*')].sort.reverse +html = File.read(File.join(SNIPPETS, 'head.html')) +html += nav 'music' +html += '
← prev | + faircamp webring | + random | + next →
' +music.each do |dir| + date = File.basename(dir).split('_')[0] + html += "
" + title = File.basename(dir).split('_')[1..-1].join(' ') + html += "

#{title}

" + html += File.read(File.join(dir, 'README')).chomp.gsub("\n\n", '

').gsub("\n", '
') # + '

' + cover = File.join(MEDIA_URL, dir.sub(MEDIA_DIR, ''), 'cover.webp') + alt = File.read(File.join(dir, 'cover.txt')).chomp + w, h = `identify -format "%w %h" #{cover}`.chomp.split(' ') + html += "#{alt}" + html += '' + copyrights_file = File.join(dir, 'copyrights') + copyrights = File.readlines(copyrights_file).collect { |l| l.chomp } if File.exist? copyrights_file + Dir[File.join(dir, '*mp3')].each_with_index do |mp3, _i| + mp3 = File.join(MEDIA_URL, mp3.sub(MEDIA_DIR, '')) + name = File.basename(mp3, '.mp3')[3..-1].gsub('_', ' ') + html += '' + html += "" + html += "" + html += '' + end + html += '
#{name} + +
' + ia = "https://archive.org/details/pdp8_#{title.gsub(' ', '_')}" + html += "

Internet Archive: #{ia}" + bc = if File.exist?(File.join(dir, 'bandcamp')) + File.read(File.join(dir, 'bandcamp')).chomp + else + "https://pdp8.bandcamp.com/album/#{title.gsub(' ', '-')}" + end + html += "

Bandcamp: #{bc}" + html += '

' +end +html += '

© pdp8 Creative Commons Attribution 4.0 International License' +html += File.read(File.join(SNIPPETS, 'tail.html')) +print_html 'music', html diff --git a/music2social.rb b/music2social.rb new file mode 100755 index 0000000..97742bb --- /dev/null +++ b/music2social.rb @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +require 'uri' +require 'json' + +Dir.chdir ARGV[0] +content = ['public', '', ''] +date, title = File.basename(ARGV[0]).split('_', 2) +title.gsub!('_', ' ') +content << title + ' LP' +content << File.read('README') +# content << '' +content << "https://pdp8.info/music.html\##{date}" +# content << '' +bc = if File.exist?('bandcamp') + File.read('bandcamp').chomp + else + "https://pdp8.bandcamp.com/album/#{title.gsub(' ', '-')}" + end +content << "Bandcamp: #{bc}" +content << '' +content << '#creativecommons #electronic #music #techno' +content << '==' +content << File.join("https://media.pdp8.info/music/#{File.basename ARGV[0]}", + 'cover.jpeg') + "\t" + `exiv2 -K Xmp.dc.description -P v cover.jpeg`.chomp.sub( + /^lang=\S+ /, '' + ) + +# Dir['*mp3'].each do |mp3| +# content << File.join("https://media.pdp8.info/music/#{File.basename ARGV[0]}", "#{File.basename mp3}") +# end +File.open('/tmp/content.txt', 'w+') { |f| f.puts content.join("\n") } +system 'hx /tmp/content.txt' +puts `curl -sb cookies.txt --data-binary @/tmp/content.txt -X POST https://social.pdp8.info/create` 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("'", ''').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(' ') + html += "

" + html += "\1') + lines = txt.split("\n") + html += lines.shift + '

' + + mp4 = File.join(MEDIA_URL, 'videos', File.basename(dir), title.gsub(' ', '_') + '.mp4') + webm = File.join(MEDIA_URL, 'videos', File.basename(dir), title.gsub(' ', '_') + '.webm') + poster = File.join(MEDIA_URL, 'videos', File.basename(dir), title.gsub(' ', '_') + '.webp') + w, h = `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 #{webm}`.chomp.split(',') + + html += "

+ " + html += lines.join('
') + html += '

' +end +html += '

 © pdp8 Creative Commons Attribution 4.0 International License' +html += File.read(File.join(SNIPPETS, 'tail.html')) +print_html 'videos', html -- cgit v1.2.3