Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion sites/meshview-info/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ Lokale kilder til de fire selvstændige sider. Ikke CoreScopes `public/` og ikke
| observer.html | /observer |
| hardware.html | /hardware |
| radio.html | /radio |
| guider.html | /guider |

## Assets og deployment

HTML bruger `/meshview-info-assets/site.css`, og observer bruger desuden
`/meshview-info-assets/copy-commands.js`. Fonts hentes relativt til CSS-filen.
`/meshview-info-assets/copy-commands.js`, og guider bruger
`/meshview-info-assets/guider.js` og miniaturerne i `assets/guider/`. Fonts hentes relativt til CSS-filen.

Siderne serveres som statiske filer på de offentlige ruter ovenfor
(skrivebeskyttet, uden om CoreScopes `public/`). De deployes ikke automatisk:
Expand All @@ -32,13 +34,26 @@ Fra repoet, med Playwright tilgængelig:
node sites/meshview-info/test-copy-commands.js
node sites/meshview-info/test-xss.cjs
node sites/meshview-info/test-mobile.cjs
node sites/meshview-info/test-guider.cjs
```

Mobiltesten starter/lukker selv en lokal server på en ledig loopback-port,
bruger syntetiske API-data og blokerer eksterne browserrequests. Den tester
Chromium ved 320/375/390/768/1280 px. `SCREENSHOT_DIR` kan sættes for billeder.
Det er ikke en test på fysisk iPhone/Safari eller af produktionens API-data.

## Videoguider (/guider)

Hver guide er et kort i `guider.html` med `data-youtube=""`. Når videoen er lagt
på YouTube, sættes dens 11-tegns id (fx `data-youtube="dQw4w9WgXcQ"`). Et kort
uden gyldigt id vises som "Video på vej" og kan ikke afspilles.

Afspilning sker først ved klik: `assets/guider.js` skifter miniaturen ud med en
`youtube-nocookie.com`-afspiller. Før klikket hentes intet fra YouTube;
miniaturerne ligger lokalt i `assets/guider/` (640×360 jpg, taget fra videoen).
Ny guide: læg miniaturen i `assets/guider/`, kopiér et kort, og link til den
matchende side i `docs/user-guide/`.

## Fonts

Uændrede TTF-filer hentet 2026-09-16 fra google/fonts, med OFL-licenser:
Expand Down
46 changes: 46 additions & 0 deletions sites/meshview-info/assets/guider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Click-to-play for /guider: nothing is loaded from YouTube until the visitor presses play.
// A card without a valid video id shows "Video på vej" and is not clickable.
(function () {
'use strict';
var ID = /^[A-Za-z0-9_-]{11}$/;

function embedUrl(id) {
return 'https://www.youtube-nocookie.com/embed/' + id + '?autoplay=1&rel=0&modestbranding=1&cc_load_policy=1&hl=da';
}

function play(btn, id) {
var frame = document.createElement('iframe');
frame.src = embedUrl(id);
frame.title = btn.getAttribute('data-title') || 'Video';
frame.setAttribute('allow', 'autoplay; encrypted-media; picture-in-picture; fullscreen');
frame.setAttribute('allowfullscreen', '');
frame.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
btn.parentNode.replaceChild(frame, btn);
frame.focus();
}

function setup(card) {
var btn = card.querySelector('.guide-play');
if (!btn) return;
var id = (card.getAttribute('data-youtube') || '').trim();
var title = btn.getAttribute('data-title') || 'video';
if (!ID.test(id)) {
btn.disabled = true;
btn.setAttribute('aria-label', title + ': video på vej');
var soon = document.createElement('span');
soon.className = 'guide-badge soon';
soon.textContent = 'Video på vej';
btn.appendChild(soon);
return;
}
btn.setAttribute('aria-label', 'Afspil video: ' + title);
btn.addEventListener('click', function () { play(btn, id); });
}

if (typeof module !== 'undefined' && module.exports) {
module.exports = { ID: ID, embedUrl: embedUrl };
return;
}
var cards = document.querySelectorAll('.guide-card');
for (var i = 0; i < cards.length; i++) setup(cards[i]);
})();
Binary file added sites/meshview-info/assets/guider/kort-og-lag.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sites/meshview-info/assets/guider/skraafoto.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions sites/meshview-info/assets/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ body .dash-card { min-width: 0; }
body .set-row { gap: 12px; }
body .set-row .v { overflow-wrap: anywhere; }
}
@media (max-width: 440px) {
body .nav-links { gap: 0 14px; }
body .nav-links a { letter-spacing: .03em; }
}
288 changes: 288 additions & 0 deletions sites/meshview-info/guider.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sites/meshview-info/hardware.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<li><a href="https://meshview.dk/#/live" target="_blank" rel="noopener">Live</a></li>
<li><a href="/velkommen#noder">Noder</a></li>
<li><a href="/velkommen#guide">Kom i gang</a></li>
<li><a href="/guider">Guider</a></li>
<li><a href="https://tools.meshview.dk">Værktøjer</a></li>
</ul>
</div>
Expand Down
1 change: 1 addition & 0 deletions sites/meshview-info/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
<li><a href="https://meshview.dk/#/live" target="_blank" rel="noopener">Live</a></li>
<li><a href="#noder">Noder</a></li>
<li><a href="#guide">Kom i gang</a></li>
<li><a href="/guider">Guider</a></li>
<li><a href="https://tools.meshview.dk">Værktøjer</a></li>
</ul>
<div class="nav-status">
Expand Down
1 change: 1 addition & 0 deletions sites/meshview-info/observer.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<li><a href="https://meshview.dk/#/live" target="_blank" rel="noopener">Live</a></li>
<li><a href="/velkommen#noder">Noder</a></li>
<li><a href="/velkommen#guide">Kom i gang</a></li>
<li><a href="/guider">Guider</a></li>
<li><a href="https://tools.meshview.dk">Værktøjer</a></li>
</ul>
</div>
Expand Down
1 change: 1 addition & 0 deletions sites/meshview-info/radio.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
<li><a href="https://meshview.dk/#/live" target="_blank" rel="noopener">Live</a></li>
<li><a href="/velkommen#noder">Noder</a></li>
<li><a href="/velkommen#guide">Kom i gang</a></li>
<li><a href="/guider">Guider</a></li>
<li><a href="https://tools.meshview.dk">Værktøjer</a></li>
</ul>
</div>
Expand Down
98 changes: 98 additions & 0 deletions sites/meshview-info/test-guider.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// /guider: click-to-play YouTube cards. Nothing is requested from YouTube before a click;
// a card without a valid id is disabled; every info page links to /guider exactly once.
// /guider-ids rewrites the published ids: card 1 a test id, card 2 malformed, card 3 empty.
const assert = require('node:assert/strict');
const http = require('node:http');
const fs = require('node:fs');
const path = require('node:path');
const { chromium } = require('playwright');
const pages = { '/velkommen': 'index.html', '/observer': 'observer.html', '/hardware': 'hardware.html', '/radio': 'radio.html', '/guider': 'guider.html' };
const VALID = 'dQw4w9WgXcQ';
const types = { '.css': 'text/css', '.js': 'text/javascript', '.ttf': 'font/ttf', '.jpg': 'image/jpeg' };
function withIds(html) {
let n = 0;
return html.replace(/data-youtube="[^"]*"/g, () => {
n++;
return n === 1 ? `data-youtube="${VALID}"` : n === 2 ? 'data-youtube="abc&quot;onerror"' : 'data-youtube=""';
});
}
const server = http.createServer((req, res) => {
const url = new URL(req.url, 'http://localhost');
if (url.pathname.startsWith('/api/')) { res.setHeader('Content-Type', 'application/json'); return res.end('[]'); }
let file = pages[url.pathname.replace(/\/$/, '')];
if (url.pathname === '/guider-ids') file = 'guider.html';
if (url.pathname.startsWith('/meshview-info-assets/')) file = 'assets/' + url.pathname.slice('/meshview-info-assets/'.length);
if (!file || file.includes('..') || !fs.existsSync(path.join(__dirname, file))) { res.statusCode = 404; return res.end(); }
res.setHeader('Content-Type', types[path.extname(file)] || 'text/html; charset=utf-8');
let body = fs.readFileSync(path.join(__dirname, file));
if (url.pathname === '/guider-ids') body = withIds(body.toString());
res.end(body);
});
let browser;
const timeout = setTimeout(() => { console.error('TIMEOUT'); process.exit(1); }, 60000);
(async () => {
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
const origin = `http://127.0.0.1:${server.address().port}`;
browser = await chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: { width: 375, height: 740 }, hasTouch: true, isMobile: true });
const page = await context.newPage();
const external = [], errors = [];
page.on('pageerror', e => errors.push(e.message));
await page.route('**/*', route => {
const u = route.request().url();
if (u.startsWith(origin)) return route.continue();
external.push(u);
return route.fulfill({ status: 204, body: '' });
});

// Every page links to /guider exactly once in the nav.
for (const p of Object.keys(pages)) {
await page.goto(origin + p);
assert.equal(await page.locator('.nav-links a[href="/guider"]').count(), 1, `${p}: one Guider link in the nav`);
}

// Published page: every card has a valid id, plays on tap, and nothing loads before that.
await page.goto(origin + '/guider');
const cards = page.locator('.guide-card');
assert.equal(await cards.count(), 3);
const titles = [];
for (let i = 0; i < 3; i++) {
const card = cards.nth(i);
assert.match(await card.getAttribute('data-youtube'), /^[A-Za-z0-9_-]{11}$/, `card ${i} has a valid id`);
const b = card.locator('.guide-play');
assert.equal(await b.isDisabled(), false, `card ${i} playable`);
assert.equal(await card.locator('.guide-badge.soon').count(), 0);
titles.push(await b.getAttribute('data-title'));
for (const a of await card.locator('.guide-links a').all()) assert((await a.boundingBox()).height >= 44, 'link target >= 44 px');
}
assert.deepEqual(titles, ['Danske kort og lag', 'Terrænprofil mellem to noder', 'Skråfoto af din node']);
assert.deepEqual(external, [], 'no external request on /guider before play');

// With ids: nothing from YouTube until the tap; the tap swaps in the nocookie iframe.
await page.goto(origin + '/guider-ids');
assert.deepEqual(external, [], 'no external request before play');
assert.equal(await cards.nth(1).locator('.guide-badge.soon').textContent(), 'Video på vej');
assert.match(await cards.nth(2).locator('.guide-play').getAttribute('aria-label'), /video på vej$/);
const first = cards.nth(0).locator('.guide-play');
assert.equal(await first.isDisabled(), false);
assert.equal(await first.getAttribute('aria-label'), 'Afspil video: Danske kort og lag');
assert.equal(await cards.nth(1).locator('.guide-play').isDisabled(), true, 'malformed id stays disabled');
assert.equal(await cards.nth(2).locator('.guide-play').isDisabled(), true, 'empty id stays disabled');
await first.tap();
const frame = cards.nth(0).locator('iframe');
await frame.waitFor();
const src = await frame.getAttribute('src');
assert.equal(new URL(src).origin, 'https://www.youtube-nocookie.com');
assert.equal(new URL(src).pathname, '/embed/' + VALID);
assert.equal(new URL(src).searchParams.get('autoplay'), '1');
assert.equal(await frame.getAttribute('title'), 'Danske kort og lag');
assert.equal(await cards.nth(0).locator('.guide-play').count(), 0, 'button replaced by the player');
assert(external.some(u => u.startsWith('https://www.youtube-nocookie.com/embed/' + VALID)), 'player requested after the tap');
assert(!external.some(u => /youtube\.com|ytimg|googlevideo/.test(new URL(u).hostname) && !u.startsWith('https://www.youtube-nocookie.com/')), 'only the nocookie host');
assert.deepEqual(errors, []);
console.log('PASS: /guider published ids, click-to-play, disabled cards without ids, one nav link per page, no external request before play');
})().catch(e => { console.error(e); process.exitCode = 1; }).finally(async () => {
if (browser) await browser.close();
await new Promise(resolve => server.close(resolve));
clearTimeout(timeout);
});
4 changes: 2 additions & 2 deletions sites/meshview-info/test-mobile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const http = require('node:http');
const fs = require('node:fs');
const path = require('node:path');
const { chromium } = require('playwright');
const routes = { '/velkommen': 'index.html', '/observer': 'observer.html', '/hardware': 'hardware.html', '/radio': 'radio.html' };
const routes = { '/velkommen': 'index.html', '/observer': 'observer.html', '/hardware': 'hardware.html', '/radio': 'radio.html', '/guider': 'guider.html' };
const expected = 'set wifi.ssid NAVN_PÅ_WIFI\nset wifi.pwd KODE_TIL_WIFI\nset mqtt.iata DIT_IATA\nset mqtt1.preset custom\nset mqtt1.server wss://mqtt.meshview.dk:443/mqtt\nset mqtt1.audience mqtt.meshview.dk\nset mqtt1.topic meshcore/{iata}/{device}/{type}\nset mqtt.owner DIT_PUB_KEY\nreboot';
const server = http.createServer((req, res) => {
const url = new URL(req.url, 'http://localhost');
Expand All @@ -19,7 +19,7 @@ const server = http.createServer((req, res) => {
let file = routes[url.pathname.replace(/\/$/, '')];
if (url.pathname.startsWith('/meshview-info-assets/')) file = 'assets/' + url.pathname.slice('/meshview-info-assets/'.length);
if (!file || file.includes('..') || !fs.existsSync(path.join(__dirname, file))) { res.statusCode = 404; return res.end(); }
res.setHeader('Content-Type', file.endsWith('.css') ? 'text/css' : file.endsWith('.js') ? 'text/javascript' : file.endsWith('.ttf') ? 'font/ttf' : 'text/html; charset=utf-8');
res.setHeader('Content-Type', file.endsWith('.css') ? 'text/css' : file.endsWith('.js') ? 'text/javascript' : file.endsWith('.ttf') ? 'font/ttf' : file.endsWith('.jpg') ? 'image/jpeg' : 'text/html; charset=utf-8');
res.end(fs.readFileSync(path.join(__dirname, file)));
});
let browser;
Expand Down
Loading