diff --git a/ChangeLog b/ChangeLog index be40aad..9d0b148 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +== 1.1.0 [2017-03-07] + +* Added ability to append extra data to all tag pages. (tfe) +* Provides compatibility to the current jekyll (3.4.1). +* A few fixes. (felipe) +* Some documentation improvements. (wsmoak, jonathanpberger) +* Prooves who is the worst open source maintainer. (pattex ^__^) + +== 1.0.1 [2015-06-11] + +* Substitution of non ASCII characters and whitespaces, also when 'tag_permalink_style: pretty'. + +== 1.0.0 [2015-06-10] + +* Generate prettier urls for tag with whitespaces or non ASCII characters. ATTENTION: Your urls may change! +* Added support for site.config["baseurl"]. (Tsukasa ŌMOTO) +* Added trailing slashes to permalinks. (Pyry Kontio) + == 0.6.0 [2014-09-03] * Pretty permalinks for tag pages. (Steve Valaitis) diff --git a/README.rdoc b/README.rdoc index 563187d..ecc0aff 100644 --- a/README.rdoc +++ b/README.rdoc @@ -4,12 +4,23 @@ By Arne Eilermann and Jens Wille + +Add space-delimited lowercase tags to FrontMatter, e.g. + + --- + author: Willow Rosenberg + tags: feminism anti-capitalism witchcraft + --- + == Usage Install it: gem install jekyll-tagging - + Add this line to your Jekyll project's Gemfile: gem 'jekyll-tagging' @@ -25,7 +36,7 @@ And in your _config.yml you have to define your layout used to generate This will look for _layouts/tag_page.html, and use it to generate tag pages into the _site/tag directory. -Now you have a new filter called tag_cloud which you can use with the site object as argument in your layout to get a cloud of all your site's tags. The tags are linked to their related tag page. Furthermore, you have a tags filter which you can feed with a post or a site object to get a link list of all its tags. +Now you have a new filter called tag_cloud which you can use with the site object as argument in your layout to get a cloud of all your site's tags. The tags are linked to their related tag page. Furthermore, you have a tags filter which you can feed with a post or a page object to get a link list of all its tags. You can optionally define a per tag Atom/RSS feed. In your _config.yml define the following: @@ -43,6 +54,14 @@ If your Jekyll permalink configuration is set to something other than < === Ignoring tags Sometimes you don't want tag pages generated for certain pages. That's ok! Just add ignored_tags: [tags,to,ignore] to your _config.yml + +=== Extra data on tag pages + +You can attach extra data to generated tag pages by specifying tag_page_data in _config.yml (this also works for tag_feed_data). For example, you might want to exclude tag pages from being picked up by `jekyll-sitemap`: + + tag_page_data: + sitemap: false + === Example tag page layout (Save this to _layouts/tag_page.html if using the _config.yml snippet above.) @@ -64,6 +83,8 @@ Sometimes you don't want tag pages generated for certain pages. That's ok! Just === Example layout of an Atom feed +(Save this to _layouts/tag_feed.xml if using the _config.yml snippet above.) + --- layout: nil --- diff --git a/Rakefile b/Rakefile index c0f875c..78b841e 100644 --- a/Rakefile +++ b/Rakefile @@ -12,7 +12,7 @@ begin :email => ['arne@kleinerdrei.net', 'jens.wille@uni-koeln.de'], :license => %q{MIT}, :homepage => :pattex, - :dependencies => %w[ruby-nuggets] + :dependencies => %w[nuggets] } }} rescue LoadError => err diff --git a/jekyll-tagging.gemspec b/jekyll-tagging.gemspec index 571d0e2..e58f3fd 100644 --- a/jekyll-tagging.gemspec +++ b/jekyll-tagging.gemspec @@ -1,34 +1,40 @@ # -*- encoding: utf-8 -*- -# stub: jekyll-tagging 0.6.0 ruby lib +# stub: jekyll-tagging 1.1.0 ruby lib Gem::Specification.new do |s| - s.name = "jekyll-tagging" - s.version = "0.6.0" + s.name = "jekyll-tagging".freeze + s.version = "1.1.0" - s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= - s.require_paths = ["lib"] - s.authors = ["Arne Eilermann", "Jens Wille"] - s.date = "2014-09-03" - s.description = "Jekyll plugin to automatically generate a tag cloud and tag pages." - s.email = ["arne@kleinerdrei.net", "jens.wille@uni-koeln.de"] - s.extra_rdoc_files = ["ChangeLog"] - s.files = ["ChangeLog", "README.rdoc", "Rakefile", "lib/jekyll/tagging.rb", "lib/jekyll/tagging/version.rb"] - s.homepage = "http://github.com/pattex/jekyll-tagging" - s.licenses = ["MIT"] - s.post_install_message = "\njekyll-tagging-0.6.0 [2014-09-03]:\n\n* Pretty permalinks for tag pages. (Steve Valaitis)\n* Added support for keywords (allenlsy)\n\n" - s.rdoc_options = ["--title", "jekyll-tagging Application documentation (v0.6.0)", "--charset", "UTF-8", "--line-numbers", "--all", "--main", "ChangeLog"] - s.rubygems_version = "2.4.1" - s.summary = "Jekyll plugin to automatically generate a tag cloud and tag pages." + s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= + s.require_paths = ["lib".freeze] + s.authors = ["Arne Eilermann".freeze, "Jens Wille".freeze] + s.date = "2017-03-07" + s.description = "Jekyll plugin to automatically generate a tag cloud and tag pages.".freeze + s.email = ["arne@kleinerdrei.net".freeze, "jens.wille@uni-koeln.de".freeze] + s.extra_rdoc_files = ["ChangeLog".freeze] + s.files = ["ChangeLog".freeze, "README.rdoc".freeze, "Rakefile".freeze, "lib/jekyll/tagging.rb".freeze, "lib/jekyll/tagging/version.rb".freeze] + s.homepage = "http://github.com/pattex/jekyll-tagging".freeze + s.licenses = ["MIT".freeze] + s.post_install_message = "\njekyll-tagging-1.1.0 [2017-03-07]:\n\n* Added ability to append extra data to all tag pages. (tfe)\n* Provides compatibility to the current jekyll (3.4.1).\n* A few fixes. (felipe)\n* Some documentation improvements. (wsmoak, jonathanpberger)\n* Prooves who is the worst open source maintainer. (pattex ^__^)\n\n".freeze + s.rdoc_options = ["--title".freeze, "jekyll-tagging Application documentation (v1.1.0)".freeze, "--charset".freeze, "UTF-8".freeze, "--line-numbers".freeze, "--all".freeze, "--main".freeze, "ChangeLog".freeze] + s.rubygems_version = "2.6.10".freeze + s.summary = "Jekyll plugin to automatically generate a tag cloud and tag pages.".freeze if s.respond_to? :specification_version then s.specification_version = 4 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q.freeze, [">= 0"]) + s.add_development_dependency(%q.freeze, [">= 0.8.7", "~> 0.8"]) + s.add_development_dependency(%q.freeze, [">= 0"]) else - s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0.8.7", "~> 0.8"]) + s.add_dependency(%q.freeze, [">= 0"]) end else - s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0.8.7", "~> 0.8"]) + s.add_dependency(%q.freeze, [">= 0"]) end end diff --git a/lib/jekyll/tagging.rb b/lib/jekyll/tagging.rb index 1c29a0f..e4164b7 100644 --- a/lib/jekyll/tagging.rb +++ b/lib/jekyll/tagging.rb @@ -1,10 +1,26 @@ require 'nuggets/range/quantile' +require 'nuggets/i18n' require 'erb' module Jekyll + module Helpers + + # call-seq: + # jekyll_tagging_slug(str) => new_str + # + # Substitutes any diacritics in _str_ with their ASCII equivalents, + # whitespaces with dashes and converts _str_ to downcase. + def jekyll_tagging_slug(str) + str.to_s.replace_diacritics.downcase.gsub(/\s/, '-') + end + + end + class Tagger < Generator + include Helpers + safe true attr_accessor :site @@ -13,6 +29,20 @@ class Tagger < Generator class << self; attr_accessor :types, :site; end + @@classifiers={ + 'log'=>proc{|classes,value,min,max| + scaled = (classes*(Math.log(value) - Math.log(min))/(Math.log(max) - Math.log(min))).to_i + scaled == classes ? classes : scaled+1}, + 'linear'=>proc{|classes,value,min,max| (1..max).quantile(value, classes)} + } + + def initialize(config) + @ignored_tags=config["ignored_tags"] || [] + @threshold=(config["tag_threshold"] || '1').to_i + @permalink_style=config['tag_permalink_style'] + @classifier=config['tag_classifier'] || 'linear' + end + def generate(site) self.class.site = self.site = site @@ -33,9 +63,11 @@ def new_tag(tag, posts) self.class.types.each { |type| if layout = site.config["tag_#{type}_layout"] data = { 'layout' => layout, 'posts' => posts.sort.reverse!, 'tag' => tag } + data.merge!(site.config["tag_#{type}_data"] || {}) name = yield data if block_given? name ||= tag + name = jekyll_tagging_slug(name) tag_dir = site.config["tag_#{type}_dir"] tag_dir = File.join(tag_dir, (pretty? ? name : '')) @@ -50,7 +82,7 @@ def new_tag(tag, posts) end def add_tag_cloud(num = 5, name = 'tag_data') - s, t = site, { name => calculate_tag_cloud(num) } + s, t = site, { name => calculate_tag_cloud(@@classifiers[@classifier].curry[num]) } s.respond_to?(:add_payload) ? s.add_payload(t) : s.config.update(t) end @@ -58,26 +90,18 @@ def add_tag_cloud(num = 5, name = 'tag_data') # classes are: set-1..set-5. # # [[, ], ...] - def calculate_tag_cloud(num = 5) - range = 0 - - tags = active_tags.map { |tag, posts| - [tag.to_s, range < (size = posts.size) ? range = size : size] - } - - - range = 1..range - - tags.sort!.map! { |tag, size| [tag, range.quantile(size, num)] } + def calculate_tag_cloud(classifier) + tags = active_tags.map { |tag, posts| [tag, posts.size] } + min, max = tags.map { |tag, size| size }.minmax + tags.sort!.map! { |tag, size| [tag, classifier.call(size,min,max)] } end def active_tags - return site.tags unless site.config["ignored_tags"] - site.tags.reject { |t| site.config["ignored_tags"].include? t[0] } + site.tags.reject { |tag, posts| @ignored_tags.include? tag or posts.size < @threshold} end def pretty? - @pretty ||= (site.permalink_style == :pretty || site.config['tag_permalink_style'] == 'pretty') + @pretty ||= (site.permalink_style == :pretty || @permalink_style == 'pretty') end end @@ -97,7 +121,9 @@ def read_yaml(*) end - module Filters + module TaggingFilters + + include Helpers def tag_cloud(site) active_tag_data.map { |tag, set| @@ -111,8 +137,8 @@ def tag_link(tag, url = tag_url(tag), html_opts = nil) end def tag_url(tag, type = :page, site = Tagger.site) - url = File.join('', site.config["tag_#{type}_dir"], ERB::Util.u(tag)) - site.permalink_style == :pretty || site.config['tag_permalink_style'] == 'pretty' ? url : url << '.html' + url = File.join('', site.config["baseurl"].to_s, site.config["tag_#{type}_dir"], ERB::Util.u(jekyll_tagging_slug(tag))) + site.permalink_style == :pretty || site.config['tag_permalink_style'] == 'pretty' ? url << '/' : url << '.html' end def tags(obj) @@ -125,13 +151,14 @@ def tags(obj) def keywords(obj) return '' if not obj['tags'] tags = obj['tags'].dup - tags.join(',') + tags.join(',') end def active_tag_data(site = Tagger.site) - return site.config['tag_data'] unless site.config["ignored_tags"] - site.config["tag_data"].reject { |tag, set| site.config["ignored_tags"].include? tag } + return site.config['tag_data'] end end end + +Liquid::Template.register_filter(Jekyll::TaggingFilters) diff --git a/lib/jekyll/tagging/version.rb b/lib/jekyll/tagging/version.rb index 3f60c88..41bc146 100644 --- a/lib/jekyll/tagging/version.rb +++ b/lib/jekyll/tagging/version.rb @@ -4,8 +4,8 @@ module Tagging module Version - MAJOR = 0 - MINOR = 6 + MAJOR = 1 + MINOR = 1 TINY = 0 class << self