-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(unsplash): Edited how I build the url to make use of withQuery
- Loading branch information
1 parent
6ed73a3
commit 8d409b6
Showing
2 changed files
with
4 additions
and
4 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,15 +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) | ||
const hasQueryParams = src.includes('?') | ||
// withQuery requires query parameters as an object, so I parse the modifiers into an object with getQuery | ||
return { | ||
url: withBase(joinURL(src + (operations ? ((hasQueryParams ? '&' : '?') + operations) : '')), baseURL) | ||
url: withQuery(withBase(src, baseURL), getQuery('?' + operations)) | ||
} | ||
} |