diff --git a/app-public/src/routes/+layout.svelte b/app-public/src/routes/+layout.svelte index 44d5553..f60f23e 100644 --- a/app-public/src/routes/+layout.svelte +++ b/app-public/src/routes/+layout.svelte @@ -13,9 +13,13 @@ import Footer from '$lib/components/Footer.svelte'; import { createBasketStore, setBasketContext } from '$lib/basket.svelte'; import { rootStyleTag, siteThemeVars } from '$shared/theme'; + import { thumbUrl } from '$shared/pb'; let { children, data } = $props(); + // The logo from Site design is the tab icon (a 300×300 thumbnail, not the full upload). + let icon = $derived(data.header?.logo?.url ? thumbUrl(data.header.logo.url) : favicon); + // One basket store per public layout instance — provided to all children // (Header indicator, ShopBlock, CheckoutBlock). Never module-level state. const basketStore = createBasketStore(data.basket ?? null); @@ -27,7 +31,9 @@ - + + + {#if icon !== favicon}{/if} diff --git a/packages/shared/src/pb.ts b/packages/shared/src/pb.ts index 0797bb5..c8ac7a7 100644 --- a/packages/shared/src/pb.ts +++ b/packages/shared/src/pb.ts @@ -20,3 +20,14 @@ export function createPocketBase(authCookie?: string, url = pbUrl) { export function getFileUrl(collectionIdOrName: string, recordId: string, filename: string) { return `${pbUrl}/api/files/${collectionIdOrName}/${recordId}/${filename}`; } + +/** + * A small version of an uploaded image: PocketBase makes thumbnails of media + * files in the sizes listed on the field (`media.file` has 300x300, cropped + * to fill). Other URLs (and SVGs, which PocketBase doesn't resize) are + * returned as they are. + */ +export function thumbUrl(url: string, size: '300x300' | '1200x0' = '300x300') { + if (!url.includes('/api/files/') || /\.svg(\?|$)/i.test(url)) return url; + return `${url}${url.includes('?') ? '&' : '?'}thumb=${size}`; +}