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
/**
* This application creates a CSV viewer using a Hono app that serves a client-side application.
* It allows users to upload a CSV file, view its contents in a table format, and provides basic sorting functionality.
*
* The approach:
* 1. Create a server-side Hono app to handle file uploads and serve the HTML, CSS, and JavaScript.
* 2. Implement client-side JavaScript to handle file reading, parsing CSV, and displaying the data in a table.
* 3. Add sorting functionality to allow users to sort the table by clicking on column headers.
*
* Libraries used:
* - Hono for the server-side application
* - Papa Parse (via esm.sh) for parsing CSV on the client-side
*/
import { serve } from 'https://esm.town/v/g/serveUtils';
import { Hono } from 'npm:hono';
function html() {
/*
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSV Viewer</title>
<link rel="stylesheet" href="/styles.css">
<script type="module" src="/main.js" defer></script>
</head>
<body>
<div class="container">
<h1>CSV Viewer</h1>
<input type="file" id="csvFile" accept=".csv">
<div id="tableContainer"></div>
</div>
</body>
</html>
*/
}
function css() {
/*
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
.container {
max-width: 800px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
color: #333;
}
input[type="file"] {
display: block;
margin: 20px auto;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
font-weight: bold;
cursor: pointer;
}
th:hover {
background-color: #e6e6e6;
}
tr:nth-child(even) {
background-color: #f8f8f8;
}
tr:hover {
background-color: #f0f0f0;
}
*/
}