iamseeley-multiroutesvelte.web.val.run
Readme

🌐 Multi-Route Website with Svelte

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 Svelte
* @description Create a personal portfolio website with multiple pages using Svelte and server-side rendering.
*/
import * as svelte from 'npm:svelte/compiler';
import { create_ssr_component, escape, validate_component } from 'npm:svelte/internal';
import { websiteStyles } from "https://esm.town/v/iamseeley/websiteStyles";
import { personalData } from "https://esm.town/v/iamseeley/personalData";
// Navigation component
const Navigation = create_ssr_component(($$result, $$props, $$bindings, slots) => {
const { currentPath } = $$props;
const links = [
{ path: '/', text: 'Home' },
{ path: '/about', text: 'About' },
{ path: '/projects', text: 'Projects' }
];
return `<nav>
${links.map(link => `<a href="${escape(link.path)}" class="${escape(currentPath === link.path ? 'active' : '')}">${escape(link.text)}</a>`).join('')}
</nav>`;
});
// Page components
const HomePage = create_ssr_component(($$result, $$props, $$bindings, slots) => {
return `
${validate_component(Navigation, 'Navigation').$$render($$result, { currentPath: '/' }, {}, {})}
<main>
<h2>Welcome to My Portfolio</h2>
<p>${personalData.summary}</p>
<p><strong>This website is rendered server-side with Svelte.</strong></p>
<p>Check out the <a href='https://www.val.town/v/iamseeley/multirouteSvelte'>source</a> and start building your own site!</p>
</main>
`;
});
const AboutPage = create_ssr_component(($$result, $$props, $$bindings, slots) => {
return `
${validate_component(Navigation, 'Navigation').$$render($$result, { currentPath: '/about' }, {}, {})}
<main>
<h2>About Me</h2>
<p>${personalData.about}</p>
</main>
`;
});
const ProjectsPage = create_ssr_component(($$result, $$props, $$bindings, slots) => {
return `
${validate_component(Navigation, 'Navigation').$$render($$result, { currentPath: '/projects' }, {}, {})}
<main>
<h2>My Projects</h2>
${personalData.projects.map(project => `
<a href="${project.url}" target="_blank" class="projectLink">
<div class="project">
<h3>${project.name}</h3>
<p>${project.description}</p>
</div>
</a>
`).join('')}
</main>
`;
});
const NotFoundPage = create_ssr_component(($$result, $$props, $$bindings, slots) => {
return `
${validate_component(Navigation, 'Navigation').$$render($$result, { currentPath: '' }, {}, {})}
<main>
<h2>404 Not Found</h2>
<p>Sorry, the page you're looking for doesn't exist.</p>
<a href="/">Return to Home</a>
</main>
`;
});
// Main handler function
export default function (req: Request): Response {
const url = new URL(req.url);
let component;
switch (url.pathname) {
case '/':
component = HomePage;
break;
case '/about':
component = AboutPage;
break;
case '/projects':
component = ProjectsPage;
break;
default:
component = NotFoundPage;
}
const { html: appContent } = component.render();
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
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 26, 2024