Public: anyone can read this; the crew can change it.

Give the app its own icon in the browser tab and on a phone home screen #16

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/speed-to-lead:mason/14-give-the-app-its-own-icon-in-the-browser → main 1 commit fork

  • Merged. mason/14-give-the-app-its-own-icon-in-the-browser was merged into main as 7e4f6d9.

Review

Sign in to review this change.
5 files changed +39 −1
src/pages/layout.ts +3 −1
@@ -38,7 +38,9 @@ export function layout(input: {
3838 <meta name="color-scheme" content="light dark">
3939 <meta name="theme-color" content="${token("color-bg")}" media="(prefers-color-scheme: light)">
4040 <meta name="theme-color" content="${token("color-bg", "dark")}" media="(prefers-color-scheme: dark)">
41 <link rel="icon" href="data:,">
41 <link rel="icon" type="image/svg+xml" href="${asset("icon.svg")}">
42 <link rel="apple-touch-icon" href="${asset("apple-touch-icon.png")}">
43 <meta name="apple-mobile-web-app-title" content="${escape(title)}">
4244 <title>${escape(name)}</title>
4345 <meta name="description" content="${escape(description)}">
4446 <meta property="og:type" content="website">
src/routes.ts +12
@@ -33,6 +33,7 @@ import { permit } from "./contract.ts";
3333 import { CADENCE, MAX_BODY, SOURCES } from "./drafts.ts";
3434 import { commit, env, forgeUrl, startedAt, version } from "./env.ts";
3535 import {
36 asset,
3637 back,
3738 escape,
3839 fields,
@@ -746,6 +747,17 @@ export const routes: readonly Route[] = [
746747 }),
747748 },
748749
750 // Browsers ask for /favicon.ico whatever the page links: send them to the mark.
751 {
752 method: "GET",
753 path: "/favicon.ico",
754 handle: () =>
755 new Response(null, {
756 status: 302,
757 headers: { location: asset("icon.svg"), ...SECURITY },
758 }),
759 },
760
749761 // Files under ./static, cached for a year when linked by content (`asset`).
750762 {
751763 method: "GET",
src/server.test.ts +23
@@ -416,6 +416,29 @@ test("static files are cached for a year when linked by content", async () => {
416416 expect((await fetch(base + "/static/..%2Fpackage.json")).status).toBe(404);
417417 });
418418
419 test("every page links the icon, and the icon and /favicon.ico answer", async () => {
420 for (const path of ["/", "/profile"]) {
421 const page = await (await fetch(base + path)).text();
422 expect(page).toMatch(
423 /<link rel="icon" type="image\/svg\+xml" href="\/static\/icon\.svg\?v=[0-9a-f]{8}">/,
424 );
425 expect(page).toContain('<link rel="apple-touch-icon" href="/static/apple-touch-icon.png?v=');
426 expect(page).toContain('<meta name="apple-mobile-web-app-title" content="Speed to Lead">');
427 }
428 const page = await (await fetch(base + "/")).text();
429 const svg = /href="(\/static\/icon\.svg\?v=[0-9a-f]{8})"/.exec(page)?.[1];
430 const icon = await fetch(base + svg!);
431 expect(icon.status).toBe(200);
432 expect(icon.headers.get("content-type")).toContain("image/svg+xml");
433 expect(icon.headers.get("x-content-type-options")).toBe("nosniff");
434 const png = await fetch(base + "/static/apple-touch-icon.png");
435 expect(png.headers.get("content-type")).toContain("image/png");
436 const ico = await fetch(base + "/favicon.ico", { redirect: "manual" });
437 expect(ico.status).toBe(302);
438 expect(ico.headers.get("location")).toBe(svg!);
439 expect(ico.headers.get("x-content-type-options")).toBe("nosniff");
440 });
441
419442 test("/healthz says up, apart from the page", async () => {
420443 const response = await fetch(base + "/healthz");
421444 expect(response.status).toBe(200);
static/apple-touch-icon.png added
Binary file not shown.
static/icon.svg added +1
@@ -0,0 +1,1 @@
1 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="14" fill="#1e5a44"/><circle cx="32" cy="32" r="21" fill="#f6f3ec"/><path d="M32 18v14l9 6" fill="none" stroke="#1e5a44" stroke-width="4.5" stroke-linecap="round" stroke-linejoin="round"/></svg>

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs