openvibers/openvibe.vip Commits

The home on phones: the questions are a fold, the creators one row (#130)

OP OpenVibers committed 14 days ago · d6d363c528 · 4 files, +176 −1

The home page is one or two screens on a phone. The questions become a fold,
closed on a phone and open where there is room, and the creators become one
sideways row of cards (every creator is still in the page). A wider screen
shows the grid and the open questions, as before.

Tested with the site's suite (home-short.test.js covers the fold and the
phone row).

Changes

ddiff --git a/public/css/vip.css b/public/css/vip.css
iindex b1ccd9d..66822f0 100644
---- a/public/css/vip.css
++++ b/public/css/vip.css
@@@ -127,3 +127,56 @@ code { background: rgba(255, 255, 255, .06); padding: 1px 5px; border-radius: 4p
.vip-live-links a { position: relative; }
.vip-live-links a::after { content: ''; position: absolute; left: 0; right: 0; top: -10px; bottom: -10px; }
}
++
++/* The phone home (2026-10-30, the owner's short-pages rule): the questions are a fold, closed on a phone and open
++ where there is room, and the creators are one sideways row (every creator is still there). */
++/* Pick (the owner's short-pages rule, 2026-10-30): on a phone the front page's blocks of the same kind are one at a
++ time, picked with a row of chips. Radio inputs and :has(), no script: the chips and the one-pane rule live under
++ 640 px and only where :has() is understood, so a wider screen, or an older browser, shows every pane and no chips.
++ Every pane stays in the page for crawlers. */
++.pick-head { display: none; }
++.pick-row { display: none; }
++@supports selector(:has(*)) { @media (max-width: 640px) {
++ .pick-bar { margin-top: 30px; }
++ .pick-head { display: block; }
++ .pick-head h2 { margin: 0 0 4px; font: 700 clamp(20px, 2.4vw, 28px)/1.2 var(--ov-font, 'Inter', system-ui, sans-serif); letter-spacing: -.02em; }
++ .pick-row { display: flex; gap: 8px; overflow-x: auto; margin: 10px -16px 0; padding: 2px 16px 4px; scrollbar-width: none; overscroll-behavior-x: contain; }
++ .pick-row::-webkit-scrollbar { display: none; }
++ .pick-row input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
++ .pick-row label { display: inline-flex; align-items: center; flex: none; min-height: 44px; padding: 0 15px; border-radius: 999px; border: 1px solid var(--border, #1f2d47); color: var(--text-secondary, #96a7c2); font-size: .9rem; font-weight: 650; white-space: nowrap; cursor: pointer; }
++ .pick-row input:checked + label { color: var(--text-primary, #e6edf7); border-color: var(--accent, #3b82f6); background: color-mix(in srgb, var(--accent, #3b82f6) 12%, transparent); }
++ .pick-row input:focus-visible + label { outline: 2px solid var(--accent, #3b82f6); outline-offset: 2px; }
++ .pick .pick-pane { display: none; }
++ /* A link that points at a pane opens that pane on a phone too. */
++ .pick .pick-pane:target { display: block !important; }
++ .pick:has(.pick-pane:target) .pick-pane:not(:target) { display: none !important; }
++ /* The chip names the pane, so the pane's own heading gives way to it; the link to more stays. */
++ .pick .pick-pane > h2, .pick .pick-pane > h3 { display: none; }
++} }
++
++/* The fold (the owner's short-pages rule): closed on a phone, and where there is room it looks like the section it
++ replaces: a heading and its content, with no card around it. */
++.hm-fold-block { margin-top: 32px; }
++.hm-fold-block > summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; cursor: pointer; list-style: none; }
++.hm-fold-block > summary::-webkit-details-marker { display: none; }
++.hm-fold-block > summary h2 { margin: 0; font: 700 clamp(19px, 2.2vw, 26px)/1.2 var(--ov-font, 'Inter', system-ui, sans-serif); }
++.hm-fold-block > summary span { color: var(--text-muted, #7386a3); font-weight: 600; font-size: .86rem; white-space: nowrap; }
++.hm-fold-block > summary:focus-visible { outline: 2px solid var(--accent, #3b82f6); outline-offset: 2px; }
++@media (min-width: 641px) {
++ .hm-fold-block { border: 0; background: none; border-radius: 0; margin: 56px auto 0; padding: 0; }
++ .hm-fold-block > summary { display: block; min-height: 0; }
++ .hm-fold-block > summary h2 { margin: 0 0 6px; font: 700 clamp(22px, 2.6vw, 30px)/1.2 var(--ov-font, 'Inter', system-ui, sans-serif); }
++ .hm-fold-block > summary span { display: none; }
++ .hm-fold-block .hm-sec, .hm-fold-block .sc-sec { margin: 0; max-width: none; padding: 0; }
++}
++@media (max-width: 640px) { .hm-fold-block { margin-top: 24px; } .hm-fold-block > summary h2 { font-size: 1.05rem; } }
++/* A fold that sits inside the section it replaces adds no space of its own. */
++:where(.sc-sec, .cm-sec, .hm-sec, .section) > .hm-fold-block { margin: 0; }
++/* The fold holds the questions, so their list gets the room the section gave it. */
++.hm-fold-block .vip-faq { margin: 0; padding: 0 16px 16px; }
++/* The creators on a phone: one sideways row of cards, every creator still in the page. */
++@media (max-width: 599px) {
++ .creator-list { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-inline: 16px; gap: 10px; margin-left: -16px; margin-right: -16px; padding: 0 16px 4px; scrollbar-width: none; }
++ .creator-list::-webkit-scrollbar { display: none; }
++ .creator-list > li { flex: 0 0 45%; min-width: 0; scroll-snap-align: start; }
++}
ddiff --git a/server/web/pages.js b/server/web/pages.js
iindex 9d0bc5e..e2ea571 100644
---- a/server/web/pages.js
++++ b/server/web/pages.js
@@@ -67,6 +67,7 @@ function homeFaqJsonLd() {
};
}
++const S = require('./short');
const avatar = (networkUrl, username, size) => `<img class="vip-avatar" src="${esc(networkUrl)}/avatar/${encodeURIComponent(username)}?s=${size}" width="${size}" height="${size}" alt="" loading="lazy" decoding="async">`;
const plural = (n, one, many) => `${n.toLocaleString('en-US')} ${n === 1 ? one : many}`;
@@@ -95,7 +96,7 @@ function home({ creators, live = [], networkUrl = 'https://openvibe.network' })
? `<ul class="creator-list">${ordered.map((c) => `<li><a href="/${encodeURIComponent(c.username)}">${avatar(networkUrl, c.username, 40)}<span class="vip-creator-text"><b>${esc(c.display_name || c.username)}</b><span class="muted">@${esc(c.username)}</span></span>${onAir.has(c.username.toLowerCase()) ? '<span class="vip-live-pill">Live</span>' : ''}</a></li>`).join('')}</ul>`
: '<p class="muted">No creator has published a plan here yet.</p>';
-- return showcase.hero({
++ const body = showcase.hero({
eyebrow: 'OpenVibe.VIP',
title: 'Memberships across', accent: 'OpenVibe',
lede: "Back the creators you watch with a monthly membership. Join once and it's recognised across OpenVibe: a badge by your name in chat, members-only posts, a members' room, whatever the plan lists.",
@@@ -159,6 +160,9 @@ if (e.active) unlockPro(); // expired, unknown or unreachable all answer no`,
],
}) + `</details></section>
<section class="sc-sec" id="questions" aria-labelledby="questions-h"><h2 id="questions-h">Questions</h2><div class="vip-faq">${HOME_FAQ.map((f) => `<details><summary>${esc(f.q)}</summary><p>${esc(f.a)}</p></details>`).join('')}</div></section>`;
++ // The questions are a fold on a phone (the owner's short-pages rule, 2026-10-30): they stay in the page for the
++ // crawlers, and the script closes them where the reader has room for more.
++ return S.foldSection(body, 'id="questions"', 'questions-fold');
}
/** The creator's public plan page. */
ddiff --git a/server/web/short.js b/server/web/short.js
nnew file mode 100644
iindex 0000000..d201b02
---- /dev/null
++++ b/server/web/short.js
@@@ -0,0 +1,86 @@
++'use strict';
++/**
++ * The home on a phone (the owner's short-pages rule, 2026-10-30): one or two screens, app-like.
++ *
++ * pickBlock() several blocks of the same kind, one at a time on a phone, picked with a row of chips. Radio
++ * inputs and :has(), no script: every block stays in the page for crawlers, and a wider screen (or a
++ * browser without :has()) shows them all and no chips.
++ * foldBlock() a part a reader rarely needs, closed on a phone and open where there is room. The page's own markup
++ * keeps it open, so a browser without the script shows it as before; the script closes it on a narrow
++ * screen and remembers the reader's choice.
++ *
++ * The CSS for both lives in the site's own stylesheet; the rule that shows the picked block is written for the
++ * page, because there is one per block.
++ */
++const esc = (s) => String(s == null ? '' : s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
++
++/**
++ * A pick block. The panes are the page's own blocks; each one keeps its heading on a wide screen, and on a phone the
++ * heading gives way to the chip that names it.
++ *
++ * pickBlock({ key, label, head, panes }) head: the heading of the block, or '' when the block already has one.
++ * panes: [{ id, label, html }]
++ */
++function pickBlock({ key, label, head = '', panes, bodyClass = '' }) {
++ // A pane with nothing to show is left out, so the chips and the rules that show them match the page.
++ panes = (panes || []).filter((p) => p.html);
++ if (!panes.length) return '';
++ const chips = panes.map((p, i) => `<input type="radio" name="pick-${esc(key)}" id="pk-${esc(key)}-${esc(p.id)}" value="${esc(p.id)}"${i === 0 ? ' checked' : ''}><label for="pk-${esc(key)}-${esc(p.id)}">${esc(p.label)}</label>`).join('');
++ // The pane carries the id the page already links to (an anchor in the hero, for instance), so a link to it still
++ // opens that pane on a phone (the CSS shows the pane a link points at).
++ const body = panes.map((p) => `<div class="pick-pane" id="${esc(p.id)}">${p.html}</div>`).join('');
++ const bar = `${head ? `<div class="pick-head"><h2>${esc(head)}</h2></div>` : ''}<div class="pick-row" role="radiogroup" aria-label="${esc(label)}">${chips}</div>`;
++ return `<div class="pick" id="pick-${esc(key)}"><div class="pick-bar">${bar}</div><div class="pick-body${bodyClass ? ' ' + esc(bodyClass) : ''}">${body}</div></div>`;
++}
++
++/** The rule that shows the picked block of a pick block: one per block, so the CSS is written for the page. */
++function pickRule(key, id) {
++ return `.pick:has(#pk-${key}-${id}:checked) #${id}{display:block}`;
++}
++
++/** The rules for every block of a pick block, in the order they appear. */
++function pickRules(key, ids) {
++ return ids.map((id) => pickRule(key, id)).join('');
++}
++
++/**
++ * A fold. The head is the heading the block had; the html is what it holds.
++ *
++ * foldBlock({ id, head, html })
++ */
++function foldBlock({ id, head, html }) {
++ return `<details class="hm-fold hm-fold-block" id="${esc(id)}" open><summary>${head}<span>tap to open</span></summary>${html}</details>${foldScript(id)}`;
++}
++
++/** The script a fold carries: closed on a phone unless the reader opened it before, and it remembers that. */
++function foldScript(id) {
++ return `<script>(function(){var d=document.getElementById(${JSON.stringify(id)});if(!d)return;var k='ov_fold_'+${JSON.stringify(id)};var s=null;try{s=localStorage.getItem(k)}catch(e){}if(s==='open'){d.open=true;return}if(s==='closed'){d.open=false;return}var t=0;if(window.matchMedia&&window.matchMedia('(max-width:640px)').matches){t=Date.now();d.open=false}d.addEventListener('toggle',function(){if(Date.now()-t<300)return;try{localStorage.setItem(k,d.open?'open':'closed')}catch(e){}})})();</script>`;
++}
++
++/**
++ * A section of the page's own markup as a fold. The section stays where it was; its own heading becomes the fold's
++ * heading, and the fold is closed on a phone (the script) and open where there is room.
++ *
++ * foldSection(html, needle, id) needle: a mark of the part to fold (a class, for instance)
++ */
++function foldSection(html, needle, id) {
++ const at = html.indexOf(needle);
++ if (at < 0) return html;
++ const start = html.lastIndexOf('<section', at);
++ const close = html.indexOf('</section>', at);
++ if (start < 0 || close < 0) return html;
++ const openEnd = html.indexOf('>', start) + 1;
++ const openTag = html.slice(start, openEnd);
++ let inner = html.slice(openEnd, close);
++ const h2 = /<h2[^>]*>[\s\S]*?<\/h2>/.exec(inner);
++ if (!h2) return html;
++ const head = h2[0];
++ inner = inner.slice(h2.index + head.length);
++ // The lede under the heading goes with it: the fold's heading says enough on a phone.
++ const lede = /<p class="sc-lede"[^>]*>[\s\S]*?<\/p>/.exec(inner);
++ if (lede) inner = inner.slice(0, lede.index) + inner.slice(lede.index + lede[0].length);
++ const fold = `<details class="hm-fold hm-fold-block" id="${esc(id)}" open><summary>${head}<span>tap to open</span></summary>${inner.trim()}</details>${foldScript(id)}`;
++ return html.slice(0, start) + openTag + fold + html.slice(close);
++}
++
++module.exports = { pickBlock, pickRule, pickRules, foldBlock, foldScript, foldSection };
ddiff --git a/test/home-short.test.js b/test/home-short.test.js
nnew file mode 100644
iindex 0000000..660935b
---- /dev/null
++++ b/test/home-short.test.js
@@@ -0,0 +1,32 @@
++'use strict';
++/**
++ * The home on a phone (the owner's short-pages rule, 2026-10-30): the questions are a fold, closed on a phone and open
++ * where there is room, and the creators are one sideways row. Everything stays in the page for the crawlers.
++ */
++const assert = require('assert');
++const fs = require('fs');
++const path = require('path');
++const pages = require('../server/web/pages');
++
++const creators = [
++ { username: 'alma', display_name: 'Alma' },
++ { username: 'bo', display_name: 'Bo' },
++];
++const html = pages.home({ creators, live: [], networkUrl: 'https://openvibe.network' });
++
++// The questions are a fold, open in the page and closed on a phone.
++assert.ok(html.includes('<details class="hm-fold hm-fold-block" id="questions-fold" open>'), 'the questions are a fold, open in the page');
++assert.ok(html.includes('document.getElementById("questions-fold")'), 'the fold has the script that closes it on a phone');
++// The questions stay in the page.
++assert.match(html, /What is a membership\?/);
++assert.ok(html.includes('id="questions"'), 'the questions keep their section');
++// Every creator stays in the page.
++for (const c of creators) assert.ok(html.includes(`href="/${c.username}"`), `${c.username} is on the page`);
++
++// The CSS guard: a fold is a 44 px target and the creators are one row on a phone.
++const css = fs.readFileSync(path.join(__dirname, '..', 'public', 'css', 'vip.css'), 'utf8');
++assert.match(css, /\.hm-fold-block > summary \{[^}]*min-height: 44px/, 'a fold is a 44 px target');
++assert.match(css, /@media \(max-width: 599px\) \{\s*\.creator-list \{ display: flex; overflow-x: auto;/, 'the creators are one sideways row on a phone');
++assert.match(css, /\.creator-list > li \{ flex: 0 0/, 'every creator keeps its place in the row');
++
++console.log('home-short: 2/2 passed');