@@ -8,13 +8,15 @@ class SimilarContentFooterTag < Liquid::Tag
88 @@similar_cats = nil
99 @@content = nil
1010 @@content_for_tag = nil
11+ @@canon_tags = nil
1112
1213 def dataInit ( v )
1314 puts "Prefetching data for similar_content footer..."
1415 @@config = v [ "site.data.content" ]
1516 @@parents_for_tag = { }
1617 @@similar_cats = { }
1718 @@content = [ ]
19+ @@canon_tags = Set . new
1820 @@content_for_tag = Hash . new { |h , k | h [ k ] = Set . new }
1921 for cofefe in v [ "site.categories" ]
2022 cat = cofefe . to_liquid . to_h
@@ -23,6 +25,9 @@ def dataInit(v)
2325 for cofefe in v [ "site.tags" ]
2426 tag = cofefe . to_liquid . to_h
2527 @@parents_for_tag [ tag [ "slug" ] ] = tag [ "parents" ]
28+ if tag [ "is_canon" ]
29+ @@canon_tags << tag [ "slug" ]
30+ end
2631 end
2732 for cofefe in v [ "site.content" ]
2833 c = cofefe . to_liquid . to_h
@@ -133,16 +138,21 @@ def render(v)
133138 end
134139 if candidate [ "tags" ] &.size &.nonzero? then
135140 denom += candidate [ "tags" ] . size * @@config [ "tdms" ]
136- for t in include_content [ "tags" ]
137- if candidate [ "tags" ] . include? t then
138- score += @@config [ "ttms" ]
141+ for t in candidate [ "tags" ]
142+ ttms = @@config [ "ttms" ]
143+ if @@canon_tags . include? t and candidate [ "category" ] == "canon"
144+ ttms *= @@config [ "ctmm" ]
145+ denom -= @@config [ "tdms" ] * ( 1.0 - @@config [ "ctmm" ] )
146+ end
147+ if include_content [ "tags" ] . include? t then
148+ score += ttms
139149 else
140150 if @@parents_for_tag [ t ] then
141151 for p in @@parents_for_tag [ t ]
142- if candidate [ "tags" ] . include? p then
152+ if include_content [ "tags" ] . include? p then
143153 score += @@config [ "tpms" ]
144154 break
145- elsif candidate [ "course" ] == p then
155+ elsif include_content [ "course" ] == p then
146156 score += @@config [ "tpms" ]
147157 break
148158 end
0 commit comments