Leaf and Kettle wants customers to add the shop to their phone's home screen and open it like an app. Browsers need a web app manifest for that. Write app/manifest.ts: its default export returns a MetadataRoute.Manifest object, which Next.js serves as JSON at /manifest.webmanifest.
Take the app's name, short_name, description, theme_color, and background_color from brand in @/lib/brand.
The installed app opens on the home page, in a window of its own: display: "standalone", scope: "/", and start_url: "/?source=pwa", so the shop's analytics can tell visits from the app. Set id to "/" as well.
List every icon in appIcons, in order, each as { src, sizes, type, purpose }: src is its file, sizes is its size twice, like "192x192", type is "image/png", and purpose is "maskable" for a maskable icon and "any" for the others.
GET /manifest.webmanifest
{
"id": "/",
"name": "Leaf and Kettle",
"short_name": "Leaf&Kettle",
"start_url": "/?source=pwa",
"display": "standalone",
...
"icons": [
{ "src": "/icons/kettle-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" },
...
]
}
lib/brand.ts, read-only. Import it as @/lib/brand.
/** Leaf and Kettle's name and colors, as the designers chose them. */
export const brand = {
name: "Leaf and Kettle",
/** For the home screen, which has room for about 12 characters under an icon. */
shortName: "Leaf&Kettle",
description: "Loose-leaf teas, brewing guides, and a kettle that's always on.",
/** For the title bar and the phone's status bar. */
themeColor: "#2f5d3a",
/** For the splash screen, while the app starts. */
backgroundColor: "#fbf8f1",
};
/**
* The app icons in public/icons, all PNG files. A maskable icon keeps its kettle inside the middle 80%,
* so a phone can crop it to a circle or a rounded square without cutting any of it off.
*/
export const appIcons = [
{ file: "/icons/kettle-192.png", size: 192, maskable: false },
{ file: "/icons/kettle-512.png", size: 512, maskable: false },
{ file: "/icons/kettle-maskable-512.png", size: 512, maskable: true },
];
const manifest = await Manifest();
expect(manifest.name).toBe("Leaf and Kettle");
expect(manifest.short_name).toBe("Leaf&Kettle");
expect(manifest.description).toBe("Loose-leaf teas, brewing guides, and a kettle that's always on.");
const manifest = await Manifest();
expect(manifest.display).toBe("standalone");
expect(manifest.scope).toBe("/");
expect(manifest.start_url).toBe("/?source=pwa");
expect((await Manifest()).id).toBe("/");
const manifest = await Manifest();
expect(manifest.theme_color).toBe("#2f5d3a");
expect(manifest.background_color).toBe("#fbf8f1");
expect((await Manifest()).icons).toEqual([
{ src: "/icons/kettle-192.png", sizes: "192x192", type: "image/png", purpose: "any" },
{ src: "/icons/kettle-512.png", sizes: "512x512", type: "image/png", purpose: "any" },
{ src: "/icons/kettle-maskable-512.png", sizes: "512x512", type: "image/png", purpose: "maskable" },
]);
Run tests runs every test on your code, here in your browser. The problem is solved when they all pass.
Ctrl + Enter runs the tests (⌘ + Enter on a Mac).
I'm here to help with A web app manifest to install the shop. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.