Use the Site design logo as the favicon (site and admin) #11

Merged
reudy merged 2 commits from logo-favicon into main 2026-10-26 14:20:07 +01:00
2 changed files with 18 additions and 1 deletions
Showing only changes of commit d3d8910c3c - Show all commits

View file

@ -13,9 +13,13 @@
import Footer from '$lib/components/Footer.svelte'; import Footer from '$lib/components/Footer.svelte';
import { createBasketStore, setBasketContext } from '$lib/basket.svelte'; import { createBasketStore, setBasketContext } from '$lib/basket.svelte';
import { rootStyleTag, siteThemeVars } from '$shared/theme'; import { rootStyleTag, siteThemeVars } from '$shared/theme';
import { thumbUrl } from '$shared/pb';
let { children, data } = $props(); 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 // One basket store per public layout instance — provided to all children
// (Header indicator, ShopBlock, CheckoutBlock). Never module-level state. // (Header indicator, ShopBlock, CheckoutBlock). Never module-level state.
const basketStore = createBasketStore(data.basket ?? null); const basketStore = createBasketStore(data.basket ?? null);
@ -27,7 +31,9 @@
</script> </script>
<svelte:head> <svelte:head>
<link rel="icon" href={favicon} /> <link rel="icon" href={icon} />
<!-- Home-screen icon on phones; iOS ignores SVG, so only for an uploaded logo. -->
{#if icon !== favicon}<link rel="apple-touch-icon" href={icon} />{/if}
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Site colours, rendered server-side (previously applied in onMount, which <!-- Site colours, rendered server-side (previously applied in onMount, which
flashed the defaults on every page load). Values are sanitised. --> flashed the defaults on every page load). Values are sanitised. -->

View file

@ -20,3 +20,14 @@ export function createPocketBase(authCookie?: string, url = pbUrl) {
export function getFileUrl(collectionIdOrName: string, recordId: string, filename: string) { export function getFileUrl(collectionIdOrName: string, recordId: string, filename: string) {
return `${pbUrl}/api/files/${collectionIdOrName}/${recordId}/${filename}`; 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}`;
}