diff --git a/src/routes/entries.ts b/src/routes/entries.ts index 8cefaf1..a2c969b 100644 --- a/src/routes/entries.ts +++ b/src/routes/entries.ts @@ -1,6 +1,6 @@ import { Context } from "hono"; +import { html, raw } from "hono/html"; import { Env, FeedMetadata, EmailData } from "../types"; -import { escapeHtml } from "../utils/html"; export async function handle(c: Context): Promise { const env = c.env as unknown as Env; @@ -34,12 +34,17 @@ export async function handle(c: Context): Promise { return new Response("Entry not found", { status: 404 }); } - const html = ` + c.header( + "Content-Security-Policy", + "default-src 'none'; style-src 'unsafe-inline'; img-src *; frame-src 'none'", + ); + + return c.html(html` - ${escapeHtml(emailData.subject)} + ${emailData.subject} -

${escapeHtml(emailData.subject)}

+

${emailData.subject}

-
From:
${escapeHtml(emailData.from)}
-
Date:
${escapeHtml(new Date(emailData.receivedAt).toUTCString())}
+
From:
${emailData.from}
+
Date:
${new Date(emailData.receivedAt).toUTCString()}
-
${emailData.content}
+
${raw(emailData.content)}
-`; - - return new Response(html, { - status: 200, - headers: { - "Content-Type": "text/html; charset=utf-8", - "Content-Security-Policy": - "default-src 'none'; style-src 'unsafe-inline'; img-src *; frame-src 'none'", - }, - }); +`); } diff --git a/src/utils/html.ts b/src/utils/html.ts deleted file mode 100644 index 62b0389..0000000 --- a/src/utils/html.ts +++ /dev/null @@ -1,7 +0,0 @@ -export function escapeHtml(str: string): string { - return str - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/"/g, """); -}