@luhtech/site-template 0.15.0 → 0.15.1

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
@@ -361,8 +361,10 @@ Two bins go with it:
361
361
 
362
362
  - **`luhtech-sync-icons <brand.json> [--public <dir>] [--check]`** renders
363
363
  `public/favicon.svg` to `apple-touch-icon.png` (180px, on the brand
364
- canvas colour), `icon-192.png` and `icon-512.png`, and writes
365
- `site.webmanifest` from the brand's name and colours. Commit the output;
364
+ canvas colour), `icon-192.png`, `icon-512.png` and `favicon.ico`
365
+ (16/32/48px -- never linked, but browsers and crawlers request it on
366
+ their own; 0.15.1), and writes `site.webmanifest` from the brand's name
367
+ and colours. Commit the output;
366
368
  `--check` exits 1 if any of it is missing or stale.
367
369
  - **`luhtech-seo-check [dist]`** checks every built page after
368
370
  `astro build`. Errors (exit 1): no title, description, canonical, icon
@@ -8,6 +8,8 @@
8
8
  * icon-192.png 192x192, transparent
9
9
  * icon-512.png 512x512, transparent
10
10
  * site.webmanifest name, short_name, icons, theme/background colour
11
+ * favicon.ico 16, 32 and 48px, transparent -- browsers and crawlers
12
+ * request /favicon.ico whatever the page links
11
13
  *
12
14
  * SiteLayout links each of these only when the file exists, so running
13
15
  * this is what turns them on for a site. Re-run when favicon.svg or the
@@ -59,6 +61,34 @@ export function paddedSvg(svg, background, padding = APPLE_PADDING) {
59
61
  return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect width="100" height="100" fill="${background}"/>${inner}</svg>`;
60
62
  }
61
63
 
64
+ export const ICO_SIZES = [16, 32, 48];
65
+
66
+ // An ICO file holding PNG images (supported by every current browser and
67
+ // by Windows since Vista): a 6-byte header, one 16-byte directory entry
68
+ // per image, then the PNG bytes themselves.
69
+ export function buildIco(pngs) {
70
+ const header = Buffer.alloc(6);
71
+ header.writeUInt16LE(0, 0); // reserved
72
+ header.writeUInt16LE(1, 2); // type: icon
73
+ header.writeUInt16LE(pngs.length, 4);
74
+ const entries = [];
75
+ let offset = 6 + 16 * pngs.length;
76
+ for (const { size, data } of pngs) {
77
+ const e = Buffer.alloc(16);
78
+ e.writeUInt8(size >= 256 ? 0 : size, 0); // width (0 means 256)
79
+ e.writeUInt8(size >= 256 ? 0 : size, 1); // height
80
+ e.writeUInt8(0, 2); // palette colours
81
+ e.writeUInt8(0, 3); // reserved
82
+ e.writeUInt16LE(1, 4); // colour planes
83
+ e.writeUInt16LE(32, 6); // bits per pixel
84
+ e.writeUInt32LE(data.length, 8);
85
+ e.writeUInt32LE(offset, 12);
86
+ entries.push(e);
87
+ offset += data.length;
88
+ }
89
+ return Buffer.concat([header, ...entries, ...pngs.map((p) => p.data)]);
90
+ }
91
+
62
92
  async function render(svg, size) {
63
93
  const { Resvg } = await import('@resvg/resvg-js');
64
94
  return new Resvg(svg, { fitTo: { mode: 'width', value: size } }).render().asPng();
@@ -88,6 +118,7 @@ async function main() {
88
118
  ['icon-192.png', await render(svg, 192)],
89
119
  ['icon-512.png', await render(svg, 512)],
90
120
  ['site.webmanifest', Buffer.from(buildManifest(brand))],
121
+ ['favicon.ico', buildIco(await Promise.all(ICO_SIZES.map(async (size) => ({ size, data: await render(svg, size) }))))],
91
122
  ];
92
123
 
93
124
  let stale = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luhtech/site-template",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
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",
@@ -17,6 +17,9 @@ export const ICON_FILES = {
17
17
  manifest: 'site.webmanifest',
18
18
  } as const;
19
19
 
20
+ // favicon.ico is generated too (luhtech-sync-icons) but never linked:
21
+ // browsers and crawlers request /favicon.ico on their own.
22
+
20
23
  export type IconFile = (typeof ICON_FILES)[keyof typeof ICON_FILES];
21
24
 
22
25
  export interface BrandLike {