class Jekyll::Tagger
Attributes
site[RW]
types[RW]
site[RW]
Public Instance Methods
generate(site)
click to toggle source
# File lib/jekyll/tagging.rb 32 def generate(site) 33 self.class.site = self.site = site 34 35 generate_tag_pages 36 add_tag_cloud 37 end
Private Instance Methods
add_tag_cloud(num = 5, name = 'tag_data')
click to toggle source
# File lib/jekyll/tagging.rb 70 def add_tag_cloud(num = 5, name = 'tag_data') 71 s, t = site, { name => calculate_tag_cloud(num) } 72 s.respond_to?(:add_payload) ? s.add_payload(t) : s.config.update(t) 73 end
calculate_tag_cloud(num = 5)
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.rb 79 def calculate_tag_cloud(num = 5) 80 range = 0 81 82 tags = active_tags.map { |tag, posts| 83 [tag.to_s, range < (size = posts.size) ? range = size : size] 84 } 85 86 87 range = 1..range 88 89 tags.sort!.map! { |tag, size| [tag, range.quantile(size, num)] } 90 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.rb 44 def generate_tag_pages 45 active_tags.each { |tag, posts| new_tag(tag, posts) } 46 end
new_tag(tag, posts) { |data| ... }
click to toggle source
# File lib/jekyll/tagging.rb 48 def new_tag(tag, posts) 49 self.class.types.each { |type| 50 if layout = site.config["tag_#{type}_layout"] 51 data = { 'layout' => layout, 'posts' => posts.sort.reverse!, 'tag' => tag } 52 data.merge!(site.config["tag_#{type}_data"] || {}) 53 54 name = yield data if block_given? 55 name ||= tag 56 name = jekyll_tagging_slug(name) 57 58 tag_dir = site.config["tag_#{type}_dir"] 59 tag_dir = File.join(tag_dir, (pretty? ? name : '')) 60 61 page_name = "#{pretty? ? 'index' : name}#{site.layouts[data['layout']].ext}" 62 63 site.pages << TagPage.new( 64 site, site.source, tag_dir, page_name, data 65 ) 66 end 67 } 68 end
pretty?()
click to toggle source
# File lib/jekyll/tagging.rb 97 def pretty? 98 @pretty ||= (site.permalink_style == :pretty || site.config['tag_permalink_style'] == 'pretty') 99 end