openvibers/openvibe.bot Commits
A shared /try link shows Bot's card: panel pages with a description carry og:url, og:image and a large Twitter card (#151)
Changes
@@@ -22,6 +22,7 @@*/const { qrSvg } = require('./qr');const { stepHelp } = require('../routines');++const social = require('openvibe-shared/social');const ESC = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ESC[c]);/** A data-* attribute's JSON, escaped for a double-quoted attribute. */@@@ -72,7 +73,10 @@ function page(title, body, { scripts = [], bodyClass = '', description = null, c<meta name="description" content="${esc(description)}"><meta property="og:title" content="${esc(title)} — OpenVibe.Bot"><meta property="og:description" content="${esc(description)}">` : ''}${canonical ? `--<link rel="canonical" href="https://openvibe.bot${esc(canonical)}">` : ''}++<link rel="canonical" href="https://openvibe.bot${esc(canonical)}">` : ''}${description && canonical ? `++<meta property="og:url" content="https://openvibe.bot${esc(canonical)}">++<meta property="og:image" content="https://openvibe.bot${esc(social.url('bot'))}">++<meta name="twitter:card" content="summary_large_image">` : ''}<link rel="stylesheet" href="/panel/panel.css"></head><body${bodyClass ? ` class="${esc(bodyClass)}"` : ''}>@@@ -55,6 +55,7 @@ const { loadProfiles } = require('../server/profiles');assert.ok(json, 'the profile rides along as data');assert.deepStrictEqual(JSON.parse(json[1]), loadProfiles().get('sim.rover'));assert.ok(html.includes('<link rel="canonical" href="https://openvibe.bot/try">') && html.includes('<meta name="description"'));++ assert.ok(/<meta property="og:image" content="https:\/\/openvibe\.bot\/shared\/social\/bot\.jpg(\?v=[^"]+)?">/.test(html) && html.includes('<meta property="og:url" content="https://openvibe.bot/try">'), 'a shared /try link shows Bot\'s card');assert.ok(html.includes('href="/robots/new"'), 'the way on to a real robot');for (const s of scripts) {const js = await get(s);
@@ -22,6 +22,7 @@
@@ -22,6 +22,7 @@
*/
*/
const { qrSvg } = require('./qr');
const { qrSvg } = require('./qr');
const { stepHelp } = require('../routines');
const { stepHelp } = require('../routines');
+const social = require('openvibe-shared/social');
const ESC = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
const ESC = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ESC[c]);
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ESC[c]);
/** A data-* attribute's JSON, escaped for a double-quoted attribute. */
/** A data-* attribute's JSON, escaped for a double-quoted attribute. */
@@ -72,7 +73,10 @@ function page(title, body, { scripts = [], bodyClass = '', description = null, c
@@ -72,7 +73,10 @@ function page(title, body, { scripts = [], bodyClass = '', description = null, c
<meta name="description" content="${esc(description)}">
<meta name="description" content="${esc(description)}">
<meta property="og:title" content="${esc(title)} — OpenVibe.Bot">
<meta property="og:title" content="${esc(title)} — OpenVibe.Bot">
<meta property="og:description" content="${esc(description)}">` : ''}${canonical ? `
<meta property="og:description" content="${esc(description)}">` : ''}${canonical ? `
-<link rel="canonical" href="https://openvibe.bot${esc(canonical)}">` : ''}
+<link rel="canonical" href="https://openvibe.bot${esc(canonical)}">` : ''}${description && canonical ? `
+<meta property="og:url" content="https://openvibe.bot${esc(canonical)}">
+<meta property="og:image" content="https://openvibe.bot${esc(social.url('bot'))}">
+<meta name="twitter:card" content="summary_large_image">` : ''}
<link rel="stylesheet" href="/panel/panel.css">
<link rel="stylesheet" href="/panel/panel.css">
</head>
</head>
<body${bodyClass ? ` class="${esc(bodyClass)}"` : ''}>
<body${bodyClass ? ` class="${esc(bodyClass)}"` : ''}>
@@ -55,6 +55,7 @@ const { loadProfiles } = require('../server/profiles');
@@ -55,6 +55,7 @@ const { loadProfiles } = require('../server/profiles');
assert.ok(json, 'the profile rides along as data');
assert.ok(json, 'the profile rides along as data');
assert.deepStrictEqual(JSON.parse(json[1]), loadProfiles().get('sim.rover'));
assert.deepStrictEqual(JSON.parse(json[1]), loadProfiles().get('sim.rover'));
assert.ok(html.includes('<link rel="canonical" href="https://openvibe.bot/try">') && html.includes('<meta name="description"'));
assert.ok(html.includes('<link rel="canonical" href="https://openvibe.bot/try">') && html.includes('<meta name="description"'));
+ assert.ok(/<meta property="og:image" content="https:\/\/openvibe\.bot\/shared\/social\/bot\.jpg(\?v=[^"]+)?">/.test(html) && html.includes('<meta property="og:url" content="https://openvibe.bot/try">'), 'a shared /try link shows Bot\'s card');
assert.ok(html.includes('href="/robots/new"'), 'the way on to a real robot');
assert.ok(html.includes('href="/robots/new"'), 'the way on to a real robot');
for (const s of scripts) {
for (const s of scripts) {
const js = await get(s);
const js = await get(s);