From f172adb6556557a75a5e273b8f60cc86cce83171 Mon Sep 17 00:00:00 2001 From: ocknamo Date: Fri, 14 Jun 2024 11:16:53 +0900 Subject: [PATCH] feat: placeholder color --- src/lib/components/Image.svelte | 82 ++++++++++++++--------------- src/lib/components/Image.type.ts | 20 +++++++ src/routes/blog/[slug]/+page.svelte | 5 +- 3 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 src/lib/components/Image.type.ts diff --git a/src/lib/components/Image.svelte b/src/lib/components/Image.svelte index f6d7bea..323c4ac 100644 --- a/src/lib/components/Image.svelte +++ b/src/lib/components/Image.svelte @@ -1,21 +1,6 @@ - - {#if src.webp} - `${s.src} ${s.w}w`).join(', ')} type="image/webp" /> - {/if} - {#if src.jpeg} - `${s.src} ${s.w}w`).join(', ')} type="image/jpeg" /> - {/if} - {#if src.png} - `${s.src} ${s.w}w`).join(', ')} type="image/png" /> - {/if} - {src.alt} - +
+ + {#if src.webp} + `${s.src} ${s.w}w`).join(', ')} type="image/webp" /> + {/if} + {#if src.jpeg} + `${s.src} ${s.w}w`).join(', ')} type="image/jpeg" /> + {/if} + {#if src.png} + `${s.src} ${s.w}w`).join(', ')} type="image/png" /> + {/if} + {src.alt} + +
diff --git a/src/lib/components/Image.type.ts b/src/lib/components/Image.type.ts new file mode 100644 index 0000000..4755551 --- /dev/null +++ b/src/lib/components/Image.type.ts @@ -0,0 +1,20 @@ +export interface Srcset { + src: string; + w: number; +} + +export interface ImageSrc { + img: string; + w?: number; + h?: number; + webp?: Srcset[]; + jpeg?: Srcset[]; + png?: Srcset[]; + failback: string; + alt: string; + placeholder?: { + dataUri?: string; + color?: string; + }; + blur?: boolean; +} diff --git a/src/routes/blog/[slug]/+page.svelte b/src/routes/blog/[slug]/+page.svelte index d1d0b5f..b66611f 100644 --- a/src/routes/blog/[slug]/+page.svelte +++ b/src/routes/blog/[slug]/+page.svelte @@ -2,6 +2,7 @@ import SvelteMarkdown from 'svelte-markdown'; import { browser } from '$app/environment'; import Image from '$lib/components/Image.svelte'; + import type { ImageSrc } from '$lib/components/Image.type.js'; export let data; @@ -9,7 +10,7 @@ // TODO: set from config const optimazerPrefix = 'https://nostr-image-optimizer.ocknamo.com/image/'; - let src = { + let src: ImageSrc = { w: 800, img: `${optimazerPrefix}width=1600,quality=70,format=webp/${data.blog.image}`, webp: [ @@ -22,7 +23,7 @@ ], failback: data.blog.image, alt: 'blog top', - placeholder: data.blog.imagePlaceholderUrl, + placeholder: { dataUri: data.blog.imagePlaceholderUrl, color: 'black' }, blur: true };