mm-jekyll-tags-list 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Changelog.md +8 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +50 -0
- data/Rakefile +1 -0
- data/lib/mm-jekyll-tags-list.rb +41 -0
- data/mm_jekyll_tags_list_plugin.gemspec +26 -0
- data/script/bootstrap +3 -0
- data/script/cibuild +3 -0
- data/spec/mm_jekyll_tags_list_spec.rb +73 -0
- data/spec/spec_helper.rb +40 -0
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 385fcb96e785760a222f9fd8ffe6565352d0c0db
|
4
|
+
data.tar.gz: 8e43122f3f71cc53973f1a8e6d50c66b08abdbbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d7a7b0b89c5205a1371330961e1359e050d4d43c8e596ebde053674577949930308c4b11a9eb12954327360e32ef32e3657de75a3b6b7cf928c89420bf6775b
|
7
|
+
data.tar.gz: f906e3826f76a91ce47593eb7a5e742f2cb32c056866f1990298f40a07e00148edc7f6153df51018f346742b7607264ec69d9d91c10156f833d56a44697af2e2
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/Changelog.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tim Oram
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Jekyll Tags Plugin
|
2
|
+
|
3
|
+
Provides a list of tags for use in tag lists or tag clouds.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem mm-jekyll-tags-list
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install mm-jekyll-tags-list
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
You must define a value for *number_popularity_classes* in _config.yml for this plugin to work. *number_popularity_classes* is the number of classes to divide the tag across for the tag cloud.
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
This plugin adds two data value, *tag_list* and *tag_data*. *tag_list* contains a list of all the tags that are used in the site. *tag_data* contains a hash with the following structure:
|
28
|
+
|
29
|
+
{'tagOne': {
|
30
|
+
'post_count': 10,
|
31
|
+
'popularity': 44,
|
32
|
+
'popularity_class': 2
|
33
|
+
},
|
34
|
+
'tagTwo': {
|
35
|
+
'post_count': 14,
|
36
|
+
'popularity': 67,
|
37
|
+
'popularity_class': 5
|
38
|
+
},
|
39
|
+
...}
|
40
|
+
|
41
|
+
*post_count* contains the number of posts that use the tag, *popularity* is the percentage from 0-100 of the tag, and *popularity_class* is a remapping of the percentage to a numerical range between 0 and *number_popularity_classes*.
|
42
|
+
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it ( https://github.com/mitmaro/jekyll-tags-list-plugin/fork )
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Jekyll
|
2
|
+
class TagsList < Generator
|
3
|
+
|
4
|
+
def generate(site)
|
5
|
+
site.data['tag_list'] = TagsList.generate_tags_structure(site).keys
|
6
|
+
site.data['tag_data'] = TagsList.generate_tags_structure(site)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.generate_tags_structure(site)
|
10
|
+
tags = Hash.new
|
11
|
+
maximum = calculate_maximum_post_count(site)
|
12
|
+
for tag in site.tags.keys do
|
13
|
+
tags[tag] = Hash.new
|
14
|
+
post_count = number_of_posts_for_tag(site, tag)
|
15
|
+
popularity = calculate_popularity(maximum, post_count)
|
16
|
+
popularity_class = calculate_popularity_class(site, maximum, popularity)
|
17
|
+
tags[tag]['post_count'] = post_count.to_s
|
18
|
+
tags[tag]['popularity'] = popularity.to_s
|
19
|
+
tags[tag]['popularity_class'] = popularity_class.to_s
|
20
|
+
end
|
21
|
+
tags
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.calculate_popularity_class(site, maximum, popularity)
|
25
|
+
output = ((site.config['number_popularity_classes'] / 100.to_f) * popularity).round
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.calculate_maximum_post_count(site)
|
29
|
+
max = site.tags.map { |tag,posts| posts.count }.max
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.number_of_posts_for_tag(site, tag)
|
33
|
+
count = site.tags[tag].length
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.calculate_popularity(maximum, count)
|
37
|
+
percent = ((count.to_f / maximum) * 100).floor
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "mm-jekyll-tags-list"
|
7
|
+
spec.version = "0.0.2"
|
8
|
+
spec.authors = ["Tim Oram"]
|
9
|
+
spec.email = ["mitmaro@gmail.com"]
|
10
|
+
spec.summary = %q{Tags List plugin for Jekyll}
|
11
|
+
spec.description = %q{Provides a list of tags for use in tag lists or tag clouds.}
|
12
|
+
spec.homepage = "https://github.com/mitmaro/jekyll-tags-list-plugin"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "jekyll", "~> 2.0"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
spec.add_development_dependency "rspec-mocks", "~> 3.0"
|
25
|
+
|
26
|
+
end
|
data/script/bootstrap
ADDED
data/script/cibuild
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Jekyll::TagsList do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@site = double("tags" => {
|
7
|
+
'a' => [1,2,3,4,5],
|
8
|
+
'b' => [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],
|
9
|
+
'c' => [1,2,3],
|
10
|
+
'd' => [1,2],
|
11
|
+
'e' => [1,2,3,4],
|
12
|
+
'f' => [1,2,3,4,5,6,7],
|
13
|
+
'g' => [1,2,3,4,5,6,7,8],
|
14
|
+
'g' => [1,2,3,4,5,6,7,8,9,10,11],
|
15
|
+
'h' => [1,2,3],
|
16
|
+
'i' => [1,2,3,4,5],
|
17
|
+
},
|
18
|
+
"config" => {
|
19
|
+
"number_popularity_classes" => 5
|
20
|
+
})
|
21
|
+
end
|
22
|
+
|
23
|
+
it "calculates the number of posts for tag" do
|
24
|
+
expect(described_class.number_of_posts_for_tag(@site, 'a')).to eql(5)
|
25
|
+
expect(described_class.number_of_posts_for_tag(@site, 'b')).to eql(15)
|
26
|
+
expect(described_class.number_of_posts_for_tag(@site, 'c')).to eql(3)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "calculates the maximum post count for a tag" do
|
30
|
+
expect(described_class.calculate_maximum_post_count(@site)).to eql(15)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "calculates the popularity of a post for a tag" do
|
34
|
+
expect(described_class.calculate_popularity(15, 12)).to eql(80)
|
35
|
+
expect(described_class.calculate_popularity(15, 2)).to eql(13)
|
36
|
+
expect(described_class.calculate_popularity(15, 3)).to eql(20)
|
37
|
+
expect(described_class.calculate_popularity(15, 4)).to eql(26)
|
38
|
+
expect(described_class.calculate_popularity(15, 5)).to eql(33)
|
39
|
+
expect(described_class.calculate_popularity(15, 8)).to eql(53)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "calculates the popularity class of a post for a tag" do
|
43
|
+
expect(described_class.calculate_popularity_class(@site, 100, 0)).to eql(0)
|
44
|
+
expect(described_class.calculate_popularity_class(@site, 100, 9)).to eql(0)
|
45
|
+
expect(described_class.calculate_popularity_class(@site, 100, 10)).to eql(1)
|
46
|
+
expect(described_class.calculate_popularity_class(@site, 100, 20)).to eql(1)
|
47
|
+
expect(described_class.calculate_popularity_class(@site, 100, 21)).to eql(1)
|
48
|
+
expect(described_class.calculate_popularity_class(@site, 100, 29)).to eql(1)
|
49
|
+
expect(described_class.calculate_popularity_class(@site, 100, 30)).to eql(2)
|
50
|
+
expect(described_class.calculate_popularity_class(@site, 100, 39)).to eql(2)
|
51
|
+
expect(described_class.calculate_popularity_class(@site, 100, 40)).to eql(2)
|
52
|
+
expect(described_class.calculate_popularity_class(@site, 100, 49)).to eql(2)
|
53
|
+
expect(described_class.calculate_popularity_class(@site, 100, 50)).to eql(3)
|
54
|
+
expect(described_class.calculate_popularity_class(@site, 100, 59)).to eql(3)
|
55
|
+
expect(described_class.calculate_popularity_class(@site, 100, 60)).to eql(3)
|
56
|
+
expect(described_class.calculate_popularity_class(@site, 100, 69)).to eql(3)
|
57
|
+
expect(described_class.calculate_popularity_class(@site, 100, 70)).to eql(4)
|
58
|
+
expect(described_class.calculate_popularity_class(@site, 100, 79)).to eql(4)
|
59
|
+
expect(described_class.calculate_popularity_class(@site, 100, 80)).to eql(4)
|
60
|
+
expect(described_class.calculate_popularity_class(@site, 100, 89)).to eql(4)
|
61
|
+
expect(described_class.calculate_popularity_class(@site, 100, 90)).to eql(5)
|
62
|
+
expect(described_class.calculate_popularity_class(@site, 100, 99)).to eql(5)
|
63
|
+
expect(described_class.calculate_popularity_class(@site, 100, 100)).to eql(5)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "generates a tags structure for site" do
|
67
|
+
result = described_class.generate_tags_structure(@site)
|
68
|
+
expect(result["a"]["post_count"]).to eql("5")
|
69
|
+
expect(result["a"]["popularity"]).to eql("33")
|
70
|
+
expect(result["a"]["popularity_class"]).to eql("2")
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
p File.expand_path('../lib/mm-jekyll-tags-list', File.dirname(__FILE__))
|
3
|
+
require File.expand_path('../lib/mm-jekyll-tags-list', File.dirname(__FILE__))
|
4
|
+
|
5
|
+
Jekyll.logger.log_level = :error
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
config.filter_run :focus
|
10
|
+
|
11
|
+
def test_dir(*subdirs)
|
12
|
+
File.join(File.dirname(__FILE__), *subdirs)
|
13
|
+
end
|
14
|
+
|
15
|
+
def source_dir(*subdirs)
|
16
|
+
test_dir('fixtures', *subdirs)
|
17
|
+
end
|
18
|
+
|
19
|
+
def dest_dir(*subdirs)
|
20
|
+
test_dir('dest', *subdirs)
|
21
|
+
end
|
22
|
+
|
23
|
+
def build_configs(overrides, base_hash = Jekyll::Configuration::DEFAULTS)
|
24
|
+
Jekyll::Utils.deep_merge_hashes(base_hash, overrides)
|
25
|
+
end
|
26
|
+
|
27
|
+
def site_configuration(overrides = {})
|
28
|
+
build_configs({
|
29
|
+
"source" => source_dir,
|
30
|
+
"destination" => dest_dir
|
31
|
+
}, build_configs(overrides))
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_site(config = {})
|
35
|
+
site = Jekyll::Site.new(site_configuration(
|
36
|
+
))
|
37
|
+
site.process
|
38
|
+
site
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mm-jekyll-tags-list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Oram
|
@@ -86,8 +86,20 @@ email:
|
|
86
86
|
executables: []
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
|
-
files:
|
90
|
-
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Changelog.md
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/mm-jekyll-tags-list.rb
|
97
|
+
- mm_jekyll_tags_list_plugin.gemspec
|
98
|
+
- script/bootstrap
|
99
|
+
- script/cibuild
|
100
|
+
- spec/mm_jekyll_tags_list_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: https://github.com/mitmaro/jekyll-tags-list-plugin
|
91
103
|
licenses:
|
92
104
|
- MIT
|
93
105
|
metadata: {}
|
@@ -111,4 +123,6 @@ rubygems_version: 2.4.1
|
|
111
123
|
signing_key:
|
112
124
|
specification_version: 4
|
113
125
|
summary: Tags List plugin for Jekyll
|
114
|
-
test_files:
|
126
|
+
test_files:
|
127
|
+
- spec/mm_jekyll_tags_list_spec.rb
|
128
|
+
- spec/spec_helper.rb
|