jekyll-tagging 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5 -0
- data/README.rdoc +2 -2
- data/lib/jekyll/tagging/version.rb +2 -2
- data/lib/jekyll/tagging.rb +30 -16
- metadata +4 -4
data/ChangeLog
CHANGED
data/README.rdoc
CHANGED
@@ -19,7 +19,7 @@ And in your <tt>_config.yml</tt> you have to define your layout used to generate
|
|
19
19
|
tag_page_layout: tag_page
|
20
20
|
tag_page_dir: tag
|
21
21
|
|
22
|
-
Now you got 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.
|
22
|
+
Now you got 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 got a <tt>tags</tt> filter which you can feed withe a <tt>post</tt> or a <tt>site</tt> object to get a link list of all its tags.
|
23
23
|
|
24
24
|
=== Example tag page layout
|
25
25
|
|
@@ -29,7 +29,7 @@ Now you got a new filter called <tt>tag_cloud</tt> which you can use with the <t
|
|
29
29
|
<h2>{{ page.tag }}</h2>
|
30
30
|
<ul>
|
31
31
|
{% for post in page.posts %}
|
32
|
-
<li><a href="{{ post.url }}">{{ post.title }}</a> ({{ post.date | date_to_string }})</li>
|
32
|
+
<li><a href="{{ post.url }}">{{ post.title }}</a> ({{ post.date | date_to_string }} | Tags: {{ post | tags }})</li>
|
33
33
|
{% endfor %}
|
34
34
|
</ul>
|
35
35
|
|
data/lib/jekyll/tagging.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
|
-
require 'nuggets/range/
|
1
|
+
require 'nuggets/range/quantile'
|
2
2
|
require 'erb'
|
3
3
|
|
4
|
-
class Range
|
5
|
-
include Nuggets::Range::QuantileMixin
|
6
|
-
end
|
7
|
-
|
8
4
|
module Jekyll
|
9
5
|
|
10
6
|
class Tagger < Generator
|
11
7
|
|
12
8
|
safe true
|
13
9
|
|
10
|
+
DEFAULT_TAG_PAGE_DIR = 'tag'
|
11
|
+
|
14
12
|
def generate(site)
|
15
|
-
@tag_page_dir = site.config['tag_page_dir'] ||
|
13
|
+
@tag_page_dir = site.config['tag_page_dir'] || DEFAULT_TAG_PAGE_DIR
|
16
14
|
@tag_page_layout = site.config['tag_page_layout']
|
17
15
|
|
18
16
|
generate_tag_pages(site) if @tag_page_layout
|
@@ -39,19 +37,17 @@ module Jekyll
|
|
39
37
|
# classes are: set-1..set-5.
|
40
38
|
#
|
41
39
|
# [[<TAG>, <CLASS>], ...]
|
42
|
-
def calculate_tag_cloud(site)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
tag_data << [t[0], "set-#{quant}"]
|
48
|
-
}
|
49
|
-
tag_data
|
40
|
+
def calculate_tag_cloud(site, num = 5)
|
41
|
+
tags = site.tags.map { |tag, posts| [tag, posts.size] }.sort
|
42
|
+
range = 1..tags.map { |_, size| size }.max
|
43
|
+
|
44
|
+
tags.map { |tag, size| [tag, range.quantile(size, num)] }
|
50
45
|
end
|
51
46
|
|
52
47
|
end
|
53
48
|
|
54
49
|
class TagPage < Page
|
50
|
+
|
55
51
|
def initialize(site, base, dir, name, data = {})
|
56
52
|
self.content = data.delete('content') || ''
|
57
53
|
self.data = data
|
@@ -72,11 +68,29 @@ module Jekyll
|
|
72
68
|
module Filters
|
73
69
|
|
74
70
|
def tag_cloud(site)
|
75
|
-
site['
|
76
|
-
|
71
|
+
dir = site['tag_page_dir']
|
72
|
+
|
73
|
+
site['tag_data'].map { |tag, set|
|
74
|
+
tag_link(tag, tag_url(tag, dir), { :class => "set-#{set}" })
|
77
75
|
}.join(' ')
|
78
76
|
end
|
79
77
|
|
78
|
+
def tag_link(tag, url = tag_url(tag), html_opts = nil)
|
79
|
+
unless html_opts.nil?
|
80
|
+
html_opts = ' ' + html_opts.map { |k, v| %Q{#{k}="#{v}"} }.join(' ')
|
81
|
+
end
|
82
|
+
%Q{<a href="#{url}"#{html_opts}>#{tag}</a>}
|
83
|
+
end
|
84
|
+
|
85
|
+
def tag_url(tag, dir = Tagger::DEFAULT_TAG_PAGE_DIR)
|
86
|
+
"/#{dir}/#{ERB::Util.u(tag)}.html"
|
87
|
+
end
|
88
|
+
|
89
|
+
def tags(obj)
|
90
|
+
tags = obj['tags'][0].is_a?(Array) ? obj['tags'].map{ |t| t[0]} : obj['tags']
|
91
|
+
tags.map { |t| tag_link(t, tag_url(t)) if t.is_a?(String) }.compact.join(', ')
|
92
|
+
end
|
93
|
+
|
80
94
|
end
|
81
95
|
|
82
96
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-tagging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Arne Eilermann
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-10-
|
19
|
+
date: 2010-10-28 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|