Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

fix: respect image hashes with dimensions #1134

Merged
merged 1 commit into from
Aug 24, 2021
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
4 changes: 3 additions & 1 deletion src/html/rewrite-blob-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ function images(document) {
if (/^https:\/\/hlx\.blob\.core\.windows\.net\/external\//.test(img.src)) {
const { pathname, hash } = new URL(img.src);
const filename = pathname.split('/').pop();
const extension = hash.includes('.') ? hash.split('.').pop() : 'jpg';

// remove width/height from hash, since helix-pages doesn't support it yet
const extension = hash.split('?').shift().split('.').pop() || 'jpg';
img.src = `./media_${filename}.${extension}`;
}
});
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/image-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@
}
],
"type": "paragraph"
},
{
"children": [
{
"alt": null,
"title": null,
"type": "image",
"url": "https://hlx.blob.core.windows.net/external/dccc13d784576fa3f0b3e06fb0ea705c49b8085#image.gif?width=100&height=100"
}
],
"type": "paragraph"
}
]
}
3 changes: 2 additions & 1 deletion test/fixtures/image-rewritten-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<p>This is a blob image:</p>
<p><img src="./media_dccc13d784576fa3f0b3e06fb0ea705c49b8085.jpg"></p>
<p>This is a blob image with type indication:</p>
<p><img src="./media_dccc13d784576fa3f0b3e06fb0ea705c49b8085.png"></p></body>
<p><img src="./media_dccc13d784576fa3f0b3e06fb0ea705c49b8085.png"></p>
<p><img src="./media_dccc13d784576fa3f0b3e06fb0ea705c49b8085.gif"></p></body>
2 changes: 1 addition & 1 deletion test/testRewriteBlobImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Test Blob Image Rewriting', () => {
content: { document },
};
rewriteBlobImages(context);
assert.equal(context.content.document.documentElement.innerHTML.trim(), expected.trim());
assert.strictEqual(context.content.document.documentElement.innerHTML.trim(), expected.trim());
});

it('Does not throw error if document is missing', () => {
Expand Down