Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c71874c
Support site.config["baseurl"]
henry0312 Jun 11, 2014
a8bcbe6
add configurable threshold and classifier
nidi3 Jan 3, 2015
7b78cac
cosmetics
nidi3 Jan 3, 2015
0a294d1
Fixed pretty permalinks: added trailing slash
golddranks Jan 10, 2015
7a74f89
Merge pull request #30 from golddranks/master
pattex Jan 12, 2015
b0e373f
Merge branch 'baseurl' of https://github.com/henry0312/jekyll-tagging…
pattex Jun 9, 2015
9238848
Tidied parameters.
pattex Jun 9, 2015
df29cce
Merge pull request #20 from henry0312/baseurl
pattex Jun 9, 2015
34b0eb9
Oh stupid me! m)
pattex Jun 9, 2015
11eb1f9
Substitute diacritics with their ASCII equivalents, whitespaces with
pattex Jun 10, 2015
7c87d91
v1.0.0
pattex Jun 10, 2015
73b6fa2
Substitution of non ASCII characters and whitespaces, also when
pattex Jun 11, 2015
a7768f2
v1.0.1
pattex Jun 11, 2015
3790d3a
Explain where to save the tag feed layout
wsmoak Jul 19, 2015
5275135
Add example code for putting tags into posts into README.
jonathanpberger Nov 19, 2015
ed09d3d
call to_s
Dec 19, 2015
4cfc683
Add ability to append extra data to all tag pages or tag feeds.
tfe Mar 29, 2016
b5a653e
Flip around the order of merging custom page data and stock data. Hav…
tfe Apr 11, 2016
588d6c7
Merge pull request #40 from wsmoak/tag-feed-location
pattex Aug 18, 2016
2554736
Merge branch 'patch-1' of https://github.com/jonathanpberger/jekyll-t…
pattex Aug 18, 2016
c000c98
Changed and removed some of jonathanpberger's additions.
pattex Aug 22, 2016
7383fea
Merge commit 'ed09d3d7b6590d242fe8b57948881567cb000f0e' into queirozf…
pattex Aug 30, 2016
4e8ea8c
Merge branch 'add-tag-page-extra-data' of https://github.com/tfe/jeky…
pattex Aug 30, 2016
56985bd
Added tfs's "ability to append extra data to all tag pages" to the Ch…
pattex Aug 30, 2016
d58fd53
Register the new Liquid filters.
pattex Sep 1, 2016
1e32a01
Corrected wrong documentation.
pattex Sep 1, 2016
a981f78
Updated dependencies from ruby-nuggets to nuggets.
pattex Sep 1, 2016
76fbc51
v1.1.0
pattex Mar 7, 2017
6bcb178
add configurable threshold and classifier
nidi3 Jan 3, 2015
65443a6
cosmetics
nidi3 Jan 3, 2015
2ea37f5
Merge remote-tracking branch 'origin/master'
nidi3 Oct 20, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
25 changes: 23 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@ By Arne Eilermann <mailto:[email protected]> and Jens Wille <mailto:jens.will

jekyll-tagging is a Jekyll plugin, to add a tag cloud and per tag pages plus feeds to your Jekyll generated Website.

== Tags
This plugin does not reinvent Jekyll's tagging feature. It just makes it easy to use.
<https://jekyllrb.com/docs/frontmatter/>

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'
Expand All @@ -25,7 +36,7 @@ And in your <tt>_config.yml</tt> you have to define your layout used to generate

This will look for <tt>_layouts/tag_page.html</tt>, and use it to generate tag pages into the <tt>_site/tag</tt> directory.

Now you have a new filter called <tt>tag_cloud</tt> which you can use with the <tt>site</tt> 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 <tt>tags</tt> filter which you can feed with a <tt>post</tt> or a <tt>site</tt> object to get a link list of all its tags.
Now you have a new filter called <tt>tag_cloud</tt> which you can use with the <tt>site</tt> 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 <tt>tags</tt> filter which you can feed with a <tt>post</tt> or a <tt>page</tt> object to get a link list of all its tags.

You can optionally define a per tag Atom/RSS feed. In your <tt>_config.yml</tt> define the following:

Expand All @@ -43,6 +54,14 @@ If your Jekyll <tt>permalink</tt> 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 <tt>ignored_tags: [tags,to,ignore]</tt> to your <tt>_config.yml</tt>

=== Extra data on tag pages

You can attach extra data to generated tag pages by specifying <tt>tag_page_data</tt> in <tt>_config.yml</tt> (this also works for <tt>tag_feed_data</tt>). 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 <tt>_layouts/tag_page.html</tt> if using the <tt>_config.yml</tt> snippet above.)
Expand All @@ -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 <tt>_layouts/tag_feed.xml</tt> if using the <tt>_config.yml</tt> snippet above.)

---
layout: nil
---
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ begin
:email => ['[email protected]', '[email protected]'],
:license => %q{MIT},
:homepage => :pattex,
:dependencies => %w[ruby-nuggets]
:dependencies => %w[nuggets]
}
}}
rescue LoadError => err
Expand Down
46 changes: 26 additions & 20 deletions jekyll-tagging.gemspec
Original file line number Diff line number Diff line change
@@ -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 = ["[email protected]", "[email protected]"]
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 = ["[email protected]".freeze, "[email protected]".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<ruby-nuggets>, [">= 0"])
s.add_runtime_dependency(%q<nuggets>.freeze, [">= 0"])
s.add_development_dependency(%q<hen>.freeze, [">= 0.8.7", "~> 0.8"])
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
else
s.add_dependency(%q<ruby-nuggets>, [">= 0"])
s.add_dependency(%q<nuggets>.freeze, [">= 0"])
s.add_dependency(%q<hen>.freeze, [">= 0.8.7", "~> 0.8"])
s.add_dependency(%q<rake>.freeze, [">= 0"])
end
else
s.add_dependency(%q<ruby-nuggets>, [">= 0"])
s.add_dependency(%q<nuggets>.freeze, [">= 0"])
s.add_dependency(%q<hen>.freeze, [">= 0.8.7", "~> 0.8"])
s.add_dependency(%q<rake>.freeze, [">= 0"])
end
end
69 changes: 48 additions & 21 deletions lib/jekyll/tagging.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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 : ''))
Expand All @@ -50,34 +82,26 @@ 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

# Calculates the css class of every tag for a tag cloud. The possible
# classes are: set-1..set-5.
#
# [[<TAG>, <CLASS>], ...]
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
Expand All @@ -97,7 +121,9 @@ def read_yaml(*)

end

module Filters
module TaggingFilters

include Helpers

def tag_cloud(site)
active_tag_data.map { |tag, set|
Expand All @@ -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)
Expand All @@ -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)
4 changes: 2 additions & 2 deletions lib/jekyll/tagging/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module Tagging

module Version

MAJOR = 0
MINOR = 6
MAJOR = 1
MINOR = 1
TINY = 0

class << self
Expand Down