Skip to content

Commit

Permalink
Koenig - Do not render image cards with no src on the front-end
Browse files Browse the repository at this point in the history
refs TryGhost/Ghost#9623
- blank images may be used in the editor as placeholders, don't render them on the front-end
  • Loading branch information
kevinansfield committed Jun 14, 2018
1 parent 1a8d4a1 commit f63f710
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/kg-default-cards/lib/cards/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module.exports = {
// let version = opts.options.version;
let dom = opts.env.dom;

if (!payload.src) {
return '';
}

let figure = dom.createElement('figure');
figure.setAttribute('class', 'kg-image-card');

Expand Down
18 changes: 16 additions & 2 deletions packages/kg-default-cards/test/cards/image_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const SimpleDom = require('simple-dom');
const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);

describe('Image card', function () {
it('generates an image', function () {
it('renders an image', function () {
let opts = {
env: {
dom: new SimpleDom.Document()
Expand All @@ -17,7 +17,7 @@ describe('Image card', function () {
serializer.serialize(card.render(opts)).should.eql('<figure class="kg-image-card"><img src="https://www.ghost.org/image.png" class="kg-image"></figure>');
});

it('generates an image with caption', function () {
it('renders an image with caption', function () {
let opts = {
env: {
dom: new SimpleDom.Document()
Expand All @@ -31,6 +31,20 @@ describe('Image card', function () {
serializer.serialize(card.render(opts)).should.eql('<figure class="kg-image-card"><img src="https://www.ghost.org/image.png" class="kg-image"><figcaption>Test caption</figcaption></figure>');
});

it('renders nothing with no src', function () {
let opts = {
env: {
dom: new SimpleDom.Document()
},
payload: {
src: '',
caption: 'Test caption'
}
};

serializer.serialize(card.render(opts)).should.eql('');
});

describe('sizes', function () {
it('standard', function () {
let opts = {
Expand Down

0 comments on commit f63f710

Please sign in to comment.