mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
df7e64fafa
refs #10790 - Moved /core/apps into core/frontend - Moved /core/server/helpers to /core/frontend/helpers along with /core/server/services/themes - Changed helper location in overrides - Moved /core/server/services/routing to /core/frontend/services - Moved /core/server/services/url to /core/frontend/services - Moved /core/server/data/meta to /core/frontend/meta - Moved /core/server/services/rss to /core/frontend/services - Moved /core/server/data/xml to /core/frontend/services
31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
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('../../server/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);
|
|
};
|