Skip to content

Commit

Permalink
[preview] Ignore image cdn parameters from preview.imageUrl (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Jan 30, 2018
1 parent 29b7fc9 commit e70b167
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/@sanity/base/src/assets/asset-url-builder.js
Expand Up @@ -2,7 +2,14 @@ const sanityUrlMatch = /^https?:\/\/cdn.sanity.\w+\/images\//

export default function assetUrlBuilder(url, options) {
const {width, height, fit} = options
if (!sanityUrlMatch.test(url) || url.indexOf('?') !== -1) {

if (!sanityUrlMatch.test(url)) {
return url
}

if (url.includes('?')) {
// todo: this is an sanity cdn url that already has parameters specified
// Consider merging with options instead of just bypassing
return url
}

Expand Down
Expand Up @@ -69,7 +69,7 @@ export default class SanityDefaultPreview extends React.PureComponent {
const {value} = this.props
const imageUrl = value.imageUrl
if (imageUrl) {
const assetUrl = assetUrlBuilder(imageUrl, dimensions)
const assetUrl = assetUrlBuilder(imageUrl.split('?')[0], dimensions)
return <img src={assetUrl} alt={value.title} />
}
return undefined
Expand Down

0 comments on commit e70b167

Please sign in to comment.