-
-
Notifications
You must be signed in to change notification settings - Fork 20
html tags in search results #148
Description
I have a suggestion for improving the Algolia integration for Ghost CMS when building an index using yarn algolia index.
Description of the Improvement Opportunity
Taking a closer look at the code that transforms Ghost posts for the Algolia index, we can see the following snippet:
posts.map((post) => {
const algoliaPost = {
objectID: post.id,
slug: post.slug,
url: post.url,
html: post.html,
image: post.feature_image,
title: post.title,
tags: [],
authors: []
};
});
Here, only the raw HTML text of the post is passed as the text content for Algolia (html: post.html). This leads to HTML tags being displayed in the search preview on Algolia, which doesn't look visually appealing.
Proposed Enhancement
My suggestion would be to add an additional excerpt field alongside the html field. For this, we could use the excerpt (preview text) of the Ghost post, which doesn't contain any HTML tags. The transformed Algolia object would then look like this:
const algoliaPost = {
objectID: post.id,
slug: post.slug,
url: post.url,
html: post.html,
excerpt: post.excerpt,
image: post.feature_image,
title: post.title,
tags: [],
authors: []
};
This excerpt could then be displayed as the preview text in the search results on Algolia, without any HTML tags being visible. This would significantly improve the presentation of the search results and make it more user-friendly. I would greatly appreciate any feedback on this proposal! Please let me know if you have any questions.