#!/usr/bin/env ruby ROOT = ARGV[0] SNIPPETS = File.join(File.dirname(__FILE__), "snippets") 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(ROOT, 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(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] html += "
" title = File.basename(dir).split("_")[1..-1].join(" ") html += "

#{title}

" html += File.read(File.join(dir, "README")) + "

" cover = File.join("/", dir.sub(ROOT, ''), "cover.jpeg") html += "cover" html += "" Dir[File.join(dir, "*mp3")].each do |mp3| mp3 = "/" + mp3.sub(ROOT, '') html += "" html += "" html += "" end html += "
#{File.basename(mp3, '.mp3')}
" bc = "https://pdp8.bandcamp.com/#{title.gsub(' ', '-')}" html += "

Bandcamp: #{bc}" html += "

" html += "
" end html += '

© pdp8 Creative Commons Attribution 4.0 International License' 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] html += "

" title = File.basename(dir).split("_")[1..-1].join(" ") html += "

#{title}

" txt = File.read(File.join(dir, "README")) txt = txt.gsub(/(http\S*)/, '\1') lines = txt.split("\n") html += lines.shift + "

" 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") html += "

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

" html += "
" end html += '

© pdp8 Creative Commons Attribution 4.0 International License' html += File.read(File.join(SNIPPETS, "tail.html")) print_html "videos", html end music_html video_html ["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")}"` [ "pdp8.png", "540px-PDP-8_.jpg", "style.css", "slideshow.js", "robots.txt" ].each { |f| puts `rsync -av "#{File.join(SNIPPETS, f)}" "#{ROOT}"` }