summaryrefslogtreecommitdiff
path: root/packages/integrations/image/src/utils.ts
diff options
context:
space:
mode:
authorGravatar Tony Sullivan <tony.f.sullivan@outlook.com> 2022-07-19 04:48:22 +0000
committerGravatar GitHub <noreply@github.com> 2022-07-18 21:48:22 -0700
commit299b4afcab090bbe014d4eaf2a5ea439e8436bcc (patch)
treeb9091512848a664f1f7862bc14f0dc99145981dd /packages/integrations/image/src/utils.ts
parent60e38f6eb4273e29995b3aa83a37ab2433b66418 (diff)
downloadastro-299b4afcab090bbe014d4eaf2a5ea439e8436bcc.tar.gz
astro-299b4afcab090bbe014d4eaf2a5ea439e8436bcc.tar.zst
astro-299b4afcab090bbe014d4eaf2a5ea439e8436bcc.zip
Feat/image url hash (#3965)
* Including a hash of the full remote URL when building for SSG * chore: add changeset
Diffstat (limited to 'packages/integrations/image/src/utils.ts')
-rw-r--r--packages/integrations/image/src/utils.ts6
1 files changed, 6 insertions, 0 deletions
diff --git a/packages/integrations/image/src/utils.ts b/packages/integrations/image/src/utils.ts
index 44c338cf4..80dff1b6e 100644
--- a/packages/integrations/image/src/utils.ts
+++ b/packages/integrations/image/src/utils.ts
@@ -1,5 +1,6 @@
import fs from 'fs';
import path from 'path';
+import { shorthash } from './shorthash.js';
import type { OutputFormat, TransformOptions } from './types';
export function isOutputFormat(value: string): value is OutputFormat {
@@ -48,6 +49,11 @@ export function propsToFilename({ src, width, height, format }: TransformOptions
const ext = path.extname(src);
let filename = src.replace(ext, '');
+ // for remote images, add a hash of the full URL to dedupe images with the same filename
+ if (isRemoteImage(src)) {
+ filename += `-${shorthash(src)}`;
+ }
+
if (width && height) {
return `${filename}_${width}x${height}.${format}`;
} else if (width) {