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
1 changed files with 15 additions and 0 deletions

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
}