Ghost/core/server/helpers/reading_time.js
Rish 65ee0f95c4 Updated reading time helper to use SDK
refs #10618

- Removed duplicate calculation for reading time by using SDK method
2019-05-07 15:33:07 +05:30

31 lines
1018 B
JavaScript

// # Reading Time Helper
//
// Usage: `{{reading_time}}`
// or for translatable themes, with (t) translation helper's subexpressions:
// `{{reading_time seconds=(t "< 1 min read") minute=(t "1 min read") minutes=(t "% min read")}}`
// and in the theme translation file, for example Spanish es.json:
// "< 1 min read": "< 1 min de lectura",
// "1 min read": "1 min de lectura",
// "% min read": "% min de lectura",
//
// Returns estimated reading time for post
const proxy = require('./proxy');
const schema = require('../data/schema').checks;
const SafeString = proxy.SafeString;
const calculateReadingTime = require('@tryghost/helpers').readingTime;
module.exports = function reading_time(options) {// eslint-disable-line camelcase
options = options || {};
options.hash = options.hash || {};
// only calculate reading time for posts
if (!schema.isPost(this)) {
return null;
}
let readingTime = calculateReadingTime(this, options.hash);
return new SafeString(readingTime);
};