Skip to content

Commit

Permalink
🔥 Remove legacy content zero hack (#8156)
Browse files Browse the repository at this point in the history
refs #7491

- this hack is so legacy I almost forgot about it 😈
- in the beginning of Ghost there were no post images
- someone figured out you could do {{content words="0"}} and it would pull out the first image in your post
- this was never documented, but enough theme developers found it that when we upgraded downsize to get rid of the bug
- we needed to add a hack to keep compatibility.
- This has to die in 🔥  for Ghost 1.0
  • Loading branch information
ErisDS authored and kirrg001 committed Mar 14, 2017
1 parent b5cdc01 commit 5605c96
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 231 deletions.
8 changes: 0 additions & 8 deletions core/server/helpers/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
var hbs = require('express-hbs'),
_ = require('lodash'),
downsize = require('downsize'),
downzero = require('../utils/downzero'),
content;

content = function (options) {
Expand All @@ -20,13 +19,6 @@ content = function (options) {
});

if (truncateOptions.hasOwnProperty('words') || truncateOptions.hasOwnProperty('characters')) {
// Legacy function: {{content words="0"}} should return leading tags.
if (truncateOptions.hasOwnProperty('words') && truncateOptions.words === 0) {
return new hbs.handlebars.SafeString(
downzero(this.html)
);
}

return new hbs.handlebars.SafeString(
downsize(this.html, truncateOptions)
);
Expand Down
109 changes: 0 additions & 109 deletions core/server/utils/downzero.js

This file was deleted.

115 changes: 1 addition & 114 deletions core/test/unit/server_helpers/content_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,120 +48,7 @@ describe('{{content}} helper', function () {
);

should.exist(rendered);
rendered.string.should.equal('<p></p>');
});

it('can truncate html to 0 words, leaving image tag if it is first', function () {
var html = '<p><img src="example.jpg" />Hello <strong>World! It\'s me!</strong></p>',
rendered = (
helpers.content
.call(
{html: html},
{hash: {words: '0'}}
)
);

should.exist(rendered);
rendered.string.should.equal('<p><img src="example.jpg" /></p>');
});

it('can truncate html to 0 words, leaving image tag with attributes', function () {
var html = '<p><img src="example.png" alt="Alternative" title="Title"></p>',
rendered = (
helpers.content
.call(
{html: html},
{hash: {words: '0'}}
)
);

should.exist(rendered);
rendered.string.should.equal('<p><img src="example.png" alt="Alternative" title="Title"></p>');
});

it('can truncate html to 0 words, leaving first image tag & if alt text has a single quote', function () {
var html = '<p><img src="example.jpg" alt="It\'s me!" />Hello <strong>World! It\'s me!</strong></p>',
rendered = (
helpers.content
.call(
{html: html},
{hash: {words: '0'}}
)
);

should.exist(rendered);
rendered.string.should.equal('<p><img src="example.jpg" alt="It\'s me!" /></p>');
});

it('can truncate html to 0 words, leaving first image tag & if alt text has a double quote', function () {
var html = '<p><img src="example.jpg" alt="A double quote is \'" />' +
'Hello <strong>World! It\'s me!</strong></p>',
rendered = (
helpers.content
.call(
{html: html},
{hash: {words: '0'}}
)
);

should.exist(rendered);
rendered.string.should.equal('<p><img src="example.jpg" alt="A double quote is \'" /></p>');
});

it('can truncate html to 0 words, leaving first image tag if it contains > & <', function () {
var html = '<p><img src="examp>><><>le.png"></p>',
rendered = (
helpers.content
.call(
{html: html},
{hash: {words: '0'}}
)
);

should.exist(rendered);
rendered.string.should.equal('<p><img src="examp>><><>le.png"></p>');
});

it('can truncate html to 0 words, leaving first two image tags', function () {
var html = '<p><img src="example.png"><img src="example.png">Hi<img src="example.png"></p>',
rendered = (
helpers.content
.call(
{html: html},
{hash: {words: '0'}}
)
);

should.exist(rendered);
rendered.string.should.equal('<p><img src="example.png"><img src="example.png"></p>');
});

it('can truncate html to 0 words, removing image if text comes first', function () {
var html = '<p><a>Bli<a><a><img src="example.png"></a></a>Blob</a></p>',
rendered = (
helpers.content
.call(
{html: html},
{hash: {words: '0'}}
)
);

should.exist(rendered);
rendered.string.should.equal('<p><a></a></p>');
});

it('can truncate html to 0 words, leaving video tag', function () {
var html = '<p><video><source src="movie.mp4"><source src="movie.ogg"></video></p>',
rendered = (
helpers.content
.call(
{html: html},
{hash: {words: '0'}}
)
);

should.exist(rendered);
rendered.string.should.equal('<p><video><source src="movie.mp4"><source src="movie.ogg"></video></p>');
rendered.string.should.equal('');
});

it('can truncate html by character', function () {
Expand Down

0 comments on commit 5605c96

Please sign in to comment.