Skip to content

Commit

Permalink
fix: href should be first
Browse files Browse the repository at this point in the history
  • Loading branch information
y-nk committed Jul 25, 2023
1 parent c5e3df6 commit 11d665a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/astro/src/assets/services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,27 +210,27 @@ export const baseService: Omit<LocalImageService, 'transform'> = {
};
},
getURL(options, serviceConfig, assetsConfig) {
const PARAMS: Record<string, keyof typeof options> = {
w: 'width',
h: 'height',
q: 'quality',
f: 'format',
};

const searchParams = Object.entries(PARAMS).reduce((params, [param, key]) => {
options[key] && params.append(param, options[key].toString());
return params;
}, new URLSearchParams());
const searchParams = new URLSearchParams();

if (isESMImportedImage(options.src)) {
searchParams.append('href', options.src.src);
} else if (isRemoteAllowed(options.src, assetsConfig)) {
searchParams.append('href', options.src);
} else {
// ignore non http strings
return options.src;
}

const PARAMS: Record<string, keyof typeof options> = {
w: 'width',
h: 'height',
q: 'quality',
f: 'format',
};

Object.entries(PARAMS).forEach(([param, key]) => {
options[key] && searchParams.append(param, options[key].toString());
});

const imageEndpoint = joinPaths(import.meta.env.BASE_URL, '/_image');
return `${imageEndpoint}?${searchParams}`;
},
Expand Down

0 comments on commit 11d665a

Please sign in to comment.