X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=src%2Ftemplate%2Ftemplate-helper.js;h=2da05dfb928007fa1f080bb35c7ab4770262d9f2;hb=e23bda592175ae5ed772f366069ccfd2f60e1f70;hp=23b0f12b37f84c6700fe9edd9f9b5851c014a225;hpb=41ae00113d39abada54823b7133c473b8fb758f5;p=websub-hub
diff --git a/src/template/template-helper.js b/src/template/template-helper.js
index 23b0f12..2da05df 100644
--- a/src/template/template-helper.js
+++ b/src/template/template-helper.js
@@ -5,10 +5,10 @@ const { Message } = require('../enum');
/**
* Render a topic as a row of details.
- * @param {Object} topic
- * @param {Object[]} subscribers
- * @param {Boolean} detailsLink
- * @returns {String}
+ * @param {object} topic topic
+ * @param {object[]} subscribers subscribers
+ * @param {boolean} detailsLink link to details
+ * @returns {string} html
*/
function renderTopicRow(topic, subscribers, detailsLink = true) {
if (!topic) {
@@ -38,7 +38,7 @@ function renderTopicRow(topic, subscribers, detailsLink = true) {
/**
* Render the header row for topic details.
- * @returns {String}
+ * @returns {string} html
*/
function renderTopicRowHeader() {
return `
@@ -63,8 +63,8 @@ function renderTopicRowHeader() {
/**
* Render a subscription as a row of details.
- * @param {Object} subscription
- * @returns {String}
+ * @param {object} subscription subscription
+ * @returns {string} html
*/
function renderSubscriptionRow(subscription) {
if (!subscription) {
@@ -73,7 +73,7 @@ function renderSubscriptionRow(subscription) {
`;
}
return `
- ${subscription.callback} |
+ ${subscription.callback} |
${TemplateHelper.dateFormat(subscription.created, Message.EndOfTime, Message.BeginningOfTime, Message.Unknown)} |
${TemplateHelper.dateFormat(subscription.verified, Message.EndOfTime, Message.Never, Message.Never)} |
${TemplateHelper.dateFormat(subscription.expires, Message.Never, Message.BeginningOfTime, Message.Never)} |
@@ -91,7 +91,7 @@ function renderSubscriptionRow(subscription) {
/**
* Render a row of headers for subscription details.
- * @returns {String}
+ * @returns {string} html
*/
function renderSubscriptionRowHeader() {
return `
@@ -114,7 +114,8 @@ function renderSubscriptionRowHeader() {
/**
* Escape some xml things in strings.
- * @param {String} string
+ * @param {string} string string to escape
+ * @returns {string} escaped
*/
function xmlEscape(string) {
if (typeof string === 'number') {
@@ -133,10 +134,33 @@ function xmlEscape(string) {
}[c]));
}
+
+/**
+ * Add common site links to navigation header.
+ * @param {number} pagePathLevel depth from root
+ * @param {object} ctx context
+ * @param {object} options options
+ */
+function navLinks(pagePathLevel, ctx, options) {
+ if (!options.navLinks) {
+ options.navLinks = [];
+ }
+ const rootPath = '../'.repeat(pagePathLevel);
+
+ if (options.pageIdentifier !== 'admin') {
+ options.navLinks.push({
+ text: 'Admin',
+ href: `${rootPath}admin/`,
+ });
+ }
+}
+
+
module.exports = Object.assign(Object.create(TemplateHelper), {
+ navLinks,
xmlEscape,
renderTopicRowHeader,
renderTopicRow,
renderSubscriptionRowHeader,
renderSubscriptionRow,
-});
\ No newline at end of file
+});