searchinGhost
searchinGhost copied to clipboard
reading_time is not supported in postsFields
It seems that reading_time
is not supported in postsFields
.
I've defined:
postsFields: ['title', 'url', 'excerpt', 'custom_excerpt', 'published_at', 'feature_image', 'reading_time'],
and inside template
function the ${post.reading_time}
outputs undefined
.
Click to see the whole template function definition
template: function (post) {
var postCard = `<article class="post-card post">`;
if (post.feature_image) {
postCard += `<a class="post-card-image-link" href="${post.url}">`;
postCard += `<img class="post-card-image" src="${post.feature_image}" alt="${post.title}" loading="lazy"/>`;
postCard += `</a>`;
}
postCard += `<div class="post-card-content">`;
postCard += `<a class="post-card-content-link" href="${post.url}">`;
postCard += `<header class="post-card-header">`;
if (post.tags.length > 0) {
postCard += `<div class="post-card-primary-tag">#${post.tags[0].name}</div>`;
}
postCard += `<h2 class="post-card-title">${post.title}</h2>`;
postCard += `</header>`;
postCard += `<section class="post-card-excerpt">`;
postCard += `<p>${post.excerpt}</p>`;
postCard += `</section>`;
postCard += `</a>`;
postCard += `<footer class="post-card-meta">`;
postCard += `<ul class="author-list">`;
postCard += `<li class="author-list-item">`;
if (post.authors.length > 0 && post.authors[0].profile_image) {
postCard += `<a href="${post.authors[0].url}" class="static-avatar">`;
postCard += `<img class="author-profile-image" src="${post.authors[0].profile_image}" alt="${post.authors[0].name}"/>`;
postCard += `</a>`;
}
postCard += `</li>`;
postCard += `</ul>`;
postCard += `<div class="post-card-byline-content">`;
if (post.authors.length > 0) {
postCard += `<span>`;
postCard += `<a href="${post.authors[0].url}">${post.authors[0].name}</a>`;
postCard += `</span>`;
}
postCard += `<span class="post-card-byline-date">`;
postCard += `<time>${post.published_at}</time>`;
postCard += `<span class="bull">•</span>`;
postCard += `${post.reading_time}`;
postCard += `</span>`;
postCard += `</div>`;
postCard += `</footer>`;
postCard += `</div>`;
postCard += `</article>`;
return postCard;
}
When I execute curl
command:
curl "http://localhost:2368/ghost/api/v3/content/posts/{id}/?key={key}&include=tags,authors" | jq
I can see that reading_time
is available:
Casper theme is displaying reading_time
in its post-card
definition:
but when using searchinGhost I can't display it and my theme is not consistent:
Would it be possible to add support for reading_time
in postsFields
?
@gmfmi, thank you for all you hard work! SearchinGhost is awesome :)
Hi @JavowiecPL, curious issue! I will dig into it to understand what is going on. I hope I will get enough free time to do it by tomorrow :)
Well, basically, the issue comes from the internal Ghost API design (if you wonder, yes, it could be really improved 😃). This is a known issue, check that link to get more information.
So with the current implementation of SearchinGhost, it is not possible to simply add the field reading_time
to the list to make it work.
But, good news, I need to partially rewrite the library so I will probably include this fix on the fly! The only issue is I don't know yet when I will find the time to do it...
Stay tuned 😉
It is not an urgent issue, take your time :grin:
Thank you for the information and your work! :+1: