diff options
author | pdp8 <pdp8@pdp8.info> | 2023-07-30 16:45:03 +0200 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2023-07-30 16:45:03 +0200 |
commit | a3ab009e96db2269dcf3f6dd1c103aa885186ee4 (patch) | |
tree | 2ace6b0a9f056ee8929c673c52a72e12dbd30e02 /html.rb | |
parent | fc32ef98dfb83b69d02a31387cf4cdae96e520cd (diff) |
media moved to media.pdp8.info, drone release
Diffstat (limited to 'html.rb')
-rwxr-xr-x | html.rb | 134 |
1 files changed, 74 insertions, 60 deletions
@@ -1,120 +1,134 @@ #!/usr/bin/env ruby +require 'erb' -ROOT = ARGV[0] -SNIPPETS = File.join(File.dirname(__FILE__), "snippets") +MEDIA_DIR = '/srv/media' +MEDIA_URL = 'https://media.pdp8.info' +WWW_DIR = '/srv/www/pdp8-test' +SNIPPETS = File.join(File.dirname(__FILE__), 'snippets') -def nav cat - html = "<nav>" +def nav(cat) + html = '<nav>' html += "<a id='logo' href='/about.html'><img src='/pdp8.png' alt='pdp8'></a>" - ["music", "pictures", "videos", "code", "contact"].each do |c| - c == cat ? cl = 'item current' : cl = 'item' + %w[music pictures videos code contact].each do |c| + cl = c == cat ? 'item current' : 'item' html += "<a class='#{cl}' href='/#{c}.html'>#{c}</a>" end html += "<a class='item' href='/rss.xml'>rss</a>" html += "<a id='menu' href='#' onclick='show_vertical_menu()'>≡</a>" - html += "</nav>" + html += '</nav>' html end -def file_html basename - path = File.join(SNIPPETS, basename + ".html") - html = File.read(File.join(SNIPPETS, "head.html")) +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")) + html += '</div>' + html += File.read(File.join(SNIPPETS, 'tail.html')) print_html basename, html end -def print_html basename, html - out = File.join(ROOT, basename + ".html") +def print_html(basename, html) + out = File.join(WWW_DIR, basename + '.html') puts out - File.open(out, "w+") { |f| f.puts html } + File.open(out, 'w+') { |f| f.puts html } + File.open('tmp.html', 'w+') { |f| f.puts html } if basename == 'music' puts `tidy -iqm -w 0 #{out} 2>&1` end def music_html - music = Dir[File.join(ROOT, "music", "*")].sort.reverse - html = File.read(File.join(SNIPPETS, "head.html")) - html += nav "music" - music.each_with_index do |dir, i| - date = File.basename(dir).split("_")[0] + music = Dir[File.join(MEDIA_DIR, 'music', '*')].sort.reverse + html = File.read(File.join(SNIPPETS, 'head.html')) + html += nav 'music' + music.each do |dir| + date = File.basename(dir).split('_')[0] html += "<div class='post' id='#{date}'>" - title = File.basename(dir).split("_")[1..-1].join(" ") + title = File.basename(dir).split('_')[1..-1].join(' ') html += "<h1>#{title}</h1>" - html += File.read(File.join(dir, "README")) + "<p>" - cover = File.join("/", dir.sub(ROOT, ''), "cover.jpeg") + 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.jpeg') html += "<img class='cover' src='#{cover}' alt='cover'>" - html += "<table>" - Dir[File.join(dir, "*mp3")].each do |mp3| - mp3 = mp3.sub(ROOT, '') - html += "<tr>" + 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] + # name += " ©#{copyrights[i]}" if copyrights + html += '<tr>' html += "<td> <audio controls> <source src='#{mp3}' type='audio/mpeg'> </audio> </td>" - html += "<td>#{File.basename(mp3, '.mp3')[3..-1]}</td>" - html += "</tr>" + html += "<td>#{name}</td>" + html += '</tr>' end - html += "</table>" - bc = "https://pdp8.bandcamp.com/album/#{title.gsub(' ', '-')}" + html += '</table>' + 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>" - html += "<hr>" + html += '</div>' + html += '<hr>' end html += '<p>© 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 + html += File.read(File.join(SNIPPETS, 'tail.html')) + print_html 'music', html end def video_html - videos = Dir[File.join(ROOT, "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] + 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(" ") + title = File.basename(dir).split('_')[1..-1].join(' ') html += "<h1>#{title}</h1>" - txt = File.read(File.join(dir, "README")) + 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>" + html += lines.shift + '<p>' - mp4 = File.join("/videos", File.basename(dir), title.gsub(" ", "_") + ".mp4") - webm = File.join("/videos", File.basename(dir), title.gsub(" ", "_") + ".webm") - poster = File.join("/videos", File.basename(dir), "poster.png") + 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') html += "<video controls poster='#{poster}'> <source src='#{webm}' type='video/webm'> <source src='#{mp4}' type='video/mp4'> </video><p> " - html += lines.join("<br>") - html += "</div>" - html += "<hr>" + html += lines.join('<br>') + html += '</div>' + html += '<hr>' end html += '<p> © 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 + html += File.read(File.join(SNIPPETS, 'tail.html')) + print_html 'videos', html end music_html video_html -["about", "code", "pictures", "contact"].each do |basename| +%w[about code pictures contact].each do |basename| file_html basename end -last = (Dir[File.join(ROOT, "music", "*")] + Dir[File.join(ROOT, "videos", "*")]).sort_by { |d| File.basename(d) }.last.split("/")[-2] + '.html' -puts `cp "#{File.join(ROOT, last)}" "#{File.join(ROOT, "index.html")}"` +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" -].each { |f| puts `rsync -av "#{File.join(SNIPPETS, f)}" "#{ROOT}"` } + 'pdp8.png', + '540px-PDP-8_.jpg', + 'style.css', + 'slideshow.js', + 'robots.txt' +].each { |f| puts `rsync -av "#{File.join(SNIPPETS, f)}" "#{WWW_DIR}"` } |