0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Added reading_time property to post/page resources in Content API

This commit is contained in:
Nazar Gargol 2019-10-09 17:38:46 +02:00 committed by Fabien O'Carroll
parent 9aca599b60
commit 977fb5f650
4 changed files with 21 additions and 5 deletions

View file

@ -1,3 +1,5 @@
const readingMinutes = require('@tryghost/helpers').utils.readingMinutes;
module.exports.forPost = (frame, model, attrs) => {
const _ = require('lodash');
@ -15,6 +17,19 @@ module.exports.forPost = (frame, model, attrs) => {
attrs.excerpt = attrs.custom_excerpt;
}
}
if (!Object.prototype.hasOwnProperty.call(frame.options, 'columns') ||
(frame.options.columns.includes('reading_time'))) {
if (attrs.html) {
let additionalImages = 0;
if (attrs.feature_image) {
additionalImages += 1;
}
attrs.reading_time = readingMinutes(attrs.html, additionalImages);
}
}
};
// @NOTE: ghost_head & ghost_foot are deprecated, remove in Ghost 3.0

View file

@ -27,6 +27,7 @@ const expectedProperties = {
// .without('page')
// canary returns a calculated excerpt field
.concat('excerpt')
.concat('reading_time')
,
author: _(schema.users)
.keys()

View file

@ -40,7 +40,7 @@
},
"dependencies": {
"@nexes/nql": "0.3.0",
"@tryghost/helpers": "1.1.12",
"@tryghost/helpers": "1.1.14",
"@tryghost/members-api": "0.8.0",
"@tryghost/members-ssr": "0.7.0",
"@tryghost/social-urls": "0.1.2",

View file

@ -199,10 +199,10 @@
mkdirp "0.5.0"
yauzl "2.4.1"
"@tryghost/helpers@1.1.12":
version "1.1.12"
resolved "https://registry.yarnpkg.com/@tryghost/helpers/-/helpers-1.1.12.tgz#ca77aa2649abd2d12760b36af2d6779619202971"
integrity sha512-9ns/YTXfUb+UOmILQq071qZ8Y6eIEvNQFLZtFiguhOzXqSHC+rKg45aNCcoP8G9opG7vmm7bkxeE/hiQ205qpw==
"@tryghost/helpers@1.1.14":
version "1.1.14"
resolved "https://registry.yarnpkg.com/@tryghost/helpers/-/helpers-1.1.14.tgz#89fe706660b256eb8caba6a5d0bbe468f5d1dced"
integrity sha512-7BKhOTkfGAE+OHsO2NXNvAR2sWQNo3vXa4k9HqGjWAvabLOYCpn47kobte3suSD8Myk9/eqwZ9MgTyC+kJajDw==
dependencies:
lodash-es "^4.17.11"