jekyll-tagging 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5 -0
- data/Rakefile +2 -2
- data/lib/jekyll/tagging.rb +48 -45
- data/lib/jekyll/tagging/version.rb +2 -2
- metadata +3 -3
data/ChangeLog
CHANGED
data/Rakefile
CHANGED
data/lib/jekyll/tagging.rb
CHANGED
@@ -7,58 +7,62 @@ module Jekyll
|
|
7
7
|
|
8
8
|
safe true
|
9
9
|
|
10
|
-
|
11
|
-
%w[TAG_PAGE_DIR TAG_FEED_DIR].each do |dir_name|
|
12
|
-
unless Tagger.const_defined?(dir_name.to_sym)
|
13
|
-
Tagger.const_set(dir_name, site.config[dir_name.downcase] || 'tag')
|
14
|
-
end
|
15
|
-
end
|
10
|
+
attr_accessor :site
|
16
11
|
|
17
|
-
|
18
|
-
@tag_feed_layout = site.config['tag_feed_layout']
|
12
|
+
@types = [:page, :feed]
|
19
13
|
|
20
|
-
|
21
|
-
Jekyll::Filters.const_set('PRETTY_URL', site.permalink_style == :pretty)
|
22
|
-
end
|
14
|
+
class << self; attr_accessor :types, :site; end
|
23
15
|
|
24
|
-
|
25
|
-
|
26
|
-
else
|
27
|
-
warn 'WARNING: You have to define a tag_page_layout in configuration file.'
|
28
|
-
end
|
16
|
+
def generate(site)
|
17
|
+
self.class.site = self.site = site
|
29
18
|
|
30
|
-
|
31
|
-
|
19
|
+
generate_tag_pages
|
20
|
+
add_tag_cloud
|
32
21
|
end
|
33
22
|
|
23
|
+
private
|
24
|
+
|
34
25
|
# Generates a page per tag and adds them to all the pages of +site+.
|
35
26
|
# A <tt>tag_page_layout</tt> have to be defined in your <tt>_config.yml</tt>
|
36
27
|
# to use this.
|
37
|
-
def generate_tag_pages
|
38
|
-
site.tags.each { |tag, posts|
|
39
|
-
|
40
|
-
|
41
|
-
|
28
|
+
def generate_tag_pages
|
29
|
+
site.tags.each { |tag, posts| new_tag(tag, posts) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def new_tag(tag, posts)
|
33
|
+
self.class.types.each { |type|
|
34
|
+
if layout = site.config["tag_#{type}_layout"]
|
35
|
+
data = { 'layout' => layout, 'posts' => posts.sort.reverse! }
|
36
|
+
|
37
|
+
name = yield data if block_given?
|
38
|
+
|
39
|
+
site.pages << TagPage.new(
|
40
|
+
site, site.source, site.config["tag_#{type}_dir"],
|
41
|
+
"#{name || tag}#{site.layouts[data['layout']].ext}", data
|
42
|
+
)
|
42
43
|
end
|
43
44
|
}
|
44
45
|
end
|
45
46
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
'posts' => posts,
|
50
|
-
})
|
47
|
+
def add_tag_cloud(num = 5, name = 'tag_data')
|
48
|
+
s, t = site, { name => calculate_tag_cloud(num) }
|
49
|
+
s.respond_to?(:add_payload) ? s.add_payload(t) : s.config.update(t)
|
51
50
|
end
|
52
51
|
|
53
52
|
# Calculates the css class of every tag for a tag cloud. The possible
|
54
53
|
# classes are: set-1..set-5.
|
55
54
|
#
|
56
55
|
# [[<TAG>, <CLASS>], ...]
|
57
|
-
def calculate_tag_cloud(
|
58
|
-
|
59
|
-
|
56
|
+
def calculate_tag_cloud(num = 5)
|
57
|
+
range = 0
|
58
|
+
|
59
|
+
tags = site.tags.map { |tag, posts|
|
60
|
+
[tag.to_s, range < (size = posts.size) ? range = size : size]
|
61
|
+
}
|
62
|
+
|
63
|
+
range = 1..range
|
60
64
|
|
61
|
-
tags.map { |tag, size| [tag, range.quantile(size, num)] }
|
65
|
+
tags.sort!.map! { |tag, size| [tag, range.quantile(size, num)] }
|
62
66
|
end
|
63
67
|
|
64
68
|
end
|
@@ -69,14 +73,12 @@ module Jekyll
|
|
69
73
|
self.content = data.delete('content') || ''
|
70
74
|
self.data = data
|
71
75
|
|
72
|
-
|
73
|
-
|
74
|
-
super(site, base, dir, name)
|
76
|
+
super(site, base, dir[-1, 1] == '/' ? dir : '/' + dir, name)
|
75
77
|
|
76
|
-
|
78
|
+
data['tag'] ||= basename
|
77
79
|
end
|
78
80
|
|
79
|
-
def read_yaml(
|
81
|
+
def read_yaml(*)
|
80
82
|
# Do nothing
|
81
83
|
end
|
82
84
|
|
@@ -86,24 +88,25 @@ module Jekyll
|
|
86
88
|
|
87
89
|
def tag_cloud(site)
|
88
90
|
site['tag_data'].map { |tag, set|
|
89
|
-
tag_link(tag, tag_url(tag),
|
91
|
+
tag_link(tag, tag_url(tag), :class => "set-#{set}")
|
90
92
|
}.join(' ')
|
91
93
|
end
|
92
94
|
|
93
95
|
def tag_link(tag, url = tag_url(tag), html_opts = nil)
|
94
|
-
|
95
|
-
html_opts = ' ' + html_opts.map { |k, v| %Q{#{k}="#{v}"} }.join(' ')
|
96
|
-
end
|
96
|
+
html_opts &&= ' ' << html_opts.map { |k, v| %Q{#{k}="#{v}"} }.join(' ')
|
97
97
|
%Q{<a href="#{url}"#{html_opts}>#{tag}</a>}
|
98
98
|
end
|
99
99
|
|
100
|
-
def tag_url(tag)
|
101
|
-
"
|
100
|
+
def tag_url(tag, type = :page, site = Tagger.site)
|
101
|
+
url = File.join('', site.config["tag_#{type}_dir"], ERB::Util.u(tag))
|
102
|
+
site.permalink_style == :pretty ? url : url << '.html'
|
102
103
|
end
|
103
104
|
|
104
105
|
def tags(obj)
|
105
|
-
tags = obj['tags']
|
106
|
-
tags.map { |t|
|
106
|
+
tags = obj['tags'].dup
|
107
|
+
tags.map! { |t| t.first } if tags.first.is_a?(Array)
|
108
|
+
tags.map! { |t| tag_link(t, tag_url(t)) if t.is_a?(String) }.compact!
|
109
|
+
tags.join(', ')
|
107
110
|
end
|
108
111
|
|
109
112
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-tagging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-10-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ruby-nuggets
|
@@ -51,7 +51,7 @@ rdoc_options:
|
|
51
51
|
- --line-numbers
|
52
52
|
- --all
|
53
53
|
- --title
|
54
|
-
- jekyll-tagging Application documentation (v0.
|
54
|
+
- jekyll-tagging Application documentation (v0.4.0)
|
55
55
|
- --main
|
56
56
|
- ChangeLog
|
57
57
|
require_paths:
|