auth cleanups
[urlittler] / src / template / info-html.js
1 'use strict';
2
3 const { TemplateHelper: th } = require('@squeep/html-template-helper');
4
5 const toDateString = (ts) => {
6 try {
7 return (ts && isFinite(ts)) ? (new Date(ts * 1000).toISOString()) : 'never';
8 } catch (e) { // eslint-disable-line no-unused-vars
9 return `(whatever '${ts.toString()}' is)`;
10 }
11 };
12
13
14 /**
15 *
16 * @param {object} details link details
17 * @returns {string} HTML details section
18 */
19 function renderDetailsSection(details) {
20 const created = toDateString(details.created);
21 const lastAccess = toDateString(details.lastAccess);
22 const expires = details.expires ? toDateString(details.expires) : '';
23
24 return `<section>
25 \t<div class="identifier">id: <span><a href="/${details.id}">${details.id}</a></span></div>
26 \t<div class="url">url: <span>${details.url}</span></div>
27 \t<div class="created">created: <time datetime="${created}">${created}</time></div>
28 \t<div class="accesses">accesses: <span>${details.accesses}</span></div>
29 \t<div class="lastaccess">last access: <time datetime="${lastAccess}">${lastAccess}</time></div>` +
30 (!details.expires ? '' : `
31 \t<div class="expires">expires: <time datetime="${expires}">${expires}</time></div>`) + `
32 </section>`;
33 }
34
35 module.exports = (ctx, details, pageTitle) => {
36 const pagePathLevel = 1;
37 const htmlOptions = {
38 pageIdentifier: 'details',
39 pageTitle,
40 footerEntries: [],
41 headElements: [],
42 };
43
44 const main = [
45 renderDetailsSection(details),
46 ];
47 return th.htmlPage(pagePathLevel, ctx, htmlOptions, main);
48 };