# vy by Christian Neukirchen, MIT-licensed.
pages = Dir["entries/*[^~]"].map { |f| File.basename f }
b = binding; Dir.mkdir("site") rescue nil
rx = Regexp.new pages.map { |p|"\\b"+p.gsub(/[\W-]/,'.?')+"\\b"}.join('|'), "i"
def n(s); s.downcase.delete("^a-z0-9"); end
words = Hash[*pages.map { |e| [n(e), e] }.flatten]
pages.each { |p|
File.open("site/#{p}.html", "w") { |o| o <<
"<!DOCTYPE html><meta charset='UTF-8'><title>vy: #{p}</title>" <<
"<style>body, pre { background-color: #333; color: #eee;
font: 12px Monaco, fixed, Consolas, monospace; }
a { color: #ffcb00; text-decoration: none; }</style>\n<pre>" <<
File.read("entries/#{p}").gsub(/^!(.*)/) { eval $1, b }.
gsub(rx) { |w| %Q{<a href="#{words[n(w)]}.html">#$&</a>}} << '</pre>' }
}