64 lines
1.4 KiB
Ruby
Executable File
64 lines
1.4 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
require 'cgi'
|
|
|
|
$PAGE_BASE = "http://tilde.town/~dzwdz/golf"
|
|
$LOCAL_BASE = "/home/dzwdz/public_html/golf"
|
|
|
|
$HTML_HEAD, $HTML_FOOT = File.read('template.html').split('/snip/')
|
|
|
|
def all_files(event)
|
|
`ls -d /home/*/golf/#{event}/*`
|
|
.lines
|
|
.map(&:strip)
|
|
end
|
|
|
|
def submissions(event)
|
|
all_files(event)
|
|
.filter {|l| not l.end_with? '.hint'}
|
|
end
|
|
|
|
def challenge_page(event)
|
|
file = File.new("#{$LOCAL_BASE}/#{event}/index.html", 'w')
|
|
file.write $HTML_HEAD
|
|
|
|
# challenge info
|
|
file.write "<div id=\"challenge_header\">"
|
|
file.write "<h1>#{event}</h1>"
|
|
file.write File.read("challenges/#{event}/desc.html")
|
|
file.write "</div>"
|
|
|
|
# solutions
|
|
file.write "<div id=\"solutions\">"
|
|
submissions(event)
|
|
.each do |path|
|
|
file.write "<div class=\"sol\">"
|
|
file.write "<h2>#{path.split('.')[-1]}, #{File.size path} bytes</h2>"
|
|
file.write "<pre>#{CGI::escapeHTML File.read path}</pre>"
|
|
file.write "<p class=\"source\">#{path.sub('/home/', '~')}</p>"
|
|
file.write "</div>"
|
|
end
|
|
|
|
file.write "</div>"
|
|
|
|
file.write $HTML_FOOT
|
|
file.close
|
|
end
|
|
|
|
def static_page(path)
|
|
File.open "#{$LOCAL_BASE}/#{path}", "w" do
|
|
|f|
|
|
f.write $HTML_HEAD
|
|
f.write File.read path
|
|
f.write $HTML_FOOT
|
|
end
|
|
end
|
|
|
|
Dir['challenges/*'].each do |path|
|
|
name = path.split('/', 2)[-1]
|
|
challenge_page name
|
|
end
|
|
|
|
static_page 'index.html'
|
|
static_page 'how.html'
|
|
`cp style.css #{$LOCAL_BASE}/`
|