initial commit
[urlittler] / src / template / report-html.js
1 'use strict';
2
3 const toDateString = (ts) => ts ? new Date(ts * 1000).toISOString() : 'never';
4
5 module.exports = (ctx, links, pageTitle) => {
6 return `<!DOCTYPE html>
7 <html lang="en">
8 <head>
9 <meta charset="utf-8">
10 <title>${pageTitle} - Link Report</title>
11 <link rel="stylesheet" href="../../static/theme.css">
12 </head>
13 <body>
14 <header>
15 <h1>Link Report</h1>
16 </header>
17 <main>
18 <table>
19 <thead>
20 <tr>
21 <th scope="col">id</th>
22 <th scope="col">url</th>
23 <th scope="col">accesses</th>
24 <th scope="col">created</th>
25 <th scope="col">expires</th>
26 <th scope="col">last access</th>
27 </tr>
28 </thead>
29 <tbody>` +
30 links.map((l) => `
31 <tr>
32 <th scope="row"><a href="/${l.id}/info">${l.id}</a></th>
33 <td>${l.url}</td>
34 <td>${l.accesses}</td>
35 <td>${toDateString(l.created)}</td>
36 <td>${toDateString(l.expires)}</td>
37 <td>${toDateString(l.lastAccess)}</td>
38 </tr>`).join('\n') + `
39 </tbody>
40 <table>
41 </main>
42 </body>
43 </html>`;
44 };