vblog
Viewing readonly version: 247View latest version
Script
99
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
/** @jsxImportSource npm:hono/jsx */
import { Hono } from "npm:hono";
import type { Context } from "npm:hono";
import type { JSX } from "npm:hono/jsx";
import type { Data, Post } from "./types";
const app = new Hono();
function Home(data: Data, c: Context) {
return (
<div>
<h1>Blog home</h1>
<ul>
{data.posts.map((post: Post, i: number) => (
<li key={post.name + i}>
<a href={`/posts/${post.name}`}>
{post.name}
</a>
</li>
))}
</ul>
</div>
);
}
function Post(data: Data, c: Context) {
const name = c.req.param("post");
const post = data.posts.find(p => p.name === name);
if (!post) return NotFound(data, c);
return (
<div>
<h1>Post {name}</h1>
<div
dangerouslySetInnerHTML={{
__html: post.html,
}}
H
www