mirror-web/_src/entrypoints-njs/fancy_index.ts
Harry Chen 7328ec3415 Switch some js files to ts for better typing
Signed-off-by: Harry Chen <i@harrychen.xyz>
2024-04-21 13:17:19 +08:00

35 lines
861 B
TypeScript

import Mark from "markup-js";
function fancyIndexRender(r: NginxHTTPRequest, templateUrl: string) {
r.subrequest(
templateUrl,
{
args: "",
body: "",
method: "GET",
},
function (rTmpl) {
if (rTmpl.status != 200) {
return r.return(rTmpl.status);
}
const tmpl = rTmpl.responseText;
const result = Mark.up(tmpl, {
url: r.variables.request_uri.replace(/\/+/g, "/").replace(/\?.*$/, ""),
});
r.status = 200;
r.headersOut["Content-Type"] = "text/html";
r.sendHeader();
r.send(result);
r.finish();
},
);
}
export function fancyIndexBeforeRender(r: NginxHTTPRequest) {
return fancyIndexRender(r, "/fancy-index/before.html");
}
export function fancyIndexAfterRender(r: NginxHTTPRequest) {
return fancyIndexRender(r, "/fancy-index/after.html");
}