jekyll-tagging-related_posts 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e2d867dcf20c6da79bf081959fa90e988c489f9f
4
+ data.tar.gz: 0edfcd46f1fb75596cf88235ecf906de89e8c328
5
+ SHA512:
6
+ metadata.gz: fe7a19d6f053b1c5087e4809abc8dd91f345e230115609c8fe29959bfbfbf8b10afb2621c4c9037417f611b291197853d53db1a8e9bf3402ee7ce7d4f036ae6b
7
+ data.tar.gz: e1a741b1722d3a908f52475e05e7faa13efd9277550e741466fb750cdfd79e7d4ef92c605ca11bfcbb85a2ee286077b16e952eb8d3770e37eccb22f17180347e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jekyll-tagging-related_posts.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 toshi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+
2
+ # jekyll-tagging-related_posts
3
+
4
+ Jekyll `related_posts` function based on tags (works for only Jekyll3). It replaces original Jekyll's `related_posts` function to use tags to calculate relationships.
5
+
6
+ The calculation algorithm is based on [LawrenceWoodman/related\_posts-jekyll\_plugin](https://github.com/LawrenceWoodman/related_posts-jekyll_plugin).
7
+
8
+ ## Requirements
9
+ * [Jekyll 3.x](https://github.com/jekyll/jekyll)
10
+ * [pattex/jekyll-tagging](https://github.com/pattex/jekyll-tagging)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'jekyll-tagging-related_posts'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install jekyll-tagging-related_posts
27
+
28
+ ## Usage
29
+
30
+ Edit `_config.yml` to use the plug-in:
31
+
32
+ ```yml
33
+ gems:
34
+ - jekyll/tagging
35
+ - jekyll-tagging-related_posts
36
+ ```
37
+
38
+ Then, add related_posts in your post layout.
39
+
40
+ ```liquid
41
+ {% if site.related_posts.size >= 1 %}
42
+ <div>
43
+ <h3>Related Posts</h3>
44
+ <ul>
45
+ {% for related_post in site.related_posts limit: 5 %}
46
+ <li><a href="{{ related_post.url }}">{{ related_post.title }}</a></li>
47
+ {% endfor %}
48
+ </ul>
49
+ </div>
50
+ {% endif %}
51
+ ```
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/toshimaru/jekyll-tagging-related_posts. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jekyll-tagging-related_posts"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jekyll/tagging/related_posts/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-tagging-related_posts"
8
+ spec.version = Jekyll::Tagging::RelatedPosts::VERSION
9
+ spec.authors = ["toshimaru"]
10
+ spec.email = ["me@toshimaru.net"]
11
+
12
+ spec.summary = %q{Replaces Jekyll's related_posts function to use tags to calculate relationships}
13
+ spec.description = %q{Replaces Jekyll's related_posts function to use tags to calculate relationships}
14
+ spec.homepage = "https://github.com/toshimaru/jekyll-tagging-related_posts"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "jekyll", "~> 3.0"
23
+ spec.add_runtime_dependency "jekyll-tagging", "~> 1.0.0"
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "byebug"
27
+ spec.add_development_dependency "minitest"
28
+ end
@@ -0,0 +1,10 @@
1
+ require "jekyll/document"
2
+
3
+ require "jekyll/tagging/related_posts/version"
4
+ require "jekyll/tagging/related_posts"
5
+
6
+ module Jekyll
7
+ class Document
8
+ include ::Jekyll::Tagging::RelatedPosts
9
+ end
10
+ end
@@ -0,0 +1,62 @@
1
+ require "jekyll/tagging/related_posts/version"
2
+
3
+ module Jekyll
4
+ module Tagging
5
+ module RelatedPosts
6
+ # Used to remove #related_posts so that it can be overridden
7
+ def self.included(klass)
8
+ klass.class_eval do
9
+ remove_method :related_posts
10
+ end
11
+ end
12
+
13
+ # Calculate related posts.
14
+ # Returns [<Post>]
15
+ def related_posts
16
+ return [] unless docs.count > 1
17
+ highest_freq = tag_freq.values.max
18
+ related_scores = Hash.new(0)
19
+
20
+ docs.each do |doc|
21
+ doc.data["tags"].each do |tag|
22
+ if self.data["tags"].include?(tag) && doc != self
23
+ cat_freq = tag_freq[tag]
24
+ related_scores[doc] += (1 + highest_freq - cat_freq)
25
+ end
26
+ end
27
+ end
28
+
29
+ sort_related_posts(related_scores)
30
+ end
31
+
32
+ private
33
+
34
+ # Calculate the frequency of each tag.
35
+ # Returns {tag => freq, tag => freq, ...}
36
+ def tag_freq
37
+ @tag_freq ||= docs.inject(Hash.new(0)) do |tag_freq, doc|
38
+ doc.data["tags"].each {|tag| tag_freq[tag] += 1 }
39
+ tag_freq
40
+ end
41
+ end
42
+
43
+ # Sort the related posts in order of their score and date
44
+ # and return just the posts
45
+ def sort_related_posts(related_scores)
46
+ related_scores.sort do |a, b|
47
+ if a[1] < b[1]
48
+ 1
49
+ elsif a[1] > b[1]
50
+ -1
51
+ else
52
+ b[0].date <=> a[0].date
53
+ end
54
+ end.collect {|post, freq| post}
55
+ end
56
+
57
+ def docs
58
+ @docs ||= site.posts.docs
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,7 @@
1
+ module Jekyll
2
+ module Tagging
3
+ module RelatedPosts
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-tagging-related_posts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - toshimaru
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jekyll-tagging
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Replaces Jekyll's related_posts function to use tags to calculate relationships
98
+ email:
99
+ - me@toshimaru.net
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/console
111
+ - bin/setup
112
+ - jekyll-tagging-related_posts.gemspec
113
+ - lib/jekyll-tagging-related_posts.rb
114
+ - lib/jekyll/tagging/related_posts.rb
115
+ - lib/jekyll/tagging/related_posts/version.rb
116
+ homepage: https://github.com/toshimaru/jekyll-tagging-related_posts
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.4.5
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Replaces Jekyll's related_posts function to use tags to calculate relationships
140
+ test_files: []