* @param {Object} ctx
* @param {Object} options
* @param {String[]=} options.logoUrl
+ * @param {String[]=} options.logoAlt
* @param {String[]=} options.pageTitle
* @returns {String}
*/
const rootPathPfx = '../'.repeat(pagePathLevel);
const {
logoUrl = '',
+ logoAlt = 'logo',
pageTitle = '',
} = options;
- const logoImg = logoUrl ? `<img src="${rootPathPfx}${logoUrl}" class="logo">` : '';
+ const logoImg = logoUrl ? `<img src="${rootPathPfx}${logoUrl}" alt="logo" class="${logoAlt}">` : '';
return `\t\t<header>
\t\t\t<h1>${logoImg}${pageTitle}</h1>
${htmlNav(ctx, options)}
* @param {String[]=} options.notificationContent
*/
function htmlMessages(ctx, options) {
- const errorHeading = options && options.errorHeading ? `
+ const errorHeading = options?.errorHeading ? `
\t<h2>${options.errorHeading}</h2>` : '';
- const errorContent = options && options.errorContent && options.errorContent.length ? '\n' + options.errorContent.map(((content) => `\t${content}`)).join('\n') : '';
- const notificationHeading = options && options.notificationHeading ? `\n\t<h2>${options.notificationHeading}</h2>` : '';
- const notificationContent = options && options.notificationContent && options.notificationContent.length ? '\n' + options.notificationContent.map(((content) => `\t${content}`)).join('\n') : '';
- const errors = ctx && ctx.errors && ctx.errors.length ? `
+ const errorContent = options?.errorContent?.length ? '\n' + options.errorContent.map(((content) => `\t${content}`)).join('\n') : '';
+ const notificationHeading = options?.notificationHeading ? `\n\t<h2>${options.notificationHeading}</h2>` : '';
+ const notificationContent = options?.notificationContent?.length ? '\n' + options.notificationContent.map(((content) => `\t${content}`)).join('\n') : '';
+ const errors = ctx?.errors?.length ? `
<section class="error">${errorHeading}${errorContent}
${UL(ctx.errors, 1)}
</section>` : '';
- const notifications = ctx && ctx.notifications && ctx.notifications.length ? `
+ const notifications = ctx?.notifications?.length ? `
<section class="notification">${notificationHeading}${notificationContent}
${UL(ctx.notifications, 1)}
</section>` : '';
* @param {Object} options
* @param {String=} options.pageTitle
* @param {String=} options.logoUrl
+ * @param {String=} options.logoAlt
* @param {Object[]=} options.bodyAttributes
* @param {String[]=} options.headElements
* @param {Object[]=} options.navLinks
* @returns {String}
*/
function htmlPage(pagePathLevel, ctx, options, main = []) {
- const user = (ctx && ctx.session && ctx.session.authenticatedProfile) || (ctx && ctx.session && ctx.session.authenticatedIdentifier);
+ const user = ctx?.session?.authenticatedProfile || ctx?.session?.authenticatedIdentifier;
if (user) {
if (!options.navLinks) {
options.navLinks = [];
}
- const logoutRedirect = ctx && ctx.url ? `?r=${encodeURIComponent(ctx.url)}` : '';
- const logoutPath = (pagePathLevel > 0) ? `${'../'.repeat(pagePathLevel - 1)}` : 'admin/';
+ const logoutRedirect = ctx?.url ? `?r=${encodeURIComponent(ctx.url)}` : '';
+ const adminPath = (pagePathLevel > 0) ? `${'../'.repeat(pagePathLevel - 1)}` : 'admin/';
options.navLinks.push({
+ text: 'Account',
+ href: `${adminPath}settings`,
+ }, {
text: `Logout (${user})`,
- href: `${logoutPath}logout${logoutRedirect}`,
+ href: `${adminPath}logout${logoutRedirect}`,
});
}