Skip to content

Commit

Permalink
fix: Remove from the src the /@@images suffix (bare Plone uses it, bu…
Browse files Browse the repository at this point in the history
…t then it's not supported in the default Volto block.
  • Loading branch information
sneridagh authored and ericof committed Feb 18, 2022
1 parent 7b62b6c commit d241cbc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"scripts": {
"start": "node ./src/server.js",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch --watchAll",
"prettier": "./node_modules/.bin/prettier --single-quote --check '**/*.{js,json}'",
"prettier:fix": "./node_modules/.bin/prettier --single-quote --write '**/*.{js,json}'",
"lint": "./node_modules/eslint/bin/eslint.js --max-warnings=0 'src/**/*.js'",
Expand Down
5 changes: 4 additions & 1 deletion src/converters/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { alignFromClassName, scaleFromUrl } from '../helpers/image.js';
import { getYTVideoId } from '../helpers/video.js';

const imageBlock = (elem) => {
// strip /@@images/image if present
const url = elem.src.split('/@@images')[0];

const block = {
'@type': 'image',
url: elem.src,
url,
alt: elem.alt,
title: elem.title,
};
Expand Down
26 changes: 20 additions & 6 deletions src/converters/blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ describe('imageBlock processing', () => {
);
const result = imageBlock(elem);
expect(result['@type']).toBe('image');
expect(result['url']).toBe(
'https://plone.org/news/item/@@images/44ae2493-53fb-4221-98dc-98fa38d6851a.jpeg',
);
expect(result['url']).toBe('https://plone.org/news/item');
expect(result['title']).toBe('A Picture');
expect(result['alt']).toBe('Picture of a person');
expect(result['size']).toBe('m');
Expand All @@ -60,10 +58,26 @@ describe('imageBlock processing', () => {
);
const result = imageBlock(elem);
expect(result['@type']).toBe('image');
expect(result['url']).toBe(
'https://plone.org/news/item/@@images/image/thumb',
);
expect(result['url']).toBe('https://plone.org/news/item');
expect(result['size']).toBe('s');
expect(result['align']).toBe('right');
});
test('Image with no @@images present', () => {
const elem = elementFromString(
'<img src="https://plone.org/news/item" title="A Picture" alt="Picture of a person" class="image-right">',
);
const result = imageBlock(elem);
expect(result['@type']).toBe('image');
expect(result['url']).toBe('https://plone.org/news/item');
});
test('Image with resolveuid present', () => {
const elem = elementFromString(
'<img src="../resolveuid/7c6a1b0a0d2f40ffb6a4c73fd67b185d" title="A Picture" alt="Picture of a person" class="image-right">',
);
const result = imageBlock(elem);
expect(result['@type']).toBe('image');
expect(result['url']).toBe(
'../resolveuid/7c6a1b0a0d2f40ffb6a4c73fd67b185d',
);
});
});

0 comments on commit d241cbc

Please sign in to comment.