TryGhost / TryGhost/algolia

html tags in search results

Open
#148 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
22
Forks
19
Avg merge
18h 31m
Merged PRs (30d)
50

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the yarn algolia index command to the post transformation shown in the issue, then inspect how the indexed fields are used for search previews. Confirm the appropriate excerpt field is indexed and verify that search result previews no longer display HTML tags.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, search
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.