#!/usr/bin/pkl eval
function template(body: String): String = "
\(body)
Served by \(read?("env:SERVER_SOFTWARE") ?? "a web server") and badpklblog."
function loadPost(name: String): String = "" + name.replaceAll("_", " ") + "
" + read("file:../posts/\(name).post").text ?? "Error in loading."
function loadIndex(): String = "Blog Listing
" + read("file:../posts/index").text.replaceAll("£", "- ").replaceAll("€", "
") + "
"
header = "Content-Type: text/html\r\n\r\n"
b = read?("env:QUERY_STRING") ?? ""
xb = b.replaceAll("%20", " ")
result = if (xb == "") template(loadIndex()) else template(loadPost(xb.replaceAll(" ", "_")))
output {
text = header + result
}