Class: Jekyll::BetterRelatedGenerator
- Inherits:
-
Generator
- Object
- Generator
- Jekyll::BetterRelatedGenerator
- Defined in:
- lib/jekyll/better_related_generator.rb
Constant Summary collapse
- TAG_WEIGHT =
Scoring weights
3- CATEGORY_WEIGHT =
2- KEYWORD_WEIGHT =
1- RECENCY_PENALTY =
Recency: subtract this many points per 30-day interval of separation
0.1- SECONDS_PER_MONTH =
60 * 60 * 24 * 30
- STOP_WORDS =
Common English stop words to exclude from keyword matching
%w[ a an the and or but in on at to for of with is are was were be been this that it its by from as into about up out if so do does did how what when where who which will would could should have has had not no can more some than then their they them there these those all any each just like may my our own said such use your ].to_set.freeze
Instance Method Summary collapse
Instance Method Details
#generate(site) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/jekyll/better_related_generator.rb', line 27 def generate(site) @site = site @config = site.config["better_related"] || {} count = (@config["count"] || 3).to_i min_score = (@config["min_score"] || 1).to_f candidates = collect_candidates site.posts.docs.each do |post| # Per-post manual override: list of URLs override = post.data["related_posts"] if override.is_a?(Array) post.data["related_posts"] = resolve_manual(override) next end # Per-post opt-out next if override == false scored = candidates .reject { |c| c.equal?(post) } .map { |c| [c, score(post, c)] } .select { |_, s| s >= min_score } .sort_by { |_, s| -s } .first(count) .map(&:first) post.data["related_posts"] = scored end end |