Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(unsplash): merge query params with src #712

Merged
merged 3 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions playground/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,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'
}
]
},
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/providers/unsplash.ts
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))
}
}