Method: JekyllTag::JTag#populate_auto_tags

Defined in:
lib/jtag/jekylltag.rb

#populate_auto_tagsObject



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/jtag/jekylltag.rb', line 202

def populate_auto_tags
  freqs = Hash.new(0)
  @words.each { |word| freqs[word] += 1 }
  freqs.delete_if { |k, v| v < @min_matches }

  return [] if freqs.empty?

  freqs.sort_by { |k, v| [v * -1, k] }.each { |word|
    index = @tags.keys.index(word[0])
    unless index.nil? || @blacklist.include?(@tags.keys[index])
      @auto_tags.push(@tags[@tags.keys[index]]) unless index.nil?
    end
  }

  @tags.each { |k, v|
    occurrences = @content.scan(/\b#{k}\b/i)
    if occurrences.count >= @min_matches
      @auto_tags.push(v)
    end
  }
end