A walkthrough on building a 'Related Posts' component for a Gatsby.js blog. The approach uses a GraphQL StaticQuery to fetch all articles, then applies a custom SimilarArticlesFactory class that implements the Builder pattern to score and rank articles by similarity. Articles earn 2 points for matching category and 1 point per matching tag, with results sorted by score using lodash and limited to a configurable maximum count.

7m read timeFrom khalilstemmler.com
Post cover image
Table of contents
Who is this article for?How we're going to do itGet Articles From a Graphql queryRank articles with the SimilarArticlesFactoryNeed more?Need even more?