openvibers/openvibe.mail Commits
The navbar takes its service and name from the Contracts site block (#4)
Changes
@@@ -16,11 +16,27 @@ const express = require('express');const shell = require('openvibe-shared/shell');const ovServe = require('openvibe-shared/serve');const cache = require('openvibe-shared/cache-policy');++const contracts = require('openvibe-contracts');const PUBLIC_DIR = path.join(__dirname, '..', '..', 'public');--const SITE_NAME = 'OpenVibe.Email';const NETWORK_URL = 'https://openvibe.network';++/**++ * The navbar's service id and display name from the site block in OpenVibe.Contracts (the `mail` manifest), with the++ * names the page shipped with before that manifest existed. The site block says "Email", so the page reads++ * "OpenVibe.Email"; the service id is what Shared's navbar, history and theme use.++ */++function siteIdentity(manifest) {++ const short = manifest && manifest.site && manifest.site.name;++ return {++ service: (manifest && manifest.id) || 'mail',++ name: short ? (/^Open[A-Z]/.test(short) ? short : `OpenVibe.${short}`) : 'OpenVibe.Email',++ };++}++const SITE = siteIdentity(contracts.services && contracts.services.get && contracts.services.get('mail'));++const SITE_NAME = SITE.name;++const SERVICE = SITE.service;++const hashes = new Map();function assetVersion(rel) {if (hashes.has(rel)) return hashes.get(rel);@@@ -51,7 +67,7 @@ const BODY = fs.readFileSync(path.join(__dirname, '..', 'views', 'home.html'), 'function homePage(config) {const base = String(config.baseUrl || 'https://openvibe.email').replace(/\/+$/, '');const nav = {-- service: 'mail',++ service: SERVICE,apiBase: NETWORK_URL,links: [{ label: 'Home', href: '/', active: true }],history: { type: 'page', title: SITE_NAME },@@@ -60,7 +76,7 @@ function homePage(config) {loginUrl: '/auth/login?next={path}',logoutUrl: '/auth/logout?next={path}',};-- const footer = { service: 'mail', variant: 'full', mount: '#ov-footer', brandName: SITE_NAME };++ const footer = { service: SERVICE, variant: 'full', mount: '#ov-footer', brandName: SITE_NAME };return shell.page({name: SITE_NAME,lang: 'en',@@@ -110,4 +126,4 @@ function mountPages(app, { config }) {});}--module.exports = { mountPages, homePage, CSP, asset };++module.exports = { mountPages, homePage, siteIdentity, CSP, asset };@@@ -7,7 +7,13 @@const test = require('node:test');const assert = require('node:assert');const { boot } = require('./helpers/boot');--const { asset } = require('../server/http/pages');++const { asset, siteIdentity } = require('../server/http/pages');++++test('the navbar takes its service and name from the Contracts site block', () => {++ assert.deepStrictEqual(siteIdentity({ id: 'mail', site: { name: 'Email' } }), { service: 'mail', name: 'OpenVibe.Email' });++ assert.deepStrictEqual(siteIdentity({ id: 'mail', site: { name: 'OpenVibe.Post' } }), { service: 'mail', name: 'OpenVibe.Post' }, 'a brand name is not doubled');++ assert.deepStrictEqual(siteIdentity(null), { service: 'mail', name: 'OpenVibe.Email' }, 'before the manifest is pinned, the page keeps the names it shipped with');++});test('/ is the page: the ten-minute address, the honest cards, the navbar, a strict policy', async (t) => {const s = await boot();
@@ -16,11 +16,27 @@ const express = require('express');
@@ -16,11 +16,27 @@ const express = require('express');
const shell = require('openvibe-shared/shell');
const shell = require('openvibe-shared/shell');
const ovServe = require('openvibe-shared/serve');
const ovServe = require('openvibe-shared/serve');
const cache = require('openvibe-shared/cache-policy');
const cache = require('openvibe-shared/cache-policy');
+const contracts = require('openvibe-contracts');
const PUBLIC_DIR = path.join(__dirname, '..', '..', 'public');
const PUBLIC_DIR = path.join(__dirname, '..', '..', 'public');
-const SITE_NAME = 'OpenVibe.Email';
const NETWORK_URL = 'https://openvibe.network';
const NETWORK_URL = 'https://openvibe.network';
+/**
+ * The navbar's service id and display name from the site block in OpenVibe.Contracts (the `mail` manifest), with the
+ * names the page shipped with before that manifest existed. The site block says "Email", so the page reads
+ * "OpenVibe.Email"; the service id is what Shared's navbar, history and theme use.
+ */
+function siteIdentity(manifest) {
+ const short = manifest && manifest.site && manifest.site.name;
+ return {
+ service: (manifest && manifest.id) || 'mail',
+ name: short ? (/^Open[A-Z]/.test(short) ? short : `OpenVibe.${short}`) : 'OpenVibe.Email',
+ };
+}
+const SITE = siteIdentity(contracts.services && contracts.services.get && contracts.services.get('mail'));
+const SITE_NAME = SITE.name;
+const SERVICE = SITE.service;
+
const hashes = new Map();
const hashes = new Map();
function assetVersion(rel) {
function assetVersion(rel) {
if (hashes.has(rel)) return hashes.get(rel);
if (hashes.has(rel)) return hashes.get(rel);
@@ -51,7 +67,7 @@ const BODY = fs.readFileSync(path.join(__dirname, '..', 'views', 'home.html'), '
@@ -51,7 +67,7 @@ const BODY = fs.readFileSync(path.join(__dirname, '..', 'views', 'home.html'), '
function homePage(config) {
function homePage(config) {
const base = String(config.baseUrl || 'https://openvibe.email').replace(/\/+$/, '');
const base = String(config.baseUrl || 'https://openvibe.email').replace(/\/+$/, '');
const nav = {
const nav = {
- service: 'mail',
+ service: SERVICE,
apiBase: NETWORK_URL,
apiBase: NETWORK_URL,
links: [{ label: 'Home', href: '/', active: true }],
links: [{ label: 'Home', href: '/', active: true }],
history: { type: 'page', title: SITE_NAME },
history: { type: 'page', title: SITE_NAME },
@@ -60,7 +76,7 @@ function homePage(config) {
@@ -60,7 +76,7 @@ function homePage(config) {
loginUrl: '/auth/login?next={path}',
loginUrl: '/auth/login?next={path}',
logoutUrl: '/auth/logout?next={path}',
logoutUrl: '/auth/logout?next={path}',
};
};
- const footer = { service: 'mail', variant: 'full', mount: '#ov-footer', brandName: SITE_NAME };
+ const footer = { service: SERVICE, variant: 'full', mount: '#ov-footer', brandName: SITE_NAME };
return shell.page({
return shell.page({
name: SITE_NAME,
name: SITE_NAME,
lang: 'en',
lang: 'en',
@@ -110,4 +126,4 @@ function mountPages(app, { config }) {
@@ -110,4 +126,4 @@ function mountPages(app, { config }) {
});
});
}
}
-module.exports = { mountPages, homePage, CSP, asset };
+module.exports = { mountPages, homePage, siteIdentity, CSP, asset };
@@ -7,7 +7,13 @@
@@ -7,7 +7,13 @@
const test = require('node:test');
const test = require('node:test');
const assert = require('node:assert');
const assert = require('node:assert');
const { boot } = require('./helpers/boot');
const { boot } = require('./helpers/boot');
-const { asset } = require('../server/http/pages');
+const { asset, siteIdentity } = require('../server/http/pages');
+
+test('the navbar takes its service and name from the Contracts site block', () => {
+ assert.deepStrictEqual(siteIdentity({ id: 'mail', site: { name: 'Email' } }), { service: 'mail', name: 'OpenVibe.Email' });
+ assert.deepStrictEqual(siteIdentity({ id: 'mail', site: { name: 'OpenVibe.Post' } }), { service: 'mail', name: 'OpenVibe.Post' }, 'a brand name is not doubled');
+ assert.deepStrictEqual(siteIdentity(null), { service: 'mail', name: 'OpenVibe.Email' }, 'before the manifest is pinned, the page keeps the names it shipped with');
+});
test('/ is the page: the ten-minute address, the honest cards, the navbar, a strict policy', async (t) => {
test('/ is the page: the ten-minute address, the honest cards, the navbar, a strict policy', async (t) => {
const s = await boot();
const s = await boot();