summaryrefslogtreecommitdiff
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
parent6b40f3b54efabb740e825ba3d94b5695c2b98ede (diff)
html.rb separated, Makefile for website generation
-rw-r--r--Makefile95
-rwxr-xr-xclimbing.rb28
-rwxr-xr-xfile.rb12
-rw-r--r--html/head.html1
-rw-r--r--html/style.css2
-rwxr-xr-xlib.rb38
-rwxr-xr-xmusic.rb51
-rwxr-xr-xmusic2social.rb (renamed from social.rb)0
-rwxr-xr-xpictures.rb33
-rwxr-xr-xvideos.rb34
10 files changed, 260 insertions, 34 deletions
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('<br>'),
+ 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 += '<div class="post">'
+ html += "<h1>#{post[:date]}</h1>"
+ html += "<video controls preload='none' width='#{w}' height='#{h}' poster=#{post[:webp]}>
+ <source src='#{post[:webm]}' type='video/webm'>
+ <source src='#{post[:mp4]}' type='video/mp4'>
+ <a href=#{post[:mp4]}>#{post[:mp4]}</a>
+ </video><p>
+ "
+ html += post[:text]
+ html += '</div>'
+end
+html += '<p>&nbsp;&copy; pdp8 <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>'
+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 += "<div class='post'>"
+html += File.read(path)
+html += '</div>'
+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 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0">
<title>pdp8</title>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fork-awesome@1.2.0/css/fork-awesome.min.css" integrity="sha256-XoaMnoYC5TH6/+ihMEnospgm0J1PM/nioxbOUdnM8HY=" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="/style.css">
<link rel="icon" type="image/png" href="/pdp8.png">
<link rel="alternate" type="application/rss+xml" title="pdp8 rss feed" href="https://pdp8.info/rss.xml">
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 = '<nav>'
+ html += "<a id='logo' href='/about.html'><img src='/pdp8.png' alt='pdp8'></a>"
+ %w[music pictures videos climbing code contact].each do |c|
+ cl = c == cat ? 'item current' : 'item'
+ html += "&nbsp;<a class='#{cl}' href='/#{c}.html'>#{c}</a>"
+ end
+ html += "&nbsp;<a class='item' href='/social/create.html'>social</a>"
+ html += "&nbsp;<a class='item' href='/rss.xml'>rss</a>"
+ html += "&nbsp;<a id='menu' href='#' onclick='show_vertical_menu()'>&equiv;</a>"
+ html += '</nav>'
+ html
+end
+
+def file_html(basename)
+ path = File.join(SNIPPETS, basename + '.html')
+ html = File.read(File.join(SNIPPETS, 'head.html'))
+ html += nav basename
+ html += "<div class='post'>"
+ html += File.read(path)
+ html += '</div>'
+ 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 += '<div class="post"><a href="https://faircamp.webr.ing/prev/pdp8.info/music.html">← prev</a> |
+ <a href="https://faircamp.webr.ing/">faircamp webring</a> |
+ <a href="https://faircamp.webr.ing/rand">random</a> |
+ <a href="https://faircamp.webr.ing/next/pdp8.info/music.html">next →</a></div>'
+music.each do |dir|
+ date = File.basename(dir).split('_')[0]
+ html += "<div class='post' id='#{date}'>"
+ title = File.basename(dir).split('_')[1..-1].join(' ')
+ html += "<h1>#{title}</h1>"
+ html += File.read(File.join(dir, 'README')).chomp.gsub("\n\n", '<p>').gsub("\n", '<br>') # + '<p>'
+ 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 += "<img class='cover' loading='lazy' width='#{w}' height='#{h}' src='#{cover}' alt='#{alt}'>"
+ html += '<table>'
+ 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 += '<tr>'
+ html += "<td>#{name}</td>"
+ html += "<td>
+ <audio preload='none' controls>
+ <source src='#{mp3}' type='audio/mpeg'>
+ <a href=#{mp3}>#{mp3}</a>
+ </audio>
+ </td>"
+ html += '</tr>'
+ end
+ html += '</table>'
+ ia = "https://archive.org/details/pdp8_#{title.gsub(' ', '_')}"
+ html += "<p>Internet Archive: <a href='#{ia}'>#{ia}</a>"
+ 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 += "<p>Bandcamp: <a href='#{bc}'>#{bc}</a>"
+ html += '</div>'
+end
+html += '<p>&copy; pdp8 <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>'
+html += File.read(File.join(SNIPPETS, 'tail.html'))
+print_html 'music', html
diff --git a/social.rb b/music2social.rb
index 97742bb..97742bb 100755
--- a/social.rb
+++ b/music2social.rb
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
diff --git a/videos.rb b/videos.rb
new file mode 100755
index 0000000..d4f68a7
--- /dev/null
+++ b/videos.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+
+require_relative 'lib'
+
+videos = Dir[File.join(MEDIA_DIR, 'videos', '*')].sort.reverse
+html = File.read(File.join(SNIPPETS, 'head.html'))
+html += nav 'videos'
+videos.each_with_index do |dir, _i|
+ date = File.basename(dir).split('_')[0]
+ html += "<div class='post' id='#{date}'>"
+ title = File.basename(dir).split('_')[1..-1].join(' ')
+ html += "<h1>#{title}</h1>"
+ txt = File.read(File.join(dir, 'README'))
+ txt = txt.gsub(/(http\S*)/, '<a href="\1">\1</a>')
+ lines = txt.split("\n")
+ html += lines.shift + '<p>'
+
+ 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 += "<video controls preload='none' width='#{w}' height='#{h}' poster='#{poster}'>
+ <source src='#{webm}' type='video/webm'>
+ <source src='#{mp4}' type='video/mp4'>
+ <a href=#{mp4}>#{mp4}</a>
+ </video><p>
+ "
+ html += lines.join('<br>')
+ html += '</div>'
+end
+html += '<p>&nbsp;&copy; pdp8 <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>'
+html += File.read(File.join(SNIPPETS, 'tail.html'))
+print_html 'videos', html