#!/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
music.each_with_index do |dir, i|
html = File.read(File.join(SNIPPETS, "head.html"))
html += nav "music"
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 += "
"
Dir[File.join(dir, "*mp3")].each do |f|
f = "/" + f.sub(ROOT, '')
html += "
#{File.basename(f, '.mp3')}
"
end
bc = "https://pdp8.bandcamp.com/#{title.gsub(' ', '-')}"
html += "
"
j = (i - 1) % music.size
p = File.join("/", File.basename(music[j]) + ".html")
html += "
previous
"
html += ""
j = (i + 1) % music.size
n = File.join("/", File.basename(music[j]) + ".html")
html += "
[#{i + 1}/#{music.size}] next
"
html += "
"
html += File.read(File.join(SNIPPETS, "tail.html"))
print_html File.basename(dir), html
if i == 0
print_html "music", html
end
end
end
def video_html
videos = Dir[File.join(ROOT, "videos", "*")].sort.reverse
videos.each_with_index do |dir, i|
html = File.read(File.join(SNIPPETS, "head.html"))
html += nav "videos"
html += "
"
title = File.basename(dir).split("_")[1..-1].join(" ")
html += "
"
j = (i - 1) % videos.size
p = File.join("/", File.basename(videos[j]) + ".html")
html += "
previous
"
html += ""
j = (i + 1) % videos.size
n = File.join("/", File.basename(videos[j]) + ".html")
html += "
[#{i + 1}/#{videos.size}] next
"
html += "
"
html += File.read(File.join(SNIPPETS, "tail.html"))
print_html File.basename(dir), html
if i == 0
print_html "videos", html
end
end
end
music_html
video_html
["about", "code", "pictures", "contact"].each do |basename|
file_html basename
end
["pdp8.png", "540px-PDP-8_.jpg", "style.css", "distances.js", "images.js"].each { |f| `rsync -av "#{File.join(SNIPPETS, f)}" "#{ROOT}"` }
`rsync -av #{File.join(SNIPPETS, "Fork-Awesome-1.2.0")} "#{ROOT}"`
# rss