const { lazy } = require('@squeep/lazy-property');
+
+/**
+ * Set up expected fields for how we handle error reporting
+ * and whatnot.
+ * @param {Object} ctx
+ */
+const initContext = (ctx) => {
+ ctx.errors = [];
+ ctx.notifications = [];
+};
+
/**
* Some fields may have values outside normal dates, handle them here.
* @param {Date} date
});
+/**
+ * Wrap a Date in a <time> block.
+ * @param {Date} date
+ * @param {Object} options
+ * @param {String=} options.title
+ */
+const timeElement = (date, options = {}) => {
+ const {
+ title,
+ pInf,
+ nInf,
+ otherwise,
+ } = options;
+ const attributes = {
+ ...(title && { title }),
+ ...(date instanceof Date && { datetime: date.toISOString() }),
+ };
+ return [
+ '<time',
+ elementAttributes(attributes),
+ '>',
+ dateFormat(date, pInf, nInf, otherwise),
+ '</time>',
+ ].join('');
+};
+
+
/**
* Render a duration.
* @param {Number} seconds
result.push(`${r} ${label}${r != 1 ? 's' : ''}`);
}
value = factor ? Math.floor(value / factor) : value;
- }
+ };
nextResult(60, 'second');
nextResult(60, 'minute');
return `\t<head>
\t\t<meta charset="utf-8">
\t\t<meta name="viewport" content="width=device-width,initial-scale=1">
-\t\t<link rel="stylesheet" href="${rootPathPfx}static/theme.css" title="Default">
-\t\t<link rel="stylesheet" href="${rootPathPfx}static/custom.css" title="Site Specific">
+\t\t<link rel="stylesheet" href="${rootPathPfx}static/theme.css">
+\t\t<link rel="stylesheet" href="${rootPathPfx}static/custom.css">
${headElements.map((e) => '\t\t' + e).join('\n')}
\t\t<title>${pageTitle}</title>
\t</head>`;
module.exports = {
+ initContext,
dateOrNot,
dateFormat,
+ timeElement,
secondsToPeriod,
htmlHead,
htmlBody,