Class: Jekyll::TagsList

Inherits:
Generator
  • Object
show all
Defined in:
lib/mm-jekyll-tags-list.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.calculate_maximum_post_count(site) ⇒ Object



28
29
30
# File 'lib/mm-jekyll-tags-list.rb', line 28

def self.calculate_maximum_post_count(site)
	max = site.tags.map { |tag,posts| posts.count }.max
end

.calculate_popularity(maximum, count) ⇒ Object



36
37
38
# File 'lib/mm-jekyll-tags-list.rb', line 36

def self.calculate_popularity(maximum, count)
	percent = ((count.to_f / maximum) * 100).floor
end

.calculate_popularity_class(site, maximum, popularity) ⇒ Object



24
25
26
# File 'lib/mm-jekyll-tags-list.rb', line 24

def self.calculate_popularity_class(site, maximum, popularity)
	output = ((site.config['number_popularity_classes'] / 100.to_f) * popularity).round
end

.generate_tags_structure(site) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mm-jekyll-tags-list.rb', line 9

def self.generate_tags_structure(site)
	tags = Hash.new
	maximum = calculate_maximum_post_count(site)
	for tag in site.tags.keys do
		tags[tag] = Hash.new
		post_count = number_of_posts_for_tag(site, tag)
		popularity = calculate_popularity(maximum, post_count)
		popularity_class = calculate_popularity_class(site, maximum, popularity)
		tags[tag]['post_count'] = post_count.to_s
		tags[tag]['popularity'] = popularity.to_s
		tags[tag]['popularity_class'] = popularity_class.to_s
	end
	tags
end

.number_of_posts_for_tag(site, tag) ⇒ Object



32
33
34
# File 'lib/mm-jekyll-tags-list.rb', line 32

def self.number_of_posts_for_tag(site, tag)
	count = site.tags[tag].length
end

Instance Method Details

#generate(site) ⇒ Object



4
5
6
7
# File 'lib/mm-jekyll-tags-list.rb', line 4

def generate(site)
	site.data['tag_list'] = TagsList.generate_tags_structure(site).keys
	site.data['tag_data'] = TagsList.generate_tags_structure(site)
end