openvibers/openvibe.media Commits
Share the content-hashed Media card (#312)
Changes
@@@ -15,11 +15,13 @@ const config = require('../config');const ovServe = require('openvibe-shared/serve');const shell = require('openvibe-shared/shell');const seoLib = require('openvibe-shared/seo');++const social = require('openvibe-shared/social');const appIcon = require('openvibe-shared/app-icon');const NETWORK_URL = (config.network && config.network.url) || 'https://openvibe.network';const SITE_NAME = 'OpenVibe.Media';--const DEFAULT_OG_IMAGE = `${config.publicUrl}/og-image.png`;++// The site's content-hashed share card (openvibe-shared/social), served from this site's own /shared copy.++const DEFAULT_OG_IMAGE = `${config.publicUrl}${social.url('media')}`;// Public base URL per app for canonical / "source" links (env-overridable JSON map).const APP_PUBLIC_URLS = (() => {@@@ -169,6 +169,12 @@ const http = require('http');assert.deepStrictEqual([r.status, r.headers.location], [301, 'https://openvibe.community/p/slug1'], 'the paste page is a redirect, no row needed');r = await get('/', nav);assert.strictEqual(r.status, 200);++ const shareImage = /<meta property="og:image" content="([^"]+)">/.exec(r.body)?.[1] || '';++ assert.match(shareImage, /^https:\/\/media\.test\/shared\/social\/media\.jpg\?v=[0-9a-f]{12}$/);++ assert.ok(r.body.includes('<meta property="og:image:width" content="1200">'));++ assert.ok(r.body.includes('<meta property="og:image:height" content="630">'));++ assert.ok(r.body.includes('<meta name="twitter:card" content="summary_large_image">'));++ assert.ok(r.body.includes(`<meta name="twitter:image" content="${shareImage}">`));const ld = [...r.body.matchAll(/<script type="application\/ld\+json">([\s\S]*?)<\/script>/g)].flatMap((m) => JSON.parse(m[1])['@graph'] || []);assert.ok(ld.some((x) => x['@type'] === 'WebSite'), 'the index names the site');const org = ld.find((x) => x['@type'] === 'Organization');
@@ -15,11 +15,13 @@ const config = require('../config');
@@ -15,11 +15,13 @@ const config = require('../config');
const ovServe = require('openvibe-shared/serve');
const ovServe = require('openvibe-shared/serve');
const shell = require('openvibe-shared/shell');
const shell = require('openvibe-shared/shell');
const seoLib = require('openvibe-shared/seo');
const seoLib = require('openvibe-shared/seo');
+const social = require('openvibe-shared/social');
const appIcon = require('openvibe-shared/app-icon');
const appIcon = require('openvibe-shared/app-icon');
const NETWORK_URL = (config.network && config.network.url) || 'https://openvibe.network';
const NETWORK_URL = (config.network && config.network.url) || 'https://openvibe.network';
const SITE_NAME = 'OpenVibe.Media';
const SITE_NAME = 'OpenVibe.Media';
-const DEFAULT_OG_IMAGE = `${config.publicUrl}/og-image.png`;
+// The site's content-hashed share card (openvibe-shared/social), served from this site's own /shared copy.
+const DEFAULT_OG_IMAGE = `${config.publicUrl}${social.url('media')}`;
// Public base URL per app for canonical / "source" links (env-overridable JSON map).
// Public base URL per app for canonical / "source" links (env-overridable JSON map).
const APP_PUBLIC_URLS = (() => {
const APP_PUBLIC_URLS = (() => {
@@ -169,6 +169,12 @@ const http = require('http');
@@ -169,6 +169,12 @@ const http = require('http');
assert.deepStrictEqual([r.status, r.headers.location], [301, 'https://openvibe.community/p/slug1'], 'the paste page is a redirect, no row needed');
assert.deepStrictEqual([r.status, r.headers.location], [301, 'https://openvibe.community/p/slug1'], 'the paste page is a redirect, no row needed');
r = await get('/', nav);
r = await get('/', nav);
assert.strictEqual(r.status, 200);
assert.strictEqual(r.status, 200);
+ const shareImage = /<meta property="og:image" content="([^"]+)">/.exec(r.body)?.[1] || '';
+ assert.match(shareImage, /^https:\/\/media\.test\/shared\/social\/media\.jpg\?v=[0-9a-f]{12}$/);
+ assert.ok(r.body.includes('<meta property="og:image:width" content="1200">'));
+ assert.ok(r.body.includes('<meta property="og:image:height" content="630">'));
+ assert.ok(r.body.includes('<meta name="twitter:card" content="summary_large_image">'));
+ assert.ok(r.body.includes(`<meta name="twitter:image" content="${shareImage}">`));
const ld = [...r.body.matchAll(/<script type="application\/ld\+json">([\s\S]*?)<\/script>/g)].flatMap((m) => JSON.parse(m[1])['@graph'] || []);
const ld = [...r.body.matchAll(/<script type="application\/ld\+json">([\s\S]*?)<\/script>/g)].flatMap((m) => JSON.parse(m[1])['@graph'] || []);
assert.ok(ld.some((x) => x['@type'] === 'WebSite'), 'the index names the site');
assert.ok(ld.some((x) => x['@type'] === 'WebSite'), 'the index names the site');
const org = ld.find((x) => x['@type'] === 'Organization');
const org = ld.find((x) => x['@type'] === 'Organization');