From e3c672f4648997dbe00624e09c63c990a8ea3596 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Mon, 22 Aug 2022 00:52:15 +0200 Subject: audio and video rendering, Fork-Awesome-1.2.0 included --- html.rb | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 125 insertions(+), 28 deletions(-) (limited to 'html.rb') diff --git a/html.rb b/html.rb index da73660..75caf46 100755 --- a/html.rb +++ b/html.rb @@ -1,43 +1,140 @@ #!/usr/bin/env ruby + ROOT = ARGV[0] SNIPPETS = File.join(File.dirname(__FILE__), "snippets") -tree = { - "music" => Dir[File.join(ROOT, "music", "*")], - "videos" => Dir[File.join(ROOT, "videos", "*")], -} -def html src - cat = File.basename(src, ".html") - html = File.read(File.join(SNIPPETS, "head.html")) - 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")) - out = File.join(ROOT, cat + ".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 80 #{out} 2>&1` - # puts `echo "#{html}" > #{out} ` + 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 += " + cover +

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

Bandcamp: #{bc}" + html += "

" + 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 -["about", "code", "pictures", "info", "newsletter"].each do |cat| - html File.join(SNIPPETS, cat + ".html") +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 += "

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

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

" + 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", "newsletter"].each do |basename| + file_html basename end -["pdp8.png", "style.css", "distances.js", "images.js"].each { |f| `cp "#{File.join(SNIPPETS, f)}" "#{ROOT}"` } +["pdp8.png", "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 -- cgit v1.2.3