class Jekyll::Tagger
Attributes
site[RW]
types[RW]
site[RW]
Public Instance Methods
generate(site)
click to toggle source
# File lib/jekyll-tagging-lite.rb 37 def generate(site) 38 self.class.site = self.site = site 39 40 generate_tag_pages 41 add_tag_cloud 42 end
Private Instance Methods
add_tag_cloud(num = 5, name = 'tag_data')
click to toggle source
# File lib/jekyll-tagging-lite.rb 75 def add_tag_cloud(num = 5, name = 'tag_data') 76 classifier = site.config['tag_classifier'] || 'linear' 77 s, t = site, { name => calculate_tag_cloud(@@classifiers[classifier].curry[num]) } 78 s.respond_to?(:add_payload) ? s.add_payload(t) : s.config.update(t) 79 end
calculate_tag_cloud(classifier)
click to toggle source
Calculates the css class of every tag for a tag cloud. The possible classes are: set-1..set-5.
- [<TAG>, <CLASS>], …
# File lib/jekyll-tagging-lite.rb 85 def calculate_tag_cloud(classifier) 86 tags = active_tags.map { |tag, posts| [tag, posts.size] } 87 min, max = tags.map { |tag, size| size }.minmax 88 tags.sort!.map! { |tag, size| [tag, classifier.call(size, min, max)] } 89 end
generate_tag_pages()
click to toggle source
Generates a page per tag and adds them to all the pages of site
. A tag_page_layout
have to be defined in your _config.yml
to use this.
# File lib/jekyll-tagging-lite.rb 49 def generate_tag_pages 50 active_tags.each { |tag, posts| new_tag(tag, posts) } 51 end
new_tag(tag, posts) { |data| ... }
click to toggle source
# File lib/jekyll-tagging-lite.rb 53 def new_tag(tag, posts) 54 self.class.types.each { |type| 55 if layout = site.config["tag_#{type}_layout"] 56 data = { 'layout' => layout, 'posts' => posts.sort.reverse!, 'tag' => tag } 57 data.merge!(site.config["tag_#{type}_data"] || {}) 58 59 name = yield data if block_given? 60 name ||= tag 61 name = jekyll_tagging_slug(name) 62 63 tag_dir = site.config["tag_#{type}_dir"] 64 tag_dir = File.join(tag_dir, (pretty? ? name : '')) 65 66 page_name = "#{pretty? ? 'index' : name}#{site.layouts[data['layout']].ext}" 67 68 site.pages << TagPage.new( 69 site, site.source, tag_dir, page_name, data 70 ) 71 end 72 } 73 end
pretty?()
click to toggle source
# File lib/jekyll-tagging-lite.rb 96 def pretty? 97 @pretty ||= (site.permalink_style == :pretty || site.config['tag_permalink_style'] == 'pretty') 98 end