summary refs log tree commit diff
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2024-07-29 14:21:31 +0200
committerpdp8 <pdp8@pdp8.info>2024-07-29 14:21:31 +0200
commitcd53a2fe5fc8baf9750fbd2d9b0b4c855d8694a7 (patch)
tree689c156602c61da3a8ea177e49ec10590f1f6fd0
parentd987641d7b68fcfa8431b1835411bb1095a37961 (diff)
rss sorting fixed, rss limited to 25 items, fediring
-rw-r--r--Makefile16
-rwxr-xr-xclimbing.rb28
-rwxr-xr-xhtml.rb189
-rw-r--r--html/style.css29
-rwxr-xr-xlib.rb35
-rwxr-xr-xmusic.rb3
-rwxr-xr-xrss.rb40
7 files changed, 90 insertions, 250 deletions
diff --git a/Makefile b/Makefile
index c8db1a6..bb2e7d3 100644
--- a/Makefile
+++ b/Makefile
@@ -28,11 +28,11 @@ 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_WEBM := $(wildcard $(CLIMBING_DIR)/*/*.webm)
 CLIMBING_MP4 := $(subst webm,mp4, $(CLIMBING_WEBM))
 CLIMBING_WEBP := $(subst webm,webp, $(CLIMBING_WEBM))
 
-HTML := index.html music.html pictures.html videos.html climbing.html about.html code.html contact.html #social/create.html social/announce.html 
+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
 
 TEST_HTML := $(addprefix $(TEST_DIR)/, $(HTML))
@@ -61,12 +61,6 @@ $(TEST_DIR)/pictures.html: $(IMG_ALBUMS) $(WEBP_IMG) $(THUMB_IMG)
 $(TEST_DIR)/videos.html: $(VIDEO_MP4) $(VIDEO_WEBP)
 	./videos.rb
 
-# $(TEST_DIR)/social/create.html: 
-# 	./social.rb create
-	
-# $(TEST_DIR)/social/announce.html: 
-# 	./social.rb announce
-	
 $(TEST_DIR)/climbing.html: $(CLIMBING_MP4) $(CLIMBING_WEBP)
 	./climbing.rb
 
@@ -88,14 +82,14 @@ $(TEST_DIR)/%.txt: ./html/%.txt
 %.mp3: %.flac
 	ffmpeg -i $< -y -vsync 0 -ab 256k -map_metadata 0 -id3v2_version 3 $@
 
-%.webp: %.webm
-	ffmpeg -i $< -loglevel error -vf thumbnail -frames:v 1 -c:v png -f image2pipe - | magick - $@
-
 $(WEBP_DIR)/%.webp: $(JPEG_DIR)/%.jpeg
 	magick $< -resize 1536x1024 -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 - $@
+
 %.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
index 139925d..c016bfa 100755
--- a/climbing.rb
+++ b/climbing.rb
@@ -1,25 +1,23 @@
 #!/usr/bin/env ruby
 require_relative 'lib'
 
+climbing = Dir[File.join(MEDIA_DIR, 'climbing', '*')].select { |f| File.directory? f }.sort.reverse
 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|
-  html += '<div class="post">'
-  html += "<h1>#{post[:date]}</h1>"
-  html += "<video controls preload='none' poster=#{post[:webp]}>
-          <source src='#{post[:webm]}' type='video/webm'>
-          <source src='#{post[:mp4]}' type='video/mp4'>
-          <a href=#{post[:mp4]}>#{post[:mp4]}</a>
+climbing.each do |dir|
+  date = File.basename(dir)
+  html += "<div class='post' id='#{date}'>"
+  html += "<h1>#{date}</h1>"
+  mp4 = Dir[File.join(dir, '*.mp4')].first.sub(MEDIA_DIR, MEDIA_URL)
+  webm = Dir[File.join(dir, '*.webm')].first.sub(MEDIA_DIR, MEDIA_URL)
+  poster = Dir[File.join(dir, '*.webp')].first.sub(MEDIA_DIR, MEDIA_URL)
+  html += "<video controls preload='none' poster='#{poster}'>
+          <source src='#{webm}' type='video/webm'>
+          <source src='#{mp4}' type='video/mp4'>
+          <a href=#{mp4}>#{mp4}</a>
         </video><p>
         "
-  html += post[:text]
+  html += File.read(File.join(dir, 'README'))
   html += '</div>'
 end
 html += File.read(File.join(SNIPPETS, 'tail.html'))
diff --git a/html.rb b/html.rb
deleted file mode 100755
index d3def36..0000000
--- a/html.rb
+++ /dev/null
@@ -1,189 +0,0 @@
-#!/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
-
-def music_html
-  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|
-    # next if dir.match 'alfadeo'
-
-    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('_', ' ')
-      # name += " &copy;#{copyrights[i]}" if copyrights
-      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
-end
-
-def picture_html
-  html = File.read(File.join(SNIPPETS, 'head.html'))
-  html += nav 'pictures'
-  html += '<div class="gallery">'
-  Dir[File.join(MEDIA_DIR, 'pictures', '*.jpeg')].sort.reverse.each do |img|
-    thumb = File.join(MEDIA_URL, 'pictures', 'thumb', File.basename(img).sub(/jpeg$/, 'webp'))
-    html += "<a href='#{File.join(MEDIA_URL, 'pictures',
-                                  File.basename(img))}'><img class='thumb' loading='lazy' width='150' height='100' src='#{thumb}'></a>"
-  end
-  html += '</div>'
-  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 'pictures', html
-end
-
-def video_html
-  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), 'poster.png')
-    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
-end
-
-def climbing_html
-  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 += File.read(File.join(SNIPPETS, 'tail.html'))
-  print_html 'climbing', html
-end
-
-music_html
-# picture_html
-video_html
-climbing_html
-
-%w[about code pictures contact].each do |basename|
-  file_html basename
-end
-
-last = (Dir[File.join(MEDIA_DIR, 'music', '*')] + Dir[File.join(MEDIA_DIR, 'videos', '*')]).sort_by { |d|
-  File.basename(d)
-}.last.split('/')[-2] + '.html'
-puts `cp "#{File.join(WWW_DIR, last)}" "#{File.join(WWW_DIR, 'index.html')}"`
-
-[
-  'pdp8.png',
-  '540px-PDP-8_.jpg',
-  'style.css',
-  'slideshow.js',
-  'robots.txt',
-  'sitemap.txt'
-].each { |f| puts `rsync -av "#{File.join(SNIPPETS, f)}" "#{WWW_DIR}"` }
diff --git a/html/style.css b/html/style.css
index ddaf027..7cce6d1 100644
--- a/html/style.css
+++ b/html/style.css
@@ -9,7 +9,9 @@ body {
 
 nav {
   display: flex;
+  flex-wrap: wrap;
   align-items: center;
+  justify-content: space-between;
 }
 
 nav img {
@@ -18,11 +20,29 @@ nav img {
 
 nav .menu {
   display: flex;
+  align-items: center;
+}
+
+nav .site {
+  display: flex;
   flex-wrap: wrap;
-  align-items: baseline;
   font-size: larger
 }
 
+nav .webring {
+  display: flex;
+  flex-wrap: wrap;
+}
+
+nav .webring .ring {
+  font-weight: bold;
+}
+
+nav .webring div {
+  display: flex;
+  margin: 0 1em;
+}
+
 nav a {
   margin: 0 0.5em;
 }
@@ -70,13 +90,6 @@ iframe {
   border: none;
 }
 
-.webring {
-  display: flex;
-  flex-wrap: wrap;
-  margin-top: 2em;
-  align-items: baseline;
-}
-
 .post {
   /* margin: 1em 2em; */
 }
diff --git a/lib.rb b/lib.rb
index b3dbc73..77f350b 100755
--- a/lib.rb
+++ b/lib.rb
@@ -6,18 +6,39 @@ 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 logo'></a>"
-  html += "<div class='menu'>"
+  html = "
+  <nav>
+    <div class='menu'>
+      <a id='logo' href='/about.html'><img src='/pdp8.png' alt='pdp8 logo'></a>
+      <div class='site'>
+  "
   %w[music pictures videos climbing code contact].each do |c|
     html += '<a '
     html += "class='current' " if c == cat
     html += "href='/#{c}.html'>#{c}</a>"
   end
-  html += "<a #{cat == 'social' ? 'class="current"' : ''} href='/social/create.html'>social</a>"
-  html += "<a href='/rss.xml'>rss</a>"
-  html += '</div>'
-  html += '</nav>'
+  html += "
+        <a #{cat == 'social' ? 'class="current"' : ''} href='/social/create.html'>social</a>
+        <a href='/rss.xml'>rss</a>
+      </div>
+    </div>
+
+    <div class='webring'>
+      <div>
+        <a href='https://fediring.net/' class='ring'>fediring:</a>
+        <a href='https://fediring.net/previous?host=pdp8.info'>←</a>
+        <a href='https://fediring.net/random'>random</a>
+        <a href='https://fediring.net/next?host=pdp8.info'>→</a>
+      </div>
+      <div>
+        <a href='https://faircamp.webr.ing/' class='ring'>faircamp:</a>
+        <a href='https://faircamp.webr.ing/prev/pdp8.info/music.html'>←</a>
+        <a href='https://faircamp.webr.ing/rand'>random</a>
+        <a href='https://faircamp.webr.ing/next/pdp8.info/music.html'>→</a>
+      </div>
+    </div>
+  </nav>
+  "
   html
 end
 
diff --git a/music.rb b/music.rb
index c63f17d..c01faf8 100755
--- a/music.rb
+++ b/music.rb
@@ -5,9 +5,6 @@ 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="webring">
-<b><a href="https://faircamp.webr.ing/">faircamp webring:</a></b>&nbsp;&nbsp;
-<a href="https://faircamp.webr.ing/prev/pdp8.info/music.html">←&nbsp;prev</a>&nbsp;|&nbsp;<a href="https://faircamp.webr.ing/rand">random</a>&nbsp;|&nbsp;<a href="https://faircamp.webr.ing/next/pdp8.info/music.html">next&nbsp;→</a></div>'
 music.each do |dir|
   date = File.basename(dir).split('_')[0]
   html += "<div class='post' id='#{date}'>"
diff --git a/rss.rb b/rss.rb
index eb163d4..68c9632 100755
--- a/rss.rb
+++ b/rss.rb
@@ -1,28 +1,41 @@
 #!/usr/bin/env ruby
+require_relative 'lib'
 require 'date'
+require 'time'
 require 'json'
 
-MEDIA = '/srv/media/'
-SOCIAL = '/srv/social/outbox/object/note/'
-WWW = '/srv/www/pdp8-test/'
+# SOCIAL = '/srv/social/outbox/object/note/'
 
 items = []
-%w[music videos].each do |cat|
-  Dir[File.join(MEDIA, cat, '*')].each do |dir|
+%w[music videos climbing].each do |cat|
+  Dir[File.join(MEDIA_DIR, cat, '*')].each do |dir|
     next unless File.basename(dir).match(/^\d/)
 
     date = File.basename(dir).split('_')[0]
     updated = Date.parse(date)
+    title = File.basename(dir).split('_')[1..-1].join(' ')
+    description = File.read(File.join(dir, 'README')).chomp.sub(/^\n/, '').sub("\n\n", "\n")
+    title = description if title.empty?
+    # title = date if title.empty?
     items << {
-      title: File.basename(dir).split('_')[1..-1].join(' '),
+      title: title,
       link: File.join('https://pdp8.info', cat + '.html#' + date),
       guid: File.join('https://pdp8.info', cat + '.html#' + date),
-      description: '<![CDATA[' + File.read(File.join(dir, 'README')).chomp.sub(/^\n/, '').sub("\n\n", "\n") + ']]>',
+      description: "<![CDATA[#{description}]]>",
       pubDate: updated.httpdate
     }
   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
+
 # duplication of music/video posts?
 # Dir[File.join(SOCIAL, '*.json')].each do |json|
 #   note = JSON.parse(File.read(json))
@@ -39,14 +52,7 @@ end
 #   }
 # end
 
-date = Dir[File.join(MEDIA, 'pictures', '*.jpeg')].last.split('_')[0]
-updated = Date.parse(date)
-items << {
-  title: 'pictures',
-  link: 'https://pdp8.info/pictures.html',
-  guid: 'https://pdp8.info/pictures.html',
-  pubDate: updated.httpdate
-}
+# jj items.sort_by { |i| DateTime.parse(i[:pubDate]) }.reverse
 
 xml = ['<?xml version="1.0" encoding="UTF-8"?>
 <rss version="2.0"
@@ -62,7 +68,7 @@ xml = ['<?xml version="1.0" encoding="UTF-8"?>
 date = DateTime.now
 xml << "    <pubDate>#{date.httpdate}</pubDate>"
 
-items.sort_by { |i| i['pubDate'] }.each do |item|
+items.sort_by { |i| DateTime.parse(i[:pubDate]) }.reverse[0..24].each do |item|
   xml << '    <item>'
   item.each do |k, v|
     xml << "      <#{k}>#{v}</#{k}>"
@@ -72,4 +78,4 @@ end
 xml << '  </channel>
 </rss>'
 
-File.open(File.join(WWW, 'rss.xml'), 'w+') { |f| f.puts xml.join("\n") }
+File.open(File.join(WWW_DIR, 'rss.xml'), 'w+') { |f| f.puts xml.join("\n") }