badpklblog/badpklblog.cgi
2024-02-11 17:10:48 +00:00

15 lines
810 B
Text
Executable file

#!/usr/bin/pkl eval
function template(body: String): String = "<!DOCTYPE HTML><html><head><style>body { background-color: #DDD06A; }</style></head><body>\(body)<hr/><i>Served by \(read?("env:SERVER_SOFTWARE") ?? "a web server") and badpklblog.</body></html>"
function loadPost(name: String): String = "<h1>" + name.replaceAll("_", " ") + "</h1>" + read("file:../posts/\(name).post").text ?? "Error in loading."
function loadIndex(): String = "<h1>Blog Listing</h1><ul>" + read("file:../posts/index").text.replaceAll("£", "<li>").replaceAll("€", "</li>") + "</ul>"
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
}