Skip to content

armgit / kiln

Public Imported from GitHub
0

Build and revise procedural 3D assets with your coding agent. Local MCP server, CLI and TypeScript engine with rendered review, editable source and GLB export.

site: real favicon.ico plus 48/96px PNG icons (#281)

Matthew Kissingerb599c4c0cbb1
diff --git a/site/.gitignore b/site/.gitignore
index dae3f9b6..259b741f 100644
--- a/site/.gitignore
+++ b/site/.gitignore
@@ -7,6 +7,7 @@ public/social/
public/fonts/
public/apple-touch-icon.png
public/favicon-*.png
+public/favicon.ico
public/standalone/
public/scene-packs/
public/scene-runtime/
diff --git a/site/scripts/build-site-media.mjs b/site/scripts/build-site-media.mjs
index fe87f9b8..548f3db4 100644
--- a/site/scripts/build-site-media.mjs
+++ b/site/scripts/build-site-media.mjs
@@ -23,6 +23,25 @@ export const staleSocialCards = (files, cards) => {
return files.filter((file) => /\.(?:webp|jpe?g|png)$/.test(file) && !wanted.has(file)).sort();
};
+/** An ICO file whose entries are PNG images (supported by every current browser and crawler). */
+export function pngIco(entries) {
+ const header = Buffer.alloc(6 + entries.length * 16);
+ header.writeUInt16LE(1, 2);
+ header.writeUInt16LE(entries.length, 4);
+ let offset = header.length;
+ entries.forEach(([size, png], index) => {
+ const at = 6 + index * 16;
+ header.writeUInt8(size >= 256 ? 0 : size, at);
+ header.writeUInt8(size >= 256 ? 0 : size, at + 1);
+ header.writeUInt16LE(1, at + 4);
+ header.writeUInt16LE(32, at + 6);
+ header.writeUInt32LE(png.length, at + 8);
+ header.writeUInt32LE(offset, at + 12);
+ offset += png.length;
+ });
+ return Buffer.concat([header, ...entries.map(([, png]) => png)]);
+}
+
export function chromeExecutable() {
const candidates = [
process.env.CHROME_PATH,
@@ -55,10 +74,15 @@ async function buildMedia() {
if (!logoPaths) throw new Error('Logo.astro has no inline SVG mark');
const logo = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">${logoPaths}</svg>`;
await writeFile(join(publicDir, 'favicon.svg'), logo);
- for (const size of [16, 32, 180]) {
+ const icons = new Map();
+ for (const size of [16, 32, 48, 96, 180]) {
const file = size === 180 ? 'apple-touch-icon.png' : `favicon-${size}.png`;
- await sharp(Buffer.from(logo)).resize(size, size).flatten({ background: '#eee9df' }).png().toFile(join(publicDir, file));
+ const png = await sharp(Buffer.from(logo)).resize(size, size).flatten({ background: '#eee9df' }).png().toBuffer();
+ await writeFile(join(publicDir, file), png);
+ icons.set(size, png);
}
+ // Search engines (Bing especially) still fetch /favicon.ico directly.
+ await writeFile(join(publicDir, 'favicon.ico'), pngIco([16, 32, 48].map((size) => [size, icons.get(size)])));
const release = await json(join(site, '../.github/published-candidate.json'));
const farm = await json(join(site, 'src/data/packs/farm.json'));
diff --git a/site/scripts/build-site-media.test.ts b/site/scripts/build-site-media.test.ts
index f20b1302..d8615173 100644
--- a/site/scripts/build-site-media.test.ts
+++ b/site/scripts/build-site-media.test.ts
@@ -1,5 +1,5 @@
import { expect, test } from 'bun:test';
-import { SOCIAL_CARD_EXTENSION, staleSocialCards } from './build-site-media.mjs';
+import { SOCIAL_CARD_EXTENSION, pngIco, staleSocialCards } from './build-site-media.mjs';
// Share cards are JPEG: every network's crawler reads JPEG and PNG, and the previous site's fixture required a PNG after two
// LinkedIn-specific preview fixes (#111, #112), so a format only some crawlers document (WebP) is not used for them.
@@ -22,3 +22,17 @@ test('only card images are candidates, and nothing is stale when every card is u
expect(staleSocialCards(['home.jpg', 'notes.txt', '.gitkeep'], [{ slug: 'home' }])).toEqual([]);
expect(staleSocialCards([], [{ slug: 'home' }])).toEqual([]);
});
+
+test('favicon.ico wraps each PNG with a directory entry', () => {
+ const small = Buffer.from([1, 2, 3]);
+ const large = Buffer.from([4, 5, 6, 7]);
+ const ico = pngIco([[16, small], [48, large]]);
+ expect(ico.readUInt16LE(2)).toBe(1);
+ expect(ico.readUInt16LE(4)).toBe(2);
+ expect(ico.readUInt8(6)).toBe(16);
+ expect(ico.readUInt32LE(6 + 8)).toBe(3);
+ expect(ico.readUInt32LE(6 + 12)).toBe(38);
+ expect(ico.readUInt8(22)).toBe(48);
+ expect(ico.readUInt32LE(22 + 12)).toBe(41);
+ expect(ico.subarray(41)).toEqual(large);
+});
diff --git a/site/src/layouts/BaseLayout.astro b/site/src/layouts/BaseLayout.astro
index 4f0e7f5a..63322250 100644
--- a/site/src/layouts/BaseLayout.astro
+++ b/site/src/layouts/BaseLayout.astro
@@ -89,8 +89,11 @@ const structured = [
<meta name="twitter:description" content={pageDescription} />
<meta name="twitter:image" content={social.url} />
<meta name="twitter:image:alt" content={social.alt} />
+ <link rel="icon" href="/favicon.ico" sizes="16x16 32x32 48x48" />
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
<link rel="icon" href="/favicon-32.png" sizes="32x32" type="image/png" />
+ <link rel="icon" href="/favicon-48.png" sizes="48x48" type="image/png" />
+ <link rel="icon" href="/favicon-96.png" sizes="96x96" type="image/png" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link
rel="preload"