From a55b8b2fc62ecac2d2a14856332c47ad04ce019a Mon Sep 17 00:00:00 2001 From: "Daniel, Petrica Andrei-Daniel" Date: Mon, 30 Jan 2023 13:01:56 +0100 Subject: [PATCH] fix(unsplash): merge query params with src (#712) --- playground/providers.ts | 10 ++++++++++ src/runtime/providers/unsplash.ts | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/playground/providers.ts b/playground/providers.ts index a22ba4a4c..dbe5bd859 100644 --- a/playground/providers.ts +++ b/playground/providers.ts @@ -671,6 +671,16 @@ export const providers: Provider[] = [ format: 'auto', from: 'Photo by Omid Armin', link: 'https://unsplash.com/@omidarmin?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText' + }, + { + src: 'https://images.unsplash.com/photo-1532236204992-f5e85c024202?crop=entropy&cs=tinysrgb&ixid=MnwxOTgwMDZ8MHwxfHNlYXJjaHwyOHx8dG9reW98ZW58MHx8fHwxNjczNzk3MDIz&w=500', + width: 300, + height: 300, + fit: 'cover', + quality: 75, + format: 'auto', + from: 'Photo by Jezael Melgoza', + link: 'https://unsplash.com/@jezar?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText' } ] }, diff --git a/src/runtime/providers/unsplash.ts b/src/runtime/providers/unsplash.ts index b4d8fe062..191c1a1fc 100644 --- a/src/runtime/providers/unsplash.ts +++ b/src/runtime/providers/unsplash.ts @@ -1,6 +1,6 @@ // https://unsplash.com/documentation#dynamically-resizable-images -import { joinURL, withBase } from 'ufo' +import { getQuery, withBase, withQuery } from 'ufo' import type { ProviderGetImage } from '../../types' import { operationsGenerator } from './imgix' @@ -8,7 +8,8 @@ const unsplashCDN = 'https://images.unsplash.com/' export const getImage: ProviderGetImage = (src, { modifiers = {}, baseURL = unsplashCDN } = {}) => { const operations = operationsGenerator(modifiers) + // withQuery requires query parameters as an object, so I parse the modifiers into an object with getQuery return { - url: withBase(joinURL(src + (operations ? ('?' + operations) : '')), baseURL) + url: withQuery(withBase(src, baseURL), getQuery('?' + operations)) } }