diff --git a/README.md b/README.md index 85eb4de..6b55206 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,20 @@ 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 + # 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 +``` + +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 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/generator.rb b/lib/jekyll/generator.rb index 035ad85..d462543 100644 --- a/lib/jekyll/generator.rb +++ b/lib/jekyll/generator.rb @@ -1,11 +1,7 @@ # frozen_string_literal: true -require "tokenizer" - module Jekyll module Related - TOKENIZER = Tokenizer::WhitespaceTokenizer.new - class Generator < Jekyll::Generator def generate(site) # Update config with defaults in place. This ensures that the config @@ -14,7 +10,7 @@ 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 +69,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]