mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 02:41:50 +03:00
301e1b2419
refs #9200 - We have not yet counted the images within your html, this commit counts images based on the this algorithm: https://blog.medium.com/read-time-and-you-bc2048ab620c - Added imageCount utility, which counts images using an img-tag regex, amended from the general tag-regex found in wordCount - Added this imageCount to the {{reading_time}} helper, adding 12 seconds to the reading time for every image - The feature image is still counted as before - The first image adds 12 seconds, the second 11, the third 10, and so on - Images from the tenth onwards add 3 seconds to the reading time
44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
var should = require('should'), // jshint ignore:line
|
|
helperUtils = require('../../../server/helpers/utils');
|
|
|
|
describe('Helpers Utils', function () {
|
|
describe('Word Count', function () {
|
|
it('[success] can count words', function () {
|
|
var html = 'Some words here',
|
|
result = helperUtils.wordCount(html);
|
|
|
|
result.should.equal(3);
|
|
});
|
|
|
|
it('[success] sanitized HTML tags', function () {
|
|
var html = '<div class="kg-card-markdown"><p>This is a text example! Count me in ;)</p></div>',
|
|
result = helperUtils.wordCount(html);
|
|
|
|
result.should.equal(8);
|
|
});
|
|
|
|
it('[success] sanitized non alpha-numeric characters', function () {
|
|
var html = '<div class="kg-card-markdown"><p>This is a text example! I love Döner. Especially number 875.</p></div>',
|
|
result = helperUtils.wordCount(html);
|
|
|
|
result.should.equal(11);
|
|
});
|
|
|
|
it('[success] sanitized white space correctly', function () {
|
|
var html = ' <div class="kg-card-markdown"><p> This is a text example!\n Count me in ;)</p></div> ',
|
|
result = helperUtils.wordCount(html);
|
|
|
|
result.should.equal(8);
|
|
});
|
|
});
|
|
|
|
describe('Image Count', function () {
|
|
it('[success] can count images', function () {
|
|
var html = '<div class="kg-card-markdown"><p>This is a <img src="hello.png"> text example! Count me in ;)</p><img src="hello.png"></div>',
|
|
result = helperUtils.imageCount(html);
|
|
|
|
result.should.equal(2);
|
|
});
|
|
});
|
|
});
|