@luhtech/site-template 0.20.1 → 0.21.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 CHANGED
@@ -362,6 +362,16 @@ 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.
365
375
 
366
376
  ## Migrating a venture site
367
377
 
@@ -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.20.1",
3
+ "version": "0.21.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",
@@ -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({ site: Astro.site, pathname: Astro.url.pathname, brand, publicFiles });
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 />
@@ -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: brand?.identity?.name ?? null,
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
  }