move to raw html, make readme use buns html rewrite and always set to

lazy image load
This commit is contained in:
creations 2025-04-26 11:10:31 -04:00
parent 10416dbff0
commit 2ee5f0512e
Signed by: creations
GPG key ID: 8F553AA4320FC711
7 changed files with 33 additions and 62 deletions

View file

@ -1,5 +1,6 @@
import { resolve } from "node:path";
import { badgeApi, lanyardConfig } from "@config/environment";
import { renderEjsTemplate } from "@helpers/ejs";
import { file } from "bun";
const routeDef: RouteDef = {
method: "GET",
@ -13,17 +14,24 @@ async function handler(request: ExtendedRequest): Promise<Response> {
.replace(/^https?:\/\//, "")
.replace(/\/$/, "");
const ejsTemplateData: EjsTemplateData = {
title: "Discord Profile",
username: "",
user: { id: id || lanyardConfig.userId },
instance: instance,
badgeApi: badgeApi,
avatar: `https://cdn.discordapp.com/embed/avatars/${Math.floor(Math.random() * 5)}.png`,
extraOptions: {},
};
const path = resolve("src", "views", "index.html");
const bunFile = file(path);
return await renderEjsTemplate("index", ejsTemplateData);
const html = new HTMLRewriter()
.on("head", {
element(head) {
head.setAttribute("data-user-id", id || lanyardConfig.userId);
head.setAttribute("data-instance-uri", instance);
head.setAttribute("data-badge-url", badgeApi || "");
},
})
.transform(await bunFile.text());
return new Response(html, {
headers: {
"Content-Type": "text/html",
},
});
}
export { handler, routeDef };