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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/** @jsxImportSource https://esm.sh/react */
import { Hono } from "npm:hono@3";
import { getAllPageEntriesDb, getLatestPageEntryDb } from "https://esm.town/v/rwev/pageEntriesDb";
import { renderToString } from "npm:react-dom/server";
const app = new Hono();
const stylesheet = (
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
/>
);
app.get("/entry", async () => {
return new Response(
renderToString(
<>
{stylesheet}
<main class="container-fluid">
<form action="https://rwev-handleSavePageForm.web.val.run/" method="post">
<textarea id="text" placeholder="New entry" name="text"></textarea>
<input type="submit" value="Submit" />
</form>
</main>
</>,
),
{
headers: {
"Content-Type": "text/html",
},
},
);
});
app.get("/", async () => {
const allEntries = await getAllPageEntriesDb();
return new Response(
renderToString(
<>
{stylesheet}
<header class="container-fluid">
<a role="button" href="/entry">New entry</a>
</header>
<main class="container-fluid">
{allEntries.map((entry) => (
<article>
<header>#{entry.id} {entry.dt}</header>
<p>{entry.value}</p>
</article>
))}
</main>
</>,
),
{
headers: {
"Content-Type": "text/html",
},
},
);
});
export default app.fetch;