import { websiteStyles } from "https://esm.town/v/iamseeley/websiteStyles";
import { personalData } from "https://esm.town/v/iamseeley/personalData";
import { generateTrackingHtml } from 'https://esm.town/v/iamseeley/counterTown';
export default async function (req: Request): Promise<Response> {
const url = new URL(req.url);
const path = url.pathname;
function createNavLinks(currentPath: string): string {
const links = [
{ path: '/', text: 'Home' },
{ path: '/about', text: 'About' },
{ path: '/projects', text: 'Projects' }
];
return links.map(link =>
`<a href="${link.path}" class="${currentPath === link.path ? 'active' : ''}">${link.text}</a>`
).join('');
}
const trackingHtmlResponse = generateTrackingHtml(req);
const trackingHtml = await trackingHtmlResponse.text();
function createHTML(title: string, content: string, req: Request): string {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${personalData.name} | HTML as String</title>
<style>
${websiteStyles}
</style>
</head>
<body>
<header>
<h1>${personalData.name}</h1>
<p>${personalData.label}</p>
</header>
<nav>
${createNavLinks(path)}
</nav>
<main>
${content}
</main>
<footer>
<ul>
${personalData.profiles.map((profile, index) => `
<li key={${index}}>
<a href='${profile.url}' target="_blank" rel="noopener noreferrer">
${profile.network}
</a>
</li>
`).join('')}
</ul>
</footer>
${trackingHtml}
</body>
</html>
`;
}
function router(path: string, req: Request): Response {
switch (path) {
case '/':
return homePage(req);
case '/about':
return aboutPage(req);
case '/projects':
return projectsPage(req);
default:
return notFoundPage(req);
}
}
function homePage(req: Request): Response {
const content = `
<h2>Welcome to My Portfolio</h2>
<p>${personalData.summary}</p>
<p><strong>This website is rendered server-side with pure HTML.</strong></p>
<p>Check out the <a href='https://www.val.town/v/iamseeley/multirouteHTML'>source</a> and start building your own site!</p>
`;
return new Response(createHTML("Home", content, req), {
headers: { "Content-Type": "text/html" },
});
}
function aboutPage(req: Request): Response {