openvibers/openvibe.deals Commits
Render every page through openvibe-publishing/layout on shared shell
Changes
nnew file mode 100644@@@ -0,0 +1,5 @@++# Changelog++++## Unreleased++++- Every page is rendered through `openvibe-publishing/layout` (v1.2.0, on `openvibe-shared/shell` v2.6.0): the head, the Frame, the noscript navigation, the footer and its init come from the shared document; robots and the canonical still come from the indexability gate's decision. Styling is unchanged.@@@ -252,10 +252,10 @@ render time, so the cache stays short); signed-in views, forms, API responses, e- **PostgreSQL 18 and Valkey 9** (OpenVibe.Host `roles/data/`, ADR-035): every read and write is async through`openvibe-sdk/db`; Valkey holds the per-actor limit counters (optional: without `VALKEY_URL` they count per process).--- **Packages** (pinned release tarballs): `openvibe-publishing` v1.1.0 (seo gate, JSON-LD, feeds,++- **Packages** (pinned release tarballs): `openvibe-publishing` v1.2.0 (seo gate, JSON-LD, feeds,sitemaps, index-hooks, discussion, ssr, and the shared ingest/publication chassis — the Sourcesclient, change cursor and pull loop, signed event consumer, common normalisers, and the publication-- glue Deals' indexing uses), `openvibe-contracts` v0.79.0, `openvibe-shared` v2.2.0++ glue Deals' indexing uses), `openvibe-contracts` v0.79.0, `openvibe-shared` v2.6.0(Frame, app icon, footer, legal, release, metrics, ready), `openvibe-sdk` v0.25.1 (sso, outbox,inbox, webhook signatures v2, service tokens, per-actor limits).- **OpenVibe.Network:** SSO (OAuth client `deals`, registered in production), JWKS,@@@ -9,9 +9,9 @@"domain": "openvibe.deals","contracts": "openvibe-contracts v0.79.0","packages": [-- "openvibe-publishing v1.1.0",++ "openvibe-publishing v1.2.0","openvibe-contracts v0.79.0",-- "openvibe-shared v2.2.0",++ "openvibe-shared v2.6.0","openvibe-sdk v0.25.1"],"capabilities": [@@@ -16,9 +16,9 @@"helmet": "^8.1.0","iovalkey": "^0.4.0","openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.79.0",-- "openvibe-publishing": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v1.1.0",++ "openvibe-publishing": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v1.2.0","openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.26.0",-- "openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v2.5.0",++ "openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v2.6.0","pg": "^8.23.0"},"devDependencies": {@@@ -1163,9 +1163,8 @@}},"node_modules/openvibe-publishing": {-- "version": "1.1.0",-- "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v1.1.0",-- "integrity": "sha512-bJsVl82hDivazoiM/np9ckKJE4V5F4OxyIiDwB6xuhK8M6P42sGU+V88rFCkyiI4BVQiKv9xs4GVx8Fj3pyjsg==",++ "version": "1.2.0",++ "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v1.2.0","license": "MIT","engines": {"node": ">=20"@@@ -1210,9 +1209,9 @@}},"node_modules/openvibe-shared": {-- "version": "2.5.0",-- "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v2.5.0",-- "integrity": "sha512-fHuUS6SXM7ezatfAyqLm1V8B6puV9YXSnz6aG6XQbWx28qghRCCHeUF3lr4nxiCGdn9SyikYtIyLGL5r1ycp9Q==",++ "version": "2.6.0",++ "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v2.6.0",++ "integrity": "sha512-IKKvWTM/9UonQ4msrzM4yir0QcTUNbhyqeN1r5ywWavU4VTsL1sI5QdHQlxge7BAsMrQ4OvMEPlHjuAfUJM3rg==","license": "MIT","dependencies": {"jsonwebtoken": "^9.0.0"@@@ -27,9 +27,9 @@"helmet": "^8.1.0","iovalkey": "^0.4.0","openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.79.0",-- "openvibe-publishing": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v1.1.0",++ "openvibe-publishing": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v1.2.0","openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.26.0",-- "openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v2.5.0",++ "openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v2.6.0","pg": "^8.23.0"},"devDependencies": {@@@ -1,25 +1,29 @@'use strict';/**-- * Page shell. Every page is server-rendered through this and is complete without JavaScript:++ * Page shell. Every page is server-rendered through openvibe-publishing/layout (openvibe-shared/shell++ * page()) and is complete without JavaScript:* - <head>: title, description, canonical and robots from the indexability gate's decision-- * (openvibe-publishing/seo metaTags — there is no default that makes a page indexable),-- * Open Graph/Twitter, JSON-LD, feed links, the shared app icon and critical canvas-- * - the OpenVibe Frame: navbar.js and theme-loader.js from the Network (progressive), a-- * <noscript> navigation bar and the server-rendered shared footer (openvibe-shared)++ * (there is no default that makes a page indexable), Open Graph/Twitter, JSON-LD, prev/next,++ * feed links, the shared app icon, the site stylesheet and the boost marker++ * - the OpenVibe Frame: theme-loader, web runtime, navbar and footer from the Network++ * (progressive), a <noscript> navigation bar and the server-rendered shared footer*/const crypto = require('crypto');--const ovServe = require('openvibe-shared/serve');const fs = require('fs');const path = require('path');--const seo = require('openvibe-publishing/seo');--const { escapeHtml: esc } = require('openvibe-publishing/ssr');--const appIcon = require('openvibe-shared/app-icon');++const layout = require('openvibe-publishing/layout');const frame = require('openvibe-shared/frame');const NETWORK_URL = 'https://openvibe.network';const SITE_NAME = 'OpenVibe.Deals';const PUBLIC_DIR = path.join(__dirname, '..', '..', 'public');++const NAV_LINKS = [++ { label: 'Hot', href: '/' },++ { label: 'New', href: '/new' },++ { label: 'Submit', href: '/submit', icon: 'fa-plus' },++ { label: 'Watches', href: '/watches', icon: 'fa-bell' },++];const hashes = new Map();function assetVersion(rel) {@@@ -42,30 +46,13 @@ function setRelease(id) { if (id) RELEASE = String(id); }*/function renderPage(o) {if (!o.decision) throw new TypeError('renderPage needs the gate decision');-- const head = seo.metaTags({-- title: o.title ? `${o.title} · ${SITE_NAME}` : SITE_NAME,-- description: o.description || 'Deals submitted and voted on by the community, with source, price and freshness always shown.',-- decision: o.decision,-- canonical: o.canonical,-- type: o.type || 'website',-- siteName: SITE_NAME,-- image: o.image || undefined,-- prev: o.prev || undefined,-- next: o.next || undefined,-- jsonLd: (o.jsonLd || []).filter(Boolean),-- });const viewer = o.viewer || { kind: 'anonymous' };const signedIn = viewer.kind === 'user';const loginNext = encodeURIComponent(o.path || '/');const nav = {service: 'deals',apiBase: NETWORK_URL,-- links: [-- { label: 'Hot', href: '/' },-- { label: 'New', href: '/new' },-- { label: 'Submit', href: '/submit', icon: 'fa-plus' },-- { label: 'Watches', href: '/watches', icon: 'fa-bell' },-- ],++ links: NAV_LINKS,history: { type: 'page', title: o.title || SITE_NAME },silentLogin: `${o.config.baseUrl}/auth/login?silent=1&next={url}`,sessionUrl: '/auth/me',@@@ -80,40 +67,31 @@ function renderPage(o) {const account = signedIn? `${viewer.staff ? '<a href="/mod">Moderation</a> · ' : ''}<a href="/watches">Watches</a> · <a href="/auth/logout?next=${loginNext}">Sign out</a>`: `<a href="/auth/login?next=${loginNext}">Sign in with OpenVibe</a>`;-- return `<!DOCTYPE html>--<html lang="${esc(o.lang || 'en')}">--<head>--<meta charset="utf-8">--<meta name="viewport" content="width=device-width, initial-scale=1">--${head}--${seo.feedLinks(o.feeds || [])}--${appIcon.headTags({ site: 'deals' })}--<link rel="stylesheet" href="${asset('css/deals.css')}">--<script src="${ovServe.url('theme-loader.js')}" defer></script>--<script src="${ovServe.url('navbar.js')}" defer></script>--<script src="${ovServe.url('footer.js')}" defer></script>--<meta name="ov-boost" content="deals@${esc(RELEASE)}">--<script src="${ovServe.url('boost.js')}" data-main="#main" defer></script>--</head>--<body class="${esc(o.bodyClass || '')}">--<a class="skip" href="#main">Skip to content</a>--<div id="navbar-mount"></div>--${frame.noscriptNav({ name: SITE_NAME, home: '/', links: [{ label: 'Hot', href: '/' }, { label: 'New', href: '/new' }, { label: 'Submit', href: '/submit' }, { label: 'Watches', href: '/watches' }] })}--<noscript><div class="account-bar" role="navigation" aria-label="Account">${account}</div></noscript>--<main id="main" class="page">--${o.body || ''}--${o.path === '/' ? frame.shipped({ service: 'deals', title: `Recently shipped on ${SITE_NAME}` }) : ''}--</main>--${frame.footer(footer)}--<script>--window.__OV_PAGE = ${JSON.stringify({ navbar: nav, footer }).replace(/</g, '\\u003c')};--document.addEventListener('DOMContentLoaded', function () {-- try { if (window.OpenVibeNavbar) OpenVibeNavbar.init(window.__OV_PAGE.navbar); } catch (e) { /* the Frame is optional */ }-- try { if (window.OpenVibeFooter) OpenVibeFooter.init(window.__OV_PAGE.footer); } catch (e) { /* */ }--});--</script>--</body>--</html>`;++ return layout.renderDocument({++ site: 'deals',++ siteName: SITE_NAME,++ lang: o.lang,++ title: o.title ? `${o.title} · ${SITE_NAME}` : SITE_NAME,++ description: o.description || 'Deals submitted and voted on by the community, with source, price and freshness always shown.',++ canonical: o.canonical,++ decision: o.decision,++ type: o.type || 'website',++ image: o.image,++ jsonLd: o.jsonLd,++ feeds: o.feeds,++ prev: o.prev,++ next: o.next,++ navbar: nav,++ footer,++ navLinks: NAV_LINKS.map(({ label, href }) => ({ label, href })),++ home: '/',++ css: asset('css/deals.css'),++ release: RELEASE,++ account,++ body: o.body,++ shipped: o.path === '/' ? frame.shipped({ service: 'deals', title: `Recently shipped on ${SITE_NAME}` }) : '',++ bodyClass: o.bodyClass,++ });}module.exports = { renderPage, asset, assetVersion, setRelease, SITE_NAME, NETWORK_URL };nnew file mode 100644@@@ -0,0 +1,61 @@++'use strict';++/**++ * The page shell (server/render/layout.js): the document is openvibe-publishing/layout's++ * (openvibe-shared/shell page()): one title, the canonical and robots from the gate's decision, the++ * JSON-LD, feeds, the site stylesheet, the boost marker, the Frame and the footer's init.++ */++const assert = require('assert');++const { boot, check, done, robotsOf } = require('./helpers/boot');++const { renderPage } = require('../server/render/layout');++++const count = (html, re) => (html.match(re) || []).length;++const split = (html) => ({ head: html.slice(0, html.indexOf('</head>')), body: html.slice(html.indexOf('</head>')) });++++(async () => {++ const t = await boot();++ const alice = t.network.addUser('alice');++++ await check('a page needs the gate decision: there is no default that makes it indexable', async () => {++ assert.throws(() => renderPage({ title: 'x', body: '', config: { baseUrl: 'https://openvibe.deals' } }), TypeError);++ });++++ await check('a deal page: one title, canonical, robots from the decision, JSON-LD, stylesheet, boost marker, Frame and footer', async () => {++ const deal = await t.submit(alice, { url: 'https://gadgets.example/drone', title: 'Mini drone with camera', price: '79.00', currency: 'USD', availability: 'in_stock' });++ const r = await t.get(`/d/${deal.slug}`);++ assert.strictEqual(r.status, 200);++ const { head, body } = split(r.text);++ assert.strictEqual(count(r.text, /<title>/g), 1, 'exactly one <title>');++ assert.ok(head.includes('<title>Mini drone with camera · OpenVibe.Deals</title>'), 'the composed title');++ assert.ok(head.includes(`<link rel="canonical" href="https://openvibe.deals/d/${deal.slug}">`), 'the canonical');++ assert.strictEqual(count(head, /<meta name="robots"/g), 1, 'one robots meta');++ assert.strictEqual(robotsOf(r.text), 'index, follow', 'robots from the decision');++ assert.ok(count(head, /<script type="application\/ld\+json">/g) >= 1, 'JSON-LD');++ assert.ok(/<link rel="stylesheet" href="\/css\/deals\.css\?v=[0-9a-f]+">/.test(head), 'the deals stylesheet');++ assert.ok(/<meta name="ov-boost" content="deals@[^"]+">/.test(head), 'the boost marker');++ assert.ok(head.includes('data-main="#main"'), 'the boost script');++ assert.ok(head.includes('<meta charset="utf-8">') && head.includes('<meta name="viewport"'), 'charset and viewport');++ assert.ok(head.includes('property="og:title"') && head.includes('name="twitter:card"'), 'Open Graph and Twitter tags');++ assert.ok(body.includes('<div id="navbar-mount"></div>'), 'the navbar mount');++ assert.ok(body.includes('<nav aria-label="Site"'), 'the noscript navigation');++ assert.ok(body.includes('href="/watches"'), 'the site links in the noscript navigation');++ assert.ok(body.includes('<main id="main" class="page">'), 'the swappable <main>');++ assert.ok(body.includes('id="ov-footer"'), 'the server-rendered footer');++ assert.ok(body.includes('OpenVibeFooter.init(window.__OV_PAGE.footer)'), 'the footer is initialised');++ assert.ok(body.includes('"loginUrl":"/auth/login?next={path}"'), 'the navbar sign-in returns to the current page');++ });++++ await check('the home page carries the feed links, one title and robots from the decision', async () => {++ const r = await t.get('/');++ const { head } = split(r.text);++ assert.strictEqual(count(head, /<title>/g), 1);++ assert.ok(head.includes('<link rel="canonical" href="https://openvibe.deals/">'));++ assert.strictEqual(robotsOf(r.text), 'index, follow');++ assert.ok(head.includes('<link rel="alternate" type="application/rss+xml" href="/feed.xml"'), 'RSS feed link');++ assert.ok(head.includes('<link rel="alternate" type="application/atom+xml" href="/atom.xml"'), 'Atom feed link');++ assert.ok(head.includes('<link rel="alternate" type="application/feed+json" href="/feed.json"'), 'JSON feed link');++ assert.ok(count(head, /<script type="application\/ld\+json">/g) >= 1, 'JSON-LD');++ });++++ await t.close();++ done();++})();
new file mode 100644
new file mode 100644
@@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
+# Changelog
+
+## Unreleased
+
+- Every page is rendered through `openvibe-publishing/layout` (v1.2.0, on `openvibe-shared/shell` v2.6.0): the head, the Frame, the noscript navigation, the footer and its init come from the shared document; robots and the canonical still come from the indexability gate's decision. Styling is unchanged.
@@ -252,10 +252,10 @@ render time, so the cache stays short); signed-in views, forms, API responses, e
@@ -252,10 +252,10 @@ render time, so the cache stays short); signed-in views, forms, API responses, e
- **PostgreSQL 18 and Valkey 9** (OpenVibe.Host `roles/data/`, ADR-035): every read and write is async through
- **PostgreSQL 18 and Valkey 9** (OpenVibe.Host `roles/data/`, ADR-035): every read and write is async through
`openvibe-sdk/db`; Valkey holds the per-actor limit counters (optional: without `VALKEY_URL` they count per process).
`openvibe-sdk/db`; Valkey holds the per-actor limit counters (optional: without `VALKEY_URL` they count per process).
-- **Packages** (pinned release tarballs): `openvibe-publishing` v1.1.0 (seo gate, JSON-LD, feeds,
+- **Packages** (pinned release tarballs): `openvibe-publishing` v1.2.0 (seo gate, JSON-LD, feeds,
sitemaps, index-hooks, discussion, ssr, and the shared ingest/publication chassis — the Sources
sitemaps, index-hooks, discussion, ssr, and the shared ingest/publication chassis — the Sources
client, change cursor and pull loop, signed event consumer, common normalisers, and the publication
client, change cursor and pull loop, signed event consumer, common normalisers, and the publication
- glue Deals' indexing uses), `openvibe-contracts` v0.79.0, `openvibe-shared` v2.2.0
+ glue Deals' indexing uses), `openvibe-contracts` v0.79.0, `openvibe-shared` v2.6.0
(Frame, app icon, footer, legal, release, metrics, ready), `openvibe-sdk` v0.25.1 (sso, outbox,
(Frame, app icon, footer, legal, release, metrics, ready), `openvibe-sdk` v0.25.1 (sso, outbox,
inbox, webhook signatures v2, service tokens, per-actor limits).
inbox, webhook signatures v2, service tokens, per-actor limits).
- **OpenVibe.Network:** SSO (OAuth client `deals`, registered in production), JWKS,
- **OpenVibe.Network:** SSO (OAuth client `deals`, registered in production), JWKS,
@@ -9,9 +9,9 @@
@@ -9,9 +9,9 @@
"domain": "openvibe.deals",
"domain": "openvibe.deals",
"contracts": "openvibe-contracts v0.79.0",
"contracts": "openvibe-contracts v0.79.0",
"packages": [
"packages": [
- "openvibe-publishing v1.1.0",
+ "openvibe-publishing v1.2.0",
"openvibe-contracts v0.79.0",
"openvibe-contracts v0.79.0",
- "openvibe-shared v2.2.0",
+ "openvibe-shared v2.6.0",
"openvibe-sdk v0.25.1"
"openvibe-sdk v0.25.1"
],
],
"capabilities": [
"capabilities": [
@@ -16,9 +16,9 @@
@@ -16,9 +16,9 @@
"helmet": "^8.1.0",
"helmet": "^8.1.0",
"iovalkey": "^0.4.0",
"iovalkey": "^0.4.0",
"openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.79.0",
"openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.79.0",
- "openvibe-publishing": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v1.1.0",
+ "openvibe-publishing": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v1.2.0",
"openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.26.0",
"openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.26.0",
- "openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v2.5.0",
+ "openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v2.6.0",
"pg": "^8.23.0"
"pg": "^8.23.0"
},
},
"devDependencies": {
"devDependencies": {
@@ -1163,9 +1163,8 @@
@@ -1163,9 +1163,8 @@
}
}
},
},
"node_modules/openvibe-publishing": {
"node_modules/openvibe-publishing": {
- "version": "1.1.0",
- "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v1.1.0",
- "integrity": "sha512-bJsVl82hDivazoiM/np9ckKJE4V5F4OxyIiDwB6xuhK8M6P42sGU+V88rFCkyiI4BVQiKv9xs4GVx8Fj3pyjsg==",
+ "version": "1.2.0",
+ "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v1.2.0",
"license": "MIT",
"license": "MIT",
"engines": {
"engines": {
"node": ">=20"
"node": ">=20"
@@ -1210,9 +1209,9 @@
@@ -1210,9 +1209,9 @@
}
}
},
},
"node_modules/openvibe-shared": {
"node_modules/openvibe-shared": {
- "version": "2.5.0",
- "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v2.5.0",
- "integrity": "sha512-fHuUS6SXM7ezatfAyqLm1V8B6puV9YXSnz6aG6XQbWx28qghRCCHeUF3lr4nxiCGdn9SyikYtIyLGL5r1ycp9Q==",
+ "version": "2.6.0",
+ "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v2.6.0",
+ "integrity": "sha512-IKKvWTM/9UonQ4msrzM4yir0QcTUNbhyqeN1r5ywWavU4VTsL1sI5QdHQlxge7BAsMrQ4OvMEPlHjuAfUJM3rg==",
"license": "MIT",
"license": "MIT",
"dependencies": {
"dependencies": {
"jsonwebtoken": "^9.0.0"
"jsonwebtoken": "^9.0.0"
@@ -27,9 +27,9 @@
@@ -27,9 +27,9 @@
"helmet": "^8.1.0",
"helmet": "^8.1.0",
"iovalkey": "^0.4.0",
"iovalkey": "^0.4.0",
"openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.79.0",
"openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.79.0",
- "openvibe-publishing": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v1.1.0",
+ "openvibe-publishing": "https://codeload.github.com/OpenVibers/OpenVibe.Publishing/tar.gz/refs/tags/v1.2.0",
"openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.26.0",
"openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.26.0",
- "openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v2.5.0",
+ "openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v2.6.0",
"pg": "^8.23.0"
"pg": "^8.23.0"
},
},
"devDependencies": {
"devDependencies": {
@@ -1,25 +1,29 @@
@@ -1,25 +1,29 @@
'use strict';
'use strict';
/**
/**
- * Page shell. Every page is server-rendered through this and is complete without JavaScript:
+ * Page shell. Every page is server-rendered through openvibe-publishing/layout (openvibe-shared/shell
+ * page()) and is complete without JavaScript:
* - <head>: title, description, canonical and robots from the indexability gate's decision
* - <head>: title, description, canonical and robots from the indexability gate's decision
- * (openvibe-publishing/seo metaTags — there is no default that makes a page indexable),
- * Open Graph/Twitter, JSON-LD, feed links, the shared app icon and critical canvas
- * - the OpenVibe Frame: navbar.js and theme-loader.js from the Network (progressive), a
- * <noscript> navigation bar and the server-rendered shared footer (openvibe-shared)
+ * (there is no default that makes a page indexable), Open Graph/Twitter, JSON-LD, prev/next,
+ * feed links, the shared app icon, the site stylesheet and the boost marker
+ * - the OpenVibe Frame: theme-loader, web runtime, navbar and footer from the Network
+ * (progressive), a <noscript> navigation bar and the server-rendered shared footer
*/
*/
const crypto = require('crypto');
const crypto = require('crypto');
-const ovServe = require('openvibe-shared/serve');
const fs = require('fs');
const fs = require('fs');
const path = require('path');
const path = require('path');
-const seo = require('openvibe-publishing/seo');
-const { escapeHtml: esc } = require('openvibe-publishing/ssr');
-const appIcon = require('openvibe-shared/app-icon');
+const layout = require('openvibe-publishing/layout');
const frame = require('openvibe-shared/frame');
const frame = require('openvibe-shared/frame');
const NETWORK_URL = 'https://openvibe.network';
const NETWORK_URL = 'https://openvibe.network';
const SITE_NAME = 'OpenVibe.Deals';
const SITE_NAME = 'OpenVibe.Deals';
const PUBLIC_DIR = path.join(__dirname, '..', '..', 'public');
const PUBLIC_DIR = path.join(__dirname, '..', '..', 'public');
+const NAV_LINKS = [
+ { label: 'Hot', href: '/' },
+ { label: 'New', href: '/new' },
+ { label: 'Submit', href: '/submit', icon: 'fa-plus' },
+ { label: 'Watches', href: '/watches', icon: 'fa-bell' },
+];
const hashes = new Map();
const hashes = new Map();
function assetVersion(rel) {
function assetVersion(rel) {
@@ -42,30 +46,13 @@ function setRelease(id) { if (id) RELEASE = String(id); }
@@ -42,30 +46,13 @@ function setRelease(id) { if (id) RELEASE = String(id); }
*/
*/
function renderPage(o) {
function renderPage(o) {
if (!o.decision) throw new TypeError('renderPage needs the gate decision');
if (!o.decision) throw new TypeError('renderPage needs the gate decision');
- const head = seo.metaTags({
- title: o.title ? `${o.title} · ${SITE_NAME}` : SITE_NAME,
- description: o.description || 'Deals submitted and voted on by the community, with source, price and freshness always shown.',
- decision: o.decision,
- canonical: o.canonical,
- type: o.type || 'website',
- siteName: SITE_NAME,
- image: o.image || undefined,
- prev: o.prev || undefined,
- next: o.next || undefined,
- jsonLd: (o.jsonLd || []).filter(Boolean),
- });
const viewer = o.viewer || { kind: 'anonymous' };
const viewer = o.viewer || { kind: 'anonymous' };
const signedIn = viewer.kind === 'user';
const signedIn = viewer.kind === 'user';
const loginNext = encodeURIComponent(o.path || '/');
const loginNext = encodeURIComponent(o.path || '/');
const nav = {
const nav = {
service: 'deals',
service: 'deals',
apiBase: NETWORK_URL,
apiBase: NETWORK_URL,
- links: [
- { label: 'Hot', href: '/' },
- { label: 'New', href: '/new' },
- { label: 'Submit', href: '/submit', icon: 'fa-plus' },
- { label: 'Watches', href: '/watches', icon: 'fa-bell' },
- ],
+ links: NAV_LINKS,
history: { type: 'page', title: o.title || SITE_NAME },
history: { type: 'page', title: o.title || SITE_NAME },
silentLogin: `${o.config.baseUrl}/auth/login?silent=1&next={url}`,
silentLogin: `${o.config.baseUrl}/auth/login?silent=1&next={url}`,
sessionUrl: '/auth/me',
sessionUrl: '/auth/me',
@@ -80,40 +67,31 @@ function renderPage(o) {
@@ -80,40 +67,31 @@ function renderPage(o) {
const account = signedIn
const account = signedIn
? `${viewer.staff ? '<a href="/mod">Moderation</a> · ' : ''}<a href="/watches">Watches</a> · <a href="/auth/logout?next=${loginNext}">Sign out</a>`
? `${viewer.staff ? '<a href="/mod">Moderation</a> · ' : ''}<a href="/watches">Watches</a> · <a href="/auth/logout?next=${loginNext}">Sign out</a>`
: `<a href="/auth/login?next=${loginNext}">Sign in with OpenVibe</a>`;
: `<a href="/auth/login?next=${loginNext}">Sign in with OpenVibe</a>`;
- return `<!DOCTYPE html>
-<html lang="${esc(o.lang || 'en')}">
-<head>
-<meta charset="utf-8">
-<meta name="viewport" content="width=device-width, initial-scale=1">
-${head}
-${seo.feedLinks(o.feeds || [])}
-${appIcon.headTags({ site: 'deals' })}
-<link rel="stylesheet" href="${asset('css/deals.css')}">
-<script src="${ovServe.url('theme-loader.js')}" defer></script>
-<script src="${ovServe.url('navbar.js')}" defer></script>
-<script src="${ovServe.url('footer.js')}" defer></script>
-<meta name="ov-boost" content="deals@${esc(RELEASE)}">
-<script src="${ovServe.url('boost.js')}" data-main="#main" defer></script>
-</head>
-<body class="${esc(o.bodyClass || '')}">
-<a class="skip" href="#main">Skip to content</a>
-<div id="navbar-mount"></div>
-${frame.noscriptNav({ name: SITE_NAME, home: '/', links: [{ label: 'Hot', href: '/' }, { label: 'New', href: '/new' }, { label: 'Submit', href: '/submit' }, { label: 'Watches', href: '/watches' }] })}
-<noscript><div class="account-bar" role="navigation" aria-label="Account">${account}</div></noscript>
-<main id="main" class="page">
-${o.body || ''}
-${o.path === '/' ? frame.shipped({ service: 'deals', title: `Recently shipped on ${SITE_NAME}` }) : ''}
-</main>
-${frame.footer(footer)}
-<script>
-window.__OV_PAGE = ${JSON.stringify({ navbar: nav, footer }).replace(/</g, '\\u003c')};
-document.addEventListener('DOMContentLoaded', function () {
- try { if (window.OpenVibeNavbar) OpenVibeNavbar.init(window.__OV_PAGE.navbar); } catch (e) { /* the Frame is optional */ }
- try { if (window.OpenVibeFooter) OpenVibeFooter.init(window.__OV_PAGE.footer); } catch (e) { /* */ }
-});
-</script>
-</body>
-</html>`;
+ return layout.renderDocument({
+ site: 'deals',
+ siteName: SITE_NAME,
+ lang: o.lang,
+ title: o.title ? `${o.title} · ${SITE_NAME}` : SITE_NAME,
+ description: o.description || 'Deals submitted and voted on by the community, with source, price and freshness always shown.',
+ canonical: o.canonical,
+ decision: o.decision,
+ type: o.type || 'website',
+ image: o.image,
+ jsonLd: o.jsonLd,
+ feeds: o.feeds,
+ prev: o.prev,
+ next: o.next,
+ navbar: nav,
+ footer,
+ navLinks: NAV_LINKS.map(({ label, href }) => ({ label, href })),
+ home: '/',
+ css: asset('css/deals.css'),
+ release: RELEASE,
+ account,
+ body: o.body,
+ shipped: o.path === '/' ? frame.shipped({ service: 'deals', title: `Recently shipped on ${SITE_NAME}` }) : '',
+ bodyClass: o.bodyClass,
+ });
}
}
module.exports = { renderPage, asset, assetVersion, setRelease, SITE_NAME, NETWORK_URL };
module.exports = { renderPage, asset, assetVersion, setRelease, SITE_NAME, NETWORK_URL };
new file mode 100644
new file mode 100644
@@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
+'use strict';
+/**
+ * The page shell (server/render/layout.js): the document is openvibe-publishing/layout's
+ * (openvibe-shared/shell page()): one title, the canonical and robots from the gate's decision, the
+ * JSON-LD, feeds, the site stylesheet, the boost marker, the Frame and the footer's init.
+ */
+const assert = require('assert');
+const { boot, check, done, robotsOf } = require('./helpers/boot');
+const { renderPage } = require('../server/render/layout');
+
+const count = (html, re) => (html.match(re) || []).length;
+const split = (html) => ({ head: html.slice(0, html.indexOf('</head>')), body: html.slice(html.indexOf('</head>')) });
+
+(async () => {
+ const t = await boot();
+ const alice = t.network.addUser('alice');
+
+ await check('a page needs the gate decision: there is no default that makes it indexable', async () => {
+ assert.throws(() => renderPage({ title: 'x', body: '', config: { baseUrl: 'https://openvibe.deals' } }), TypeError);
+ });
+
+ await check('a deal page: one title, canonical, robots from the decision, JSON-LD, stylesheet, boost marker, Frame and footer', async () => {
+ const deal = await t.submit(alice, { url: 'https://gadgets.example/drone', title: 'Mini drone with camera', price: '79.00', currency: 'USD', availability: 'in_stock' });
+ const r = await t.get(`/d/${deal.slug}`);
+ assert.strictEqual(r.status, 200);
+ const { head, body } = split(r.text);
+ assert.strictEqual(count(r.text, /<title>/g), 1, 'exactly one <title>');
+ assert.ok(head.includes('<title>Mini drone with camera · OpenVibe.Deals</title>'), 'the composed title');
+ assert.ok(head.includes(`<link rel="canonical" href="https://openvibe.deals/d/${deal.slug}">`), 'the canonical');
+ assert.strictEqual(count(head, /<meta name="robots"/g), 1, 'one robots meta');
+ assert.strictEqual(robotsOf(r.text), 'index, follow', 'robots from the decision');
+ assert.ok(count(head, /<script type="application\/ld\+json">/g) >= 1, 'JSON-LD');
+ assert.ok(/<link rel="stylesheet" href="\/css\/deals\.css\?v=[0-9a-f]+">/.test(head), 'the deals stylesheet');
+ assert.ok(/<meta name="ov-boost" content="deals@[^"]+">/.test(head), 'the boost marker');
+ assert.ok(head.includes('data-main="#main"'), 'the boost script');
+ assert.ok(head.includes('<meta charset="utf-8">') && head.includes('<meta name="viewport"'), 'charset and viewport');
+ assert.ok(head.includes('property="og:title"') && head.includes('name="twitter:card"'), 'Open Graph and Twitter tags');
+ assert.ok(body.includes('<div id="navbar-mount"></div>'), 'the navbar mount');
+ assert.ok(body.includes('<nav aria-label="Site"'), 'the noscript navigation');
+ assert.ok(body.includes('href="/watches"'), 'the site links in the noscript navigation');
+ assert.ok(body.includes('<main id="main" class="page">'), 'the swappable <main>');
+ assert.ok(body.includes('id="ov-footer"'), 'the server-rendered footer');
+ assert.ok(body.includes('OpenVibeFooter.init(window.__OV_PAGE.footer)'), 'the footer is initialised');
+ assert.ok(body.includes('"loginUrl":"/auth/login?next={path}"'), 'the navbar sign-in returns to the current page');
+ });
+
+ await check('the home page carries the feed links, one title and robots from the decision', async () => {
+ const r = await t.get('/');
+ const { head } = split(r.text);
+ assert.strictEqual(count(head, /<title>/g), 1);
+ assert.ok(head.includes('<link rel="canonical" href="https://openvibe.deals/">'));
+ assert.strictEqual(robotsOf(r.text), 'index, follow');
+ assert.ok(head.includes('<link rel="alternate" type="application/rss+xml" href="/feed.xml"'), 'RSS feed link');
+ assert.ok(head.includes('<link rel="alternate" type="application/atom+xml" href="/atom.xml"'), 'Atom feed link');
+ assert.ok(head.includes('<link rel="alternate" type="application/feed+json" href="/feed.json"'), 'JSON feed link');
+ assert.ok(count(head, /<script type="application\/ld\+json">/g) >= 1, 'JSON-LD');
+ });
+
+ await t.close();
+ done();
+})();