@luhtech/site-template 0.20.1 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -0
- package/bin/luhtech-device-smoke.mjs +179 -0
- package/package.json +10 -3
- package/src/components/VentureMark.astro +3 -2
- package/src/layouts/SiteLayout.astro +15 -2
- package/src/lib/markReplay.ts +89 -0
- package/src/lib/seoHead.ts +28 -1
package/README.md
CHANGED
|
@@ -362,6 +362,46 @@ Two bins go with it:
|
|
|
362
362
|
link, `og:image` or `<html lang>`. Warnings: title over 60 characters,
|
|
363
363
|
description outside 70-160, anything but one `<h1>` -- those are content
|
|
364
364
|
edits, reported rather than blocking.
|
|
365
|
+
- **`luhtech-device-smoke [dist] [--site content/sites/<venture>.json]`**
|
|
366
|
+
(0.21.0, content/site 1.5.0 `devices`) loads every built page at each
|
|
367
|
+
device the site supports -- phone 390x844, tablet 820x1180 and 1180x820,
|
|
368
|
+
desktop 1440x900; all three when the record has no `devices` -- and exits
|
|
369
|
+
1 on a missing or zoom-locking viewport, a page wider than the screen, no
|
|
370
|
+
visible header link or menu button, or, for `devices.installable`, a
|
|
371
|
+
missing manifest link, apple-touch-icon or `apple-mobile-web-app-capable`.
|
|
372
|
+
Needs Playwright, an optional peer: `npm i -D playwright && npx playwright
|
|
373
|
+
install chromium`. `SiteLayout` emits the web-app meta for an installable
|
|
374
|
+
site.
|
|
375
|
+
|
|
376
|
+
## An animated mark replays when clicked (0.22.0)
|
|
377
|
+
|
|
378
|
+
Every animated mark ran once on load and then sat on its last frame;
|
|
379
|
+
clicking it did nothing. `SiteLayout` now installs one replay for every
|
|
380
|
+
element on the page carrying `data-mark-replay="<group>"`:
|
|
381
|
+
|
|
382
|
+
- **Inline markup** (an `<svg>`, or a wrapper around one, animated with
|
|
383
|
+
CSS) restarts its animations in place. `VentureMark` sets
|
|
384
|
+
`data-mark-replay="venture"` on an animated mark.
|
|
385
|
+
- **An `<img>` of an animated SVG** gets a fresh `data:` URL of the
|
|
386
|
+
animated file, so the browser draws it from frame 0. Point
|
|
387
|
+
`data-mark-replay-src` at the animated file when the `<img>` shows a
|
|
388
|
+
static one at rest (Ectropy's lockup, which its reveal ends on). `data:`
|
|
389
|
+
rather than `blob:`, because a CSP like ectropy.ai's allows `data:`
|
|
390
|
+
images and not `blob:`.
|
|
391
|
+
|
|
392
|
+
A click on a mark whose link opens this same page replays it and does not
|
|
393
|
+
reload, so the nav logo (linked to `/`) replays on the landing page. From
|
|
394
|
+
any other page it is an ordinary link home. A link to another origin, or
|
|
395
|
+
one opened in a new tab, is left alone. Under
|
|
396
|
+
`prefers-reduced-motion: reduce` nothing replays.
|
|
397
|
+
|
|
398
|
+
A site opts its nav logo in on the element it passes to the `logo` slot:
|
|
399
|
+
|
|
400
|
+
```astro
|
|
401
|
+
<Fragment slot="logo">
|
|
402
|
+
<img src="/brand/x-lockup.svg" data-mark-replay="nav" data-mark-replay-src="/brand/x-mark-animated.svg" alt="X" />
|
|
403
|
+
</Fragment>
|
|
404
|
+
```
|
|
365
405
|
|
|
366
406
|
## Migrating a venture site
|
|
367
407
|
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Loads every built HTML page under a site's dist/ at each device the site
|
|
4
|
+
* supports and fails when a page does not work there
|
|
5
|
+
* (d-2026-10-19-sr-site-devices; content/site.schema.json 1.5.0 `devices`).
|
|
6
|
+
* Run after `astro build`, like luhtech-seo-check.
|
|
7
|
+
*
|
|
8
|
+
* Errors (exit 1), per page and device:
|
|
9
|
+
* - no viewport meta, or one without width=device-width, or one that locks
|
|
10
|
+
* zoom (user-scalable=no, maximum-scale=1)
|
|
11
|
+
* - the page is wider than the screen (horizontal scroll)
|
|
12
|
+
* - no visible way to navigate in the header (a link, or a menu button)
|
|
13
|
+
* - devices.installable and a manifest link, an apple-touch-icon or
|
|
14
|
+
* apple-mobile-web-app-capable missing
|
|
15
|
+
*
|
|
16
|
+
* Devices: phone 390x844 (touch), tablet 820x1180 and 1180x820 (touch),
|
|
17
|
+
* desktop 1440x900. A site whose record omits `devices` is held to all three.
|
|
18
|
+
*
|
|
19
|
+
* Needs Playwright (an optional peer dependency) with Chromium installed:
|
|
20
|
+
* `npm i -D playwright && npx playwright install chromium`.
|
|
21
|
+
*
|
|
22
|
+
* Usage: luhtech-device-smoke [dist-dir] [--site <content/sites/x.json>]
|
|
23
|
+
*/
|
|
24
|
+
import { createServer } from 'node:http';
|
|
25
|
+
import { readFileSync, readdirSync, statSync, realpathSync, existsSync } from 'node:fs';
|
|
26
|
+
import { extname, join, relative, resolve } from 'node:path';
|
|
27
|
+
import { fileURLToPath } from 'node:url';
|
|
28
|
+
|
|
29
|
+
export const DEVICE_VIEWPORTS = {
|
|
30
|
+
phone: [{ label: 'phone', width: 390, height: 844, isMobile: true, hasTouch: true, deviceScaleFactor: 3 }],
|
|
31
|
+
tablet: [
|
|
32
|
+
{ label: 'tablet portrait', width: 820, height: 1180, isMobile: true, hasTouch: true, deviceScaleFactor: 2 },
|
|
33
|
+
{ label: 'tablet landscape', width: 1180, height: 820, isMobile: true, hasTouch: true, deviceScaleFactor: 2 },
|
|
34
|
+
],
|
|
35
|
+
desktop: [{ label: 'desktop', width: 1440, height: 900, isMobile: false, hasTouch: false, deviceScaleFactor: 1 }],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** The devices a site is held to: its record's `devices.supported`, or all three. */
|
|
39
|
+
export function devicesFor(site) {
|
|
40
|
+
const supported = site?.devices?.supported;
|
|
41
|
+
return Array.isArray(supported) && supported.length ? supported : ['phone', 'tablet', 'desktop'];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Problems with a page's viewport meta content (null when there is none). */
|
|
45
|
+
export function viewportProblems(content) {
|
|
46
|
+
if (content == null) return ['no viewport meta'];
|
|
47
|
+
const c = content.replace(/\s+/g, '').toLowerCase();
|
|
48
|
+
const problems = [];
|
|
49
|
+
if (!c.includes('width=device-width')) problems.push('viewport is not width=device-width');
|
|
50
|
+
if (/user-scalable=(no|0)/.test(c)) problems.push('viewport locks zoom (user-scalable=no)');
|
|
51
|
+
if (/maximum-scale=1(\.0+)?(,|$)/.test(c)) problems.push('viewport locks zoom (maximum-scale=1)');
|
|
52
|
+
return problems;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Install tags an installable page is missing. */
|
|
56
|
+
export function installProblems(html) {
|
|
57
|
+
const tags = html.match(/<(link|meta)\b[^>]*>/gi) ?? [];
|
|
58
|
+
const has = (re) => tags.some((t) => re.test(t));
|
|
59
|
+
const problems = [];
|
|
60
|
+
if (!has(/rel=["'][^"']*\bmanifest\b/i)) problems.push('installable, but no manifest link');
|
|
61
|
+
if (!has(/rel=["'][^"']*\bapple-touch-icon\b/i)) problems.push('installable, but no apple-touch-icon');
|
|
62
|
+
if (!has(/name=["']apple-mobile-web-app-capable["']/i)) problems.push('installable, but no apple-mobile-web-app-capable meta');
|
|
63
|
+
return problems;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function htmlFiles(dir) {
|
|
67
|
+
const out = [];
|
|
68
|
+
for (const entry of readdirSync(dir)) {
|
|
69
|
+
const full = join(dir, entry);
|
|
70
|
+
if (statSync(full).isDirectory()) out.push(...htmlFiles(full));
|
|
71
|
+
else if (entry.endsWith('.html')) out.push(full);
|
|
72
|
+
}
|
|
73
|
+
return out.sort();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const TYPES = {
|
|
77
|
+
'.html': 'text/html', '.css': 'text/css', '.js': 'text/javascript', '.mjs': 'text/javascript',
|
|
78
|
+
'.svg': 'image/svg+xml', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg',
|
|
79
|
+
'.webp': 'image/webp', '.ico': 'image/x-icon', '.json': 'application/json',
|
|
80
|
+
'.webmanifest': 'application/manifest+json', '.woff2': 'font/woff2', '.txt': 'text/plain',
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
function serve(dist) {
|
|
84
|
+
const server = createServer((req, res) => {
|
|
85
|
+
let path = decodeURIComponent(new URL(req.url, 'http://x').pathname);
|
|
86
|
+
let file = join(dist, path);
|
|
87
|
+
if (existsSync(file) && statSync(file).isDirectory()) file = join(file, 'index.html');
|
|
88
|
+
if (!existsSync(file)) {
|
|
89
|
+
res.writeHead(404);
|
|
90
|
+
res.end();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
res.writeHead(200, { 'content-type': TYPES[extname(file)] ?? 'application/octet-stream' });
|
|
94
|
+
res.end(readFileSync(file));
|
|
95
|
+
});
|
|
96
|
+
return new Promise((ok) => server.listen(0, '127.0.0.1', () => ok(server)));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function main() {
|
|
100
|
+
const args = process.argv.slice(2);
|
|
101
|
+
const siteAt = args.indexOf('--site');
|
|
102
|
+
const sitePath = siteAt >= 0 ? args[siteAt + 1] : null;
|
|
103
|
+
const distArg = args.find((a, i) => !a.startsWith('--') && i !== siteAt + 1);
|
|
104
|
+
const dist = resolve(process.cwd(), distArg ?? 'dist');
|
|
105
|
+
const site = sitePath ? JSON.parse(readFileSync(resolve(process.cwd(), sitePath), 'utf-8')) : null;
|
|
106
|
+
const installable = site?.devices?.installable === true;
|
|
107
|
+
const viewports = devicesFor(site).flatMap((d) => DEVICE_VIEWPORTS[d] ?? []);
|
|
108
|
+
|
|
109
|
+
let playwright;
|
|
110
|
+
try {
|
|
111
|
+
playwright = await import('playwright');
|
|
112
|
+
} catch {
|
|
113
|
+
console.error('luhtech-device-smoke needs Playwright: npm i -D playwright && npx playwright install chromium');
|
|
114
|
+
process.exitCode = 2;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const files = htmlFiles(dist);
|
|
119
|
+
const server = await serve(dist);
|
|
120
|
+
const origin = `http://127.0.0.1:${server.address().port}`;
|
|
121
|
+
const browser = await playwright.chromium.launch();
|
|
122
|
+
let errorCount = 0;
|
|
123
|
+
try {
|
|
124
|
+
for (const vp of viewports) {
|
|
125
|
+
const context = await browser.newContext({
|
|
126
|
+
viewport: { width: vp.width, height: vp.height },
|
|
127
|
+
isMobile: vp.isMobile,
|
|
128
|
+
hasTouch: vp.hasTouch,
|
|
129
|
+
deviceScaleFactor: vp.deviceScaleFactor,
|
|
130
|
+
});
|
|
131
|
+
const page = await context.newPage();
|
|
132
|
+
for (const file of files) {
|
|
133
|
+
const rel = relative(dist, file);
|
|
134
|
+
const path = '/' + rel.replace(/index\.html$/, '').replace(/\\/g, '/');
|
|
135
|
+
const problems = [];
|
|
136
|
+
await page.goto(origin + path, { waitUntil: 'load' });
|
|
137
|
+
const r = await page.evaluate(() => {
|
|
138
|
+
const visible = (el) => {
|
|
139
|
+
const b = el.getBoundingClientRect();
|
|
140
|
+
const s = getComputedStyle(el);
|
|
141
|
+
return b.width > 0 && b.height > 0 && s.visibility !== 'hidden' && s.display !== 'none';
|
|
142
|
+
};
|
|
143
|
+
const header = document.querySelector('header');
|
|
144
|
+
return {
|
|
145
|
+
viewport: document.querySelector('meta[name="viewport"]')?.getAttribute('content') ?? null,
|
|
146
|
+
scrollWidth: document.documentElement.scrollWidth,
|
|
147
|
+
innerWidth: window.innerWidth,
|
|
148
|
+
navReachable: header
|
|
149
|
+
? [...header.querySelectorAll('a[href], button')].some(visible)
|
|
150
|
+
: false,
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
problems.push(...viewportProblems(r.viewport));
|
|
154
|
+
if (r.scrollWidth > r.innerWidth + 1) {
|
|
155
|
+
problems.push(`page is ${r.scrollWidth}px wide on a ${r.innerWidth}px screen`);
|
|
156
|
+
}
|
|
157
|
+
if (!r.navReachable) problems.push('no visible header link or menu button');
|
|
158
|
+
if (installable) problems.push(...installProblems(readFileSync(file, 'utf-8')));
|
|
159
|
+
if (problems.length) {
|
|
160
|
+
console.log(`${rel} @ ${vp.label} ${vp.width}x${vp.height}`);
|
|
161
|
+
for (const p of problems) console.log(` error: ${p}`);
|
|
162
|
+
errorCount += problems.length;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
await context.close();
|
|
166
|
+
}
|
|
167
|
+
} finally {
|
|
168
|
+
await browser.close();
|
|
169
|
+
server.close();
|
|
170
|
+
}
|
|
171
|
+
console.log(
|
|
172
|
+
`\n${files.length} pages x ${viewports.length} viewports (${viewports.map((v) => v.label).join(', ')}): ${errorCount} errors.`
|
|
173
|
+
);
|
|
174
|
+
if (errorCount > 0) process.exitCode = 1;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
178
|
+
main();
|
|
179
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luhtech/site-template",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Shared Astro component library + content-instance contract for LuhTech venture marketing sites -- one template renders every site from content/page.schema.json + content/site.schema.json instances.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,14 +35,21 @@
|
|
|
35
35
|
"luhtech-sync-animated-marks": "bin/luhtech-sync-animated-marks.mjs",
|
|
36
36
|
"luhtech-sync-venture-directory": "bin/luhtech-sync-venture-directory.mjs",
|
|
37
37
|
"luhtech-sync-icons": "bin/luhtech-sync-icons.mjs",
|
|
38
|
-
"luhtech-seo-check": "bin/luhtech-seo-check.mjs"
|
|
38
|
+
"luhtech-seo-check": "bin/luhtech-seo-check.mjs",
|
|
39
|
+
"luhtech-device-smoke": "bin/luhtech-device-smoke.mjs"
|
|
39
40
|
},
|
|
40
41
|
"scripts": {
|
|
41
42
|
"test": "node --experimental-strip-types --test test/*.test.mjs"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
45
|
"astro": "^7.2",
|
|
45
|
-
"tailwindcss": "^4"
|
|
46
|
+
"tailwindcss": "^4",
|
|
47
|
+
"playwright": ">=1.40"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"playwright": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
46
53
|
},
|
|
47
54
|
"dependencies": {
|
|
48
55
|
"@lucide/astro": "^1.42.0",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
// /brand/{brandRef}-mark.svg file (onerror-hidden if even that's missing)
|
|
11
11
|
// for every venture that doesn't have one yet. Not every venture needs an
|
|
12
12
|
// animated mark for this to work; it degrades honestly per-venture
|
|
13
|
-
// instead of assuming universal coverage.
|
|
13
|
+
// instead of assuming universal coverage. An animated mark replays when
|
|
14
|
+
// clicked (data-mark-replay="venture", SiteLayout's installMarkReplay, 0.22.0).
|
|
14
15
|
import { VENTURE_MARKS } from '../lib/venture-marks.generated';
|
|
15
16
|
|
|
16
17
|
export interface Props {
|
|
@@ -21,7 +22,7 @@ const { brandRef, class: className = 'h-6 w-6 mb-2' } = Astro.props;
|
|
|
21
22
|
const animated = VENTURE_MARKS[brandRef];
|
|
22
23
|
---
|
|
23
24
|
{animated ? (
|
|
24
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox={animated.viewBox} class={className} role="img" aria-label={brandRef} set:html={animated.markup} />
|
|
25
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox={animated.viewBox} class={className} role="img" aria-label={brandRef} data-mark-replay="venture" set:html={animated.markup} />
|
|
25
26
|
) : (
|
|
26
27
|
<img
|
|
27
28
|
src={`/brand/${brandRef}-mark.svg`}
|
|
@@ -14,7 +14,7 @@ import Icon from '../components/Icon.astro';
|
|
|
14
14
|
import { existsSync } from 'node:fs';
|
|
15
15
|
import { join } from 'node:path';
|
|
16
16
|
import type { LoadedBrand } from '../content/loadBrand.js';
|
|
17
|
-
import { ICON_FILES, buildSeoHead } from '../lib/seoHead.js';
|
|
17
|
+
import { ICON_FILES, buildSeoHead, type SiteDevices } from '../lib/seoHead.js';
|
|
18
18
|
|
|
19
19
|
export interface Props {
|
|
20
20
|
site: LoadedSite;
|
|
@@ -30,7 +30,14 @@ const { site, page, brand } = Astro.props as Props;
|
|
|
30
30
|
const publicFiles = new Set(
|
|
31
31
|
Object.values(ICON_FILES).filter((f) => existsSync(join(process.cwd(), 'public', f)))
|
|
32
32
|
);
|
|
33
|
-
const head = buildSeoHead({
|
|
33
|
+
const head = buildSeoHead({
|
|
34
|
+
site: Astro.site,
|
|
35
|
+
pathname: Astro.url.pathname,
|
|
36
|
+
brand,
|
|
37
|
+
publicFiles,
|
|
38
|
+
// content/site 1.5.0 (d-2026-10-19-sr-site-devices): installable adds the web-app meta.
|
|
39
|
+
devices: site.devices as SiteDevices | undefined,
|
|
40
|
+
});
|
|
34
41
|
|
|
35
42
|
const seo = page.seo as { title: string; description: string; ogImage?: string; noindex?: boolean };
|
|
36
43
|
const footer = site.footer as { legalLine: string; parentHref?: string };
|
|
@@ -80,6 +87,7 @@ const linkItems = nav.filter((item) => item !== ctaItem);
|
|
|
80
87
|
|
|
81
88
|
{head.themeColor && <meta name="theme-color" content={head.themeColor} />}
|
|
82
89
|
{head.links.map((l) => <link rel={l.rel} href={l.href} type={l.type} sizes={l.sizes} />)}
|
|
90
|
+
{head.metas.map((m) => <meta name={m.name} content={m.content} />)}
|
|
83
91
|
|
|
84
92
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
85
93
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
@@ -159,6 +167,11 @@ const linkItems = nav.filter((item) => item !== ctaItem);
|
|
|
159
167
|
</div>
|
|
160
168
|
</footer>
|
|
161
169
|
<script>
|
|
170
|
+
// An animated mark replays when it is clicked: any [data-mark-replay]
|
|
171
|
+
// on the page, the nav logo and VentureMark included (0.22.0).
|
|
172
|
+
import { installMarkReplay } from '../lib/markReplay';
|
|
173
|
+
installMarkReplay();
|
|
174
|
+
|
|
162
175
|
// Mobile nav toggle. Plain click handler + classList, no
|
|
163
176
|
// framework/island needed for something this small -- matches
|
|
164
177
|
// this file's own existing no-js/reveal scripts' own approach.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// A venture's animated mark plays again when it is clicked (0.22.0,
|
|
2
|
+
// d-2026-10-20-st-mark-replay). L4 2026-10-20: "the logo does not animate
|
|
3
|
+
// when you click ... this applies on all svg animations per the template".
|
|
4
|
+
// Every animated mark in the pack ran once on load and then sat on its last
|
|
5
|
+
// frame: Ectropy's reveal once per browser session, luh.tech's drop-in and
|
|
6
|
+
// the VentureMark marks once per page. Clicking a mark did nothing visible.
|
|
7
|
+
//
|
|
8
|
+
// An element opts in with data-mark-replay="<group>". Two kinds of mark:
|
|
9
|
+
// - inline markup (an <svg> or a wrapper around one) whose CSS animations
|
|
10
|
+
// are restarted in place;
|
|
11
|
+
// - an <img> of an animated SVG, which a page cannot restart, so it gets
|
|
12
|
+
// a fresh data: URL of the animated file (data-mark-replay-src, else its
|
|
13
|
+
// own src). data:, not blob:, because ectropy.ai's CSP allows data: and
|
|
14
|
+
// https: images but not blob:. Each replay's URL differs by a trailing
|
|
15
|
+
// comment, so the browser draws a new image and its timeline starts at 0.
|
|
16
|
+
// A click that opens this same page replays in place and does not reload,
|
|
17
|
+
// so the nav logo (linked to "/") replays on the landing page. A click that
|
|
18
|
+
// opens any other page is an ordinary navigation (L4 2026-10-20: "logo
|
|
19
|
+
// replay only needs to happen on the landing page"). Reduced motion:
|
|
20
|
+
// nothing replays.
|
|
21
|
+
|
|
22
|
+
export const REPLAY_ATTR = 'data-mark-replay';
|
|
23
|
+
export const REPLAY_SRC_ATTR = 'data-mark-replay-src';
|
|
24
|
+
|
|
25
|
+
export type ReplayTarget = 'here' | 'next' | 'away';
|
|
26
|
+
|
|
27
|
+
/** Where a click on a mark lands: 'here' with no link or a link to this
|
|
28
|
+
* page, 'next' for another page of this site, 'away' for another origin. */
|
|
29
|
+
export function replayTarget(href: string | null | undefined, current: string): ReplayTarget {
|
|
30
|
+
if (!href) return 'here';
|
|
31
|
+
let to: URL;
|
|
32
|
+
let from: URL;
|
|
33
|
+
try {
|
|
34
|
+
from = new URL(current);
|
|
35
|
+
to = new URL(href, from);
|
|
36
|
+
} catch {
|
|
37
|
+
return 'here';
|
|
38
|
+
}
|
|
39
|
+
if (to.origin !== from.origin) return 'away';
|
|
40
|
+
const path = (u: URL) => u.pathname.replace(/\/index\.html$/, '/').replace(/(.)\/$/, '$1');
|
|
41
|
+
return path(to) === path(from) && to.search === from.search ? 'here' : 'next';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The data: URL for replay number n of an SVG's text. */
|
|
45
|
+
export function replayDataUrl(svgText: string, n: number): string {
|
|
46
|
+
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(`${svgText}<!--replay ${n}-->`)}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const svgText = new Map<string, Promise<string>>();
|
|
50
|
+
let replays = 0;
|
|
51
|
+
|
|
52
|
+
/** Play one mark from its first frame. */
|
|
53
|
+
export function replayMark(el: Element): void {
|
|
54
|
+
if (el.tagName === 'IMG') {
|
|
55
|
+
const img = el as HTMLImageElement;
|
|
56
|
+
const src = img.getAttribute(REPLAY_SRC_ATTR) || img.currentSrc || img.src;
|
|
57
|
+
if (!src) return;
|
|
58
|
+
if (!svgText.has(src)) {
|
|
59
|
+
svgText.set(src, fetch(src).then((r) => (r.ok ? r.text() : Promise.reject(new Error(`${r.status}`)))));
|
|
60
|
+
}
|
|
61
|
+
const n = ++replays;
|
|
62
|
+
svgText.get(src)!.then(
|
|
63
|
+
(text) => { img.src = replayDataUrl(text, n); },
|
|
64
|
+
() => { svgText.delete(src); },
|
|
65
|
+
);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (typeof el.getAnimations === 'function') {
|
|
69
|
+
for (const a of el.getAnimations({ subtree: true })) {
|
|
70
|
+
a.cancel();
|
|
71
|
+
a.play();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Wire every [data-mark-replay] on the page: a click on one whose link
|
|
77
|
+
* opens this page replays it. */
|
|
78
|
+
export function installMarkReplay(doc: Document = document, win: Window = window): void {
|
|
79
|
+
if (win.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
|
80
|
+
doc.addEventListener('click', (e) => {
|
|
81
|
+
const el = (e.target as Element | null)?.closest?.(`[${REPLAY_ATTR}]`);
|
|
82
|
+
if (!el) return;
|
|
83
|
+
const link = el.closest('a[href]') as HTMLAnchorElement | null;
|
|
84
|
+
if (link && (link.target === '_blank' || e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0)) return;
|
|
85
|
+
if (replayTarget(link?.getAttribute('href'), win.location.href) !== 'here') return;
|
|
86
|
+
if (link && new URL(link.href).hash === win.location.hash) e.preventDefault();
|
|
87
|
+
replayMark(el);
|
|
88
|
+
});
|
|
89
|
+
}
|
package/src/lib/seoHead.ts
CHANGED
|
@@ -36,6 +36,19 @@ export interface SeoHeadInput {
|
|
|
36
36
|
/** Which ICON_FILES exist in the consuming site's public/ directory. */
|
|
37
37
|
publicFiles: ReadonlySet<string>;
|
|
38
38
|
locale?: string;
|
|
39
|
+
/** content/site 1.5.0 devices: installable adds the iOS/Android web-app meta. */
|
|
40
|
+
devices?: SiteDevices;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** content/site.schema.json 1.5.0 `devices` (d-2026-10-19-sr-site-devices). */
|
|
44
|
+
export interface SiteDevices {
|
|
45
|
+
supported: Array<'phone' | 'tablet' | 'desktop'>;
|
|
46
|
+
installable?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface MetaTag {
|
|
50
|
+
name: string;
|
|
51
|
+
content: string;
|
|
39
52
|
}
|
|
40
53
|
|
|
41
54
|
export interface LinkTag {
|
|
@@ -51,6 +64,8 @@ export interface SeoHead {
|
|
|
51
64
|
locale: string;
|
|
52
65
|
themeColor: string | null;
|
|
53
66
|
links: LinkTag[];
|
|
67
|
+
/** Web-app meta for an installable site (content/site devices.installable). */
|
|
68
|
+
metas: MetaTag[];
|
|
54
69
|
}
|
|
55
70
|
|
|
56
71
|
export function canonicalUrl(site: URL | string | undefined, pathname: string): string | null {
|
|
@@ -67,12 +82,24 @@ export function buildSeoHead(input: SeoHeadInput): SeoHead {
|
|
|
67
82
|
if (publicFiles.has(ICON_FILES.png192)) links.push({ rel: 'icon', href: `/${ICON_FILES.png192}`, type: 'image/png', sizes: '192x192' });
|
|
68
83
|
if (publicFiles.has(ICON_FILES.appleTouch)) links.push({ rel: 'apple-touch-icon', href: `/${ICON_FILES.appleTouch}`, sizes: '180x180' });
|
|
69
84
|
if (publicFiles.has(ICON_FILES.manifest)) links.push({ rel: 'manifest', href: `/${ICON_FILES.manifest}` });
|
|
85
|
+
// An installable site opens from the home screen without browser chrome. The
|
|
86
|
+
// status bar keeps its default style so content never sits under it.
|
|
87
|
+
const siteName = brand?.identity?.name ?? null;
|
|
88
|
+
const metas: MetaTag[] = input.devices?.installable
|
|
89
|
+
? [
|
|
90
|
+
{ name: 'mobile-web-app-capable', content: 'yes' },
|
|
91
|
+
{ name: 'apple-mobile-web-app-capable', content: 'yes' },
|
|
92
|
+
{ name: 'apple-mobile-web-app-status-bar-style', content: 'default' },
|
|
93
|
+
...(siteName ? [{ name: 'apple-mobile-web-app-title', content: siteName }] : []),
|
|
94
|
+
]
|
|
95
|
+
: [];
|
|
70
96
|
return {
|
|
71
97
|
canonical,
|
|
72
|
-
siteName
|
|
98
|
+
siteName,
|
|
73
99
|
locale: input.locale ?? 'en_US',
|
|
74
100
|
// The header renders on bg-ink, so the browser chrome matches it.
|
|
75
101
|
themeColor: brand?.color?.foundation?.ink?.hex ?? null,
|
|
76
102
|
links,
|
|
103
|
+
metas,
|
|
77
104
|
};
|
|
78
105
|
}
|