Ghost
Ghost copied to clipboard
Cannot get reading time from API via ?fields param
Issue Summary
When making a request to the Content API for posts and including reading_time
as a field, it is not returned.
Steps to Reproduce
Request the demo site with reading_time
:
https://demo.ghost.io/ghost/api/canary/content/posts/?key=22444f78447824223cefc48062&fields=title,url,reading_time
Note that it does work if you include the html
field, which reading time is calculated based on.
https://demo.ghost.io/ghost/api/canary/content/posts/?key=22444f78447824223cefc48062&fields=title,url,reading_time,html
Ghost Version
5.2
Node.js Version
14
How did you install Ghost?
ghost cli
Database type
MySQL 8
Browser & OS version
N/a
Relevant log / error output
n/a
Code of Conduct
- [X] I agree to be friendly and polite to people in this repository
I have the exact same problem. I've seen that when you request some specific fields you need to try with slightly different names than the ones marked on the fields from the GET/posts response. For example, in the GET/posts response it is marked "tags" in plural but when you add the "&fields" to the request you need to put "tag" in singular. Although I haven't found the correct name for reading_time (if it exists).
EDIT: I've searched for different alternatives and I came across with this library https://www.npmjs.com/package/reading-time it's easy to use but making the request for the html (which the library needs in order to calculate the time) can be quite heavy. On the other hand, I don't think we have an option here because other alternative I looked over https://github.com/styxlab/next-cms-ghost/blob/master/lib/readingTime.ts also uses html for the time calculations
Happy coding!
Our bot has automatically marked this issue as stale because there has not been any activity here in some time.
The issue will be closed soon if there are no further updates, however we ask that you do not post comments to keep the issue open if you are not actively working on a PR.
We keep the issue list minimal so we can keep focus on the most pressing issues. Closed issues can always be reopened if a new contributor is found. Thank you for understanding 🙂
Sir plss assign this to me. I can fix this bug
Field reading_time
doesn't work if field html
is not present. You need to add field html
too to get it.
here is the code - https://github.com/TryGhost/Ghost/blob/31b3905f8d22d9c3c8cb8e43cea1da042107e297/ghost/core/core/server/api/endpoints/utils/serializers/output/utils/extra-attrs.js#L62
Our bot has automatically marked this issue as stale because there has not been any activity here in some time.
The issue will be closed soon if there are no further updates, however we ask that you do not post comments to keep the issue open if you are not actively working on a PR.
We keep the issue list minimal so we can keep focus on the most pressing issues. Closed issues can always be reopened if a new contributor is found. Thank you for understanding 🙂