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
Check · Review · Land · Live done — Landed and live in production.
mason/speed-to-lead:mason/14-give-the-app-its-own-icon-in-the-browser → main 1 commit fork
5 files
changed +39
−1
src/pages/layout.ts +3 −1
| @@ -38,7 +38,9 @@ export function layout(input: { | ||
| 38 | 38 | <meta name="color-scheme" content="light dark"> |
| 39 | 39 | <meta name="theme-color" content="${token("color-bg")}" media="(prefers-color-scheme: light)"> |
| 40 | 40 | <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)}"> | |
| 42 | 44 | <title>${escape(name)}</title> |
| 43 | 45 | <meta name="description" content="${escape(description)}"> |
| 44 | 46 | <meta property="og:type" content="website"> |
src/routes.ts +12
| @@ -33,6 +33,7 @@ import { permit } from "./contract.ts"; | ||
| 33 | 33 | import { CADENCE, MAX_BODY, SOURCES } from "./drafts.ts"; |
| 34 | 34 | import { commit, env, forgeUrl, startedAt, version } from "./env.ts"; |
| 35 | 35 | import { |
| 36 | asset, | |
| 36 | 37 | back, |
| 37 | 38 | escape, |
| 38 | 39 | fields, |
| @@ -746,6 +747,17 @@ export const routes: readonly Route[] = [ | ||
| 746 | 747 | }), |
| 747 | 748 | }, |
| 748 | 749 | |
| 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 | ||
| 749 | 761 | // Files under ./static, cached for a year when linked by content (`asset`). |
| 750 | 762 | { |
| 751 | 763 | method: "GET", |
src/server.test.ts +23
| @@ -416,6 +416,29 @@ test("static files are cached for a year when linked by content", async () => { | ||
| 416 | 416 | expect((await fetch(base + "/static/..%2Fpackage.json")).status).toBe(404); |
| 417 | 417 | }); |
| 418 | 418 | |
| 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 | ||
| 419 | 442 | test("/healthz says up, apart from the page", async () => { |
| 420 | 443 | const response = await fetch(base + "/healthz"); |
| 421 | 444 | 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> |
new above
offline