Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html tags in search results #148

Open
noezdev opened this issue Sep 19, 2024 · 0 comments
Open

html tags in search results #148

noezdev opened this issue Sep 19, 2024 · 0 comments

Comments

@noezdev
Copy link

noezdev commented Sep 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant