parkerdavis-newcommentnotification.web.val.run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { email } from "https://esm.town/v/std/email";
const DELETE_COMMENT_SECRET = Deno.env.get("DELETE_COMMENT_SECRET");
import { type Comment } from "https://esm.town/v/parkerdavis/CommentType";
const baseUrl = "agave-astro.netlify.app";
export default async function(req: Request): Promise<Response> {
if (req.method === "POST") {
const comment = await req.json() as Comment;
console.log("comment", comment);
const manageUrl =
`https://${baseUrl}/api/comments/commentManager?secret=${DELETE_COMMENT_SECRET}&commentId=${comment.id}`;
const modifiedBody = comment.body.replaceAll("\n", "<br>");
await email({
subject: `New Comment on ${comment.path}`,
html: `
<h1>New Comment on "${comment.path}"</h1>
<p>Author: ${comment.author}</p>
<p>Body: <br>${modifiedBody}</p>
<p><a href="https://${baseUrl}${comment.path}#comments-section">View Comment</a></p>
<p><a href="${manageUrl}">Manage Comment / Rebuild Site</a></p>
<pre>${JSON.stringify(comment, null, 2)}</pre>
`,
});
return Response.json({ ok: true });
} else {
return new Response("Hi");
}
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
v39
June 22, 2024