From 1edd6053b395182d3d1a55dc8d403f307811aabb Mon Sep 17 00:00:00 2001 From: Max Kapur Date: Wed, 20 Aug 2025 17:43:06 -0500 Subject: [PATCH 1/3] Add installation instructions to README --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 85eb4de..2786fff 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,17 @@ here.](https://maxkapur.com/jekyll-related/) ## Installation +This gem is *not* hosted on RubyGems.org. I may upload it eventually; for now, +you can depend directly on the git repo by adding the following to your Gemfile: + +```text +group :jekyll_plugins do + gem "jekyll-related", git: "https://github.com/maxkapur/jekyll-related", branch: "main" +end +``` + +Below is boilerplate generated by the `bundle gem command`: + TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier From 67da865bd33324d4330ca57e419e7782c1e8bc6d Mon Sep 17 00:00:00 2001 From: Max Kapur Date: Wed, 20 Aug 2025 18:01:35 -0500 Subject: [PATCH 2/3] Remove tokenizer dependency and implement our own method We are playing it fast and loose with tokenization anyway (no stemming). Might as well use regex word boundaries to separate out words and let the algorithm figure out that punctuation, etc. are low weight. --- jekyll-related.gemspec | 1 - lib/jekyll/related.rb | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/jekyll-related.gemspec b/jekyll-related.gemspec index 23f84b3..d1913ca 100644 --- a/jekyll-related.gemspec +++ b/jekyll-related.gemspec @@ -36,7 +36,6 @@ Gem::Specification.new do |spec| # Uncomment to register a new dependency of your gem # spec.add_dependency "example-gem", "~> 1.0" spec.add_dependency "jekyll", "~> 4.3" - spec.add_dependency "tokenizer", "~> 0.3" # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html diff --git a/lib/jekyll/related.rb b/lib/jekyll/related.rb index 5297936..f52a419 100644 --- a/lib/jekyll/related.rb +++ b/lib/jekyll/related.rb @@ -3,9 +3,6 @@ require_relative "related/version" require_relative "tag" -require "tokenizer" - -TOKENIZER = Tokenizer::WhitespaceTokenizer.new DEFAULT_FACTOR = 10.0 module Jekyll @@ -14,7 +11,7 @@ class Generator < Jekyll::Generator def generate(site) # Count tokens within each post. post_tallies = site.posts.docs.to_h do |post| - [post, (TOKENIZER.tokenize post.content.downcase).tally] + [post, (tokenize post.content.downcase).tally] end # Count global frequency of each token. @@ -73,6 +70,11 @@ def generate(site) end end + # Split post body into "words" + def tokenize(post) + post.split(/\b/).delete_if { |x| /\s+/.match? x } + end + # Cosine similarity between the two count vectors def similarity(current_post, related_post) v_current = @post_token_volume[current_post][:volume] From dccfc8e6b7a489d74fafa865d511b1fb1dd26b7d Mon Sep 17 00:00:00 2001 From: Max Kapur Date: Wed, 20 Aug 2025 18:08:10 -0500 Subject: [PATCH 3/3] Add instructions for pinning specific git commit --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 2786fff..6b55206 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,10 @@ you can depend directly on the git repo by adding the following to your Gemfile: ```text group :jekyll_plugins do + # Track the main branch. Might break occasionally :D gem "jekyll-related", git: "https://github.com/maxkapur/jekyll-related", branch: "main" + # Pin a specific git commit + gem "jekyll-related", git: "https://github.com/maxkapur/jekyll-related", ref: "67da865bd33324d4330ca57e419e7782c1e8bc6d" end ```