This commit is contained in:
abbie 2024-02-11 17:10:48 +00:00
parent 181def9f0a
commit a0cfae1bc5
Signed by: threeoh6000
GPG key ID: 801FE4AD456E922C

15
badpklblog.cgi Executable file
View file

@ -0,0 +1,15 @@
#!/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
}