658a6dd284
- the proxy should always be used to access other parts of Ghost, including the urlService etc - use consistent ES6 style for requires - minimise use of lodash where possible - remove circular dependency between proxy and template util - End goal here is to enforce that the only link between helpers + the rest of Ghost is the proxy
29 lines
947 B
JavaScript
29 lines
947 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 {SafeString, checks} = require('./proxy');
|
|
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 (!checks.isPost(this)) {
|
|
return null;
|
|
}
|
|
|
|
let readingTime = calculateReadingTime(this, options.hash);
|
|
|
|
return new SafeString(readingTime);
|
|
};
|