forked from nuxt/image
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(unsplash): merge query params with src (nuxt#712)
- Loading branch information
1 parent
ff96538
commit 1f09a76
Showing
2 changed files
with
13 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
// 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' | ||
|
||
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)) | ||
} | ||
} |