iamseeley-multiroutehono.web.val.run
Readme

🌐 Multi-Route Website with Hono

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* @title Multi-Route Website with Hono in Val Town
* @description Create a personal portfolio website with multiple pages using Hono framework and JSX.
*/
/** @jsxImportSource npm:hono@3/jsx */
import { Hono } from "npm:hono";
import { jsxRenderer } from 'npm:hono/jsx-renderer';
import type { FC } from 'hono/jsx';
import { html } from 'npm:hono/html';
import { websiteStyles } from "https://esm.town/v/iamseeley/websiteStyles";
import { personalData } from "https://esm.town/v/iamseeley/personalData";
const app = new Hono();
// JSX renderer middleware
app.use('*', jsxRenderer(({ children }) => {
return html`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>${personalData.name} | Server-side Hono</title>
<style>
${websiteStyles}
</style>
</head>
<body>
<header>
<h1>${personalData.name}</h1>
<p>${personalData.label}</p>
</header>
${children}
<footer>
<ul>
${personalData.profiles.map((profile, index) => html`
<li key=${index}>
<a href='${profile.url}' target="_blank" rel="noopener noreferrer">
${profile.network}
</a>
</li>
`)}
</ul>
</footer>
</body>
</html>`;
}));
// Navigation component
const Navigation: FC<{ currentPath: string }> = ({ currentPath }) => (
<nav>
{[
{ path: '/', text: 'Home' },
{ path: '/about', text: 'About' },
{ path: '/projects', text: 'Projects' }
].map(link => (
<a
key={link.path}
href={link.path}
class={currentPath === link.path ? 'active' : ''}
>
{link.text}
</a>
))}
</nav>
);
// Page components
const HomePage: FC = () => (
<>
<Navigation currentPath="/" />
<main>
<h2>Welcome to My Portfolio</h2>
<p>{personalData.summary}</p>
<p><strong>This website is rendered server-side with Hono.</strong></p>
<p>Check out the <a href='https://www.val.town/v/iamseeley/multirouteHono'>source</a> and start building your own site!</p>
</main>
</>
);
const AboutPage: FC = () => (
<>
<Navigation currentPath="/about" />
<main>
<h2>About Me</h2>
<p>{personalData.about}</p>
</main>
</>
);
const ProjectsPage: FC = () => (
<>
<Navigation currentPath="/projects" />
<main>
<h2>My Projects</h2>
{personalData.projects.map((project, index) => (
<a key={index} href={project.url} target="_blank" class="projectLink">
<div class="project">
<h3>{project.name}</h3>
<p>{project.description}</p>
</div>
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!
June 25, 2024