jekyll-tagging-lite 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/ChangeLog +68 -0
  3. data/README.md +156 -0
  4. data/lib/jekyll-tagging-lite.rb +161 -0
  5. metadata +115 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eee9e18517125d735ea195534407713bbe049e9a27203ab919e010a20e7f7264
4
+ data.tar.gz: 650b205b1635ce740a4bece26d7eae1e2444dc89470f524023dbd6dcb1f4425c
5
+ SHA512:
6
+ metadata.gz: da25ba7d19c3a99381f66c115394c748b271972d546e976d308df4b3ad4339faee9a0f506765bd191c7faeab3bd449628be9a6513999cd77cbd74e2fa642d750
7
+ data.tar.gz: dd96501f2df68202fdee65f8f95d1f713092f4b0db977af15d69ccc05405268d31c5449407a1f3a3015dfb1ece831d4bb80a6c258e33c739de14a28023b74f38
data/ChangeLog ADDED
@@ -0,0 +1,68 @@
1
+ == 0.1.0 [2018-02-03]
2
+ * Fixed missing title (fabiomux)
3
+ * Added classifier (nidi3)
4
+ * Simplified specs
5
+ * Re-released as jekyll-tagging-lite
6
+
7
+ == 1.1.0 [2017-03-07]
8
+
9
+ * Added ability to append extra data to all tag pages. (tfe)
10
+ * Provides compatibility to the current jekyll (3.4.1).
11
+ * A few fixes. (felipe)
12
+ * Some documentation improvements. (wsmoak, jonathanpberger)
13
+ * Prooves who is the worst open source maintainer. (pattex ^__^)
14
+
15
+ == 1.0.1 [2015-06-11]
16
+
17
+ * Substitution of non ASCII characters and whitespaces, also when 'tag_permalink_style: pretty'.
18
+
19
+ == 1.0.0 [2015-06-10]
20
+
21
+ * Generate prettier urls for tag with whitespaces or non ASCII characters. ATTENTION: Your urls may change!
22
+ * Added support for site.config["baseurl"]. (Tsukasa ŌMOTO)
23
+ * Added trailing slashes to permalinks. (Pyry Kontio)
24
+
25
+ == 0.6.0 [2014-09-03]
26
+
27
+ * Pretty permalinks for tag pages. (Steve Valaitis)
28
+ * Added support for keywords (allenlsy)
29
+
30
+ == 0.5.0 [2013-06-06]
31
+
32
+ * Added rel="tag" to posts' tag links. (Brandon Hicks)
33
+ * Added support for ignored tags. (Zee Spencer)
34
+
35
+ == 0.4.0 [2012-10-22]
36
+
37
+ * Heavy refactoring to better support monkey patching.
38
+ * Fixed issue when a number is used as a tag. (Fabrice Rossi)
39
+
40
+ == 0.3.1 [2012-05-24]
41
+
42
+ * Added support for Jekyll::Site#add_payload (custom extension).
43
+
44
+ == 0.3.0 [2012-02-03]
45
+
46
+ * Feed per tag feature added.
47
+
48
+ == 0.2.0 [2011-03-10]
49
+
50
+ * Added support for pretty tag page URLs.
51
+ * Some bugs fixed.
52
+
53
+ == 0.1.2 [2011-01-31]
54
+
55
+ * Nothing to do when there are no tags.
56
+
57
+ == 0.1.1 [2010-11-26]
58
+
59
+ * Posts on tag pages are now sorted.
60
+
61
+ == 0.1.0 [2010-10-28]
62
+
63
+ * Added a <tt>tags</tt> filter.
64
+ * Ease customization by adding additional layers.
65
+
66
+ == 0.0.1 [2010-10-25]
67
+
68
+ * Here I am!
data/README.md ADDED
@@ -0,0 +1,156 @@
1
+ # jekyll-tagging-lite [![Gem Version](https://badge.fury.io/rb/jekyll-tagging-lite.svg)](https://badge.fury.io/rb/jekyll-tagging-lite)
2
+
3
+ Re-published to rubygems as `jekyll-tagging-lite` by @mehdisadeghi.
4
+
5
+ I have merged some waiting PRs and also made a change to cache the tag_cloud function's result which
6
+ signifcantly increases build time (from 12s down to 5s) on my [website](https://github.com/mehdisadeghi/mehdix.ir).
7
+
8
+ Moreover, I restructed the files so one can simple add `gem jekyll-tagging-lite` to Gemfile and is done. No need to
9
+ requiring `jekyll/tagging` (was annoying for me).
10
+
11
+ For the list of changes made to the upstream see the commit history.
12
+
13
+ The instructions below remain the same, except for the gem name and the requiring part.
14
+
15
+ # jekyll-tagging
16
+
17
+ By Arne Eilermann <mailto:arne@kleinerdrei.net> and Jens Wille <mailto:jens.wille@uni-koeln.de>
18
+
19
+ jekyll-tagging is a Jekyll plugin, to add a tag cloud and per tag pages plus feeds to your Jekyll generated Website.
20
+
21
+ ## Tags
22
+ This plugin does not reinvent Jekyll's tagging feature. It just makes it easy to use.
23
+ <https://jekyllrb.com/docs/frontmatter/>
24
+
25
+ Add space-delimited lowercase tags to FrontMatter, e.g.
26
+
27
+ ~~~~
28
+ author: Willow Rosenberg
29
+ tags: feminism anti-capitalism witchcraft
30
+ ~~~~
31
+
32
+ ## Usage
33
+
34
+ Install it:
35
+
36
+ gem install jekyll-tagging
37
+
38
+ Add this line to your Jekyll project's Gemfile:
39
+
40
+ group :jekyll_plugins do
41
+ gem "jekyll-tagging-lite"
42
+ end
43
+
44
+ And in your `_config.yml` you have to define your layout used to generate tag pages like:
45
+
46
+ tag_page_layout: tag_page
47
+ tag_page_dir: tag
48
+
49
+ This will look for `_layouts/tag_page.html`>, and use it to generate tag pages into the `_site/tag` directory.
50
+
51
+ Now you have a new filter called `tag_cloud` which you can use with the `site` 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 `tags` filter which you can feed with a `post` or a `page` object to get a link list of all its tags.
52
+
53
+ You can optionally define a per tag Atom/RSS feed. In your `_config.yml` define the following:
54
+
55
+ tag_feed_layout: tag_feed
56
+ tag_feed_dir: tag
57
+
58
+ (`tag_page_dir` and `tag_feed_dir` can have the same value.)
59
+
60
+ ### Pretty page links
61
+
62
+ If your Jekyll `permalink` configuration is set to something other than `:pretty`, and you still want to have pretty tag links define the following in your `_config.yml`:
63
+
64
+ tag_permalink_style: pretty
65
+
66
+ ### Ignoring tags
67
+
68
+ Sometimes you don't want tag pages generated for certain pages. That's ok! Just add `ignored_tags: [tags,to,ignore]` to your `_config.yml`
69
+
70
+ ### Extra data on tag pages
71
+
72
+ You can attach extra data to generated tag pages by specifying `tag_page_data` in `_config.yml` (this also works for `tag_feed_data`). For example, you might want to exclude tag pages from being picked up by `jekyll-sitemap`:
73
+
74
+ tag_page_data:
75
+ sitemap: false
76
+
77
+ ### Example tag page layout
78
+
79
+ (Save this to `_layouts/tag_page.html` if using the `_config.yml` snippet above.)
80
+
81
+ ~~~~
82
+ ---
83
+ layout: default
84
+ ---
85
+ <h2>{{ page.tag }}</h2>
86
+ <ul>
87
+ {% for post in page.posts %}
88
+ <li><a href#"{{ post.url }}">{{ post.title }}</a> ({{ post.date | date_to_string }} | Tags: {{ post | tags }})</li>
89
+ {% endfor %}
90
+ </ul>
91
+
92
+ <div id#"tag-cloud">
93
+ {{ site | tag_cloud }}
94
+ </div>
95
+ ~~~~
96
+
97
+ ### Example layout of an Atom feed
98
+
99
+ (Save this to `_layouts/tag_feed.xml` if using the `_config.yml` snippet above.)
100
+
101
+ ~~~~
102
+ ---
103
+ layout: nil
104
+ ---
105
+ <?xml version#"1.0" encoding#"utf-8"?>
106
+ <feed xmlns#"http://www.w3.org/2005/Atom">
107
+ <title>Your Title - {{ page.tag }}</title>
108
+ <link href#"http://example.com{{ page.url }}" rel#"self"/>
109
+ <link href#"http://example.com/tag/{{ page.tag }}.html"/>
110
+ <updated>{{ site.time | date_to_xmlschema }}</updated>
111
+ <id>http://example.com/tag/{{ page.tag }}.html</id>
112
+ <author>
113
+ <name>Author Here</name>
114
+ </author>
115
+ {% for post in page.posts %}
116
+ <entry>
117
+ <title>{{ post.title }}</title>
118
+ <link href#"http://example.com{{ post.url }}"/>
119
+ <updated>{{ post.date | date_to_xmlschema }}</updated>
120
+ <id>http://example.com{{ post.id }}</id>
121
+ <content type#"html">{{ post.content | xml_escape }}</content>
122
+ </entry>
123
+ {% endfor %}
124
+ </feed>
125
+ ~~~~
126
+
127
+ ## Links
128
+
129
+ Documentation:: <http://rubydoc.info/gems/jekyll-tagging/frames>
130
+ Source code:: <http://github.com/pattex/jekyll-tagging>
131
+ RubyGem:: <http://rubygems.org/gems/jekyll-tagging>
132
+
133
+ ## License
134
+
135
+ ### The MIT License
136
+
137
+ Copyright (c) 2010-2012 University of Cologne,
138
+ Albertus-Magnus-Platz, 50923 Cologne, Germany
139
+
140
+ Permission is hereby granted, free of charge, to any person obtaining a copy
141
+ of this software and associated documentation files (the "Software"), to deal
142
+ in the Software without restriction, including without limitation the rights
143
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
144
+ copies of the Software, and to permit persons to whom the Software is
145
+ furnished to do so, subject to the following conditions:
146
+
147
+ The above copyright notice and this permission notice shall be included in
148
+ all copies or substantial portions of the Software.
149
+
150
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
151
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
152
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
153
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
154
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
155
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
156
+ THE SOFTWARE.
@@ -0,0 +1,161 @@
1
+ require 'nuggets/range/quantile'
2
+ require 'nuggets/i18n'
3
+ require 'erb'
4
+
5
+
6
+ module Jekyll
7
+
8
+ module Helpers
9
+ # call-seq:
10
+ # jekyll_tagging_slug(str) => new_str
11
+ #
12
+ # Substitutes any diacritics in _str_ with their ASCII equivalents,
13
+ # whitespaces with dashes and converts _str_ to downcase.
14
+ def jekyll_tagging_slug(str)
15
+ str.to_s.replace_diacritics.downcase.gsub(/\s/, '-')
16
+ end
17
+ end
18
+
19
+ class Tagger < Generator
20
+ include Helpers
21
+
22
+ safe true
23
+
24
+ attr_accessor :site
25
+
26
+ @types = [:page, :feed]
27
+
28
+ class << self; attr_accessor :types, :site; end
29
+
30
+ @@classifiers = {
31
+ 'log' => proc{|classes, value, min, max|
32
+ scaled = (classes * (Math.log(value) - Math.log(min)) / (Math.log(max) - Math.log(min))).to_i
33
+ scaled == classes ? classes : scaled + 1},
34
+ 'linear' => proc{|classes, value, min, max| (1..max).quantile(value, classes)}
35
+ }
36
+
37
+ def generate(site)
38
+ self.class.site = self.site = site
39
+
40
+ generate_tag_pages
41
+ add_tag_cloud
42
+ end
43
+
44
+ private
45
+
46
+ # Generates a page per tag and adds them to all the pages of +site+.
47
+ # A <tt>tag_page_layout</tt> have to be defined in your <tt>_config.yml</tt>
48
+ # to use this.
49
+ def generate_tag_pages
50
+ active_tags.each { |tag, posts| new_tag(tag, posts) }
51
+ end
52
+
53
+ def new_tag(tag, posts)
54
+ self.class.types.each { |type|
55
+ if layout = site.config["tag_#{type}_layout"]
56
+ data = { 'layout' => layout, 'posts' => posts.sort.reverse!, 'tag' => tag }
57
+ data.merge!(site.config["tag_#{type}_data"] || {})
58
+
59
+ name = yield data if block_given?
60
+ name ||= tag
61
+ name = jekyll_tagging_slug(name)
62
+
63
+ tag_dir = site.config["tag_#{type}_dir"]
64
+ tag_dir = File.join(tag_dir, (pretty? ? name : ''))
65
+
66
+ page_name = "#{pretty? ? 'index' : name}#{site.layouts[data['layout']].ext}"
67
+
68
+ site.pages << TagPage.new(
69
+ site, site.source, tag_dir, page_name, data
70
+ )
71
+ end
72
+ }
73
+ end
74
+
75
+ def add_tag_cloud(num = 5, name = 'tag_data')
76
+ classifier = site.config['tag_classifier'] || 'linear'
77
+ s, t = site, { name => calculate_tag_cloud(@@classifiers[classifier].curry[num]) }
78
+ s.respond_to?(:add_payload) ? s.add_payload(t) : s.config.update(t)
79
+ end
80
+
81
+ # Calculates the css class of every tag for a tag cloud. The possible
82
+ # classes are: set-1..set-5.
83
+ #
84
+ # [[<TAG>, <CLASS>], ...]
85
+ def calculate_tag_cloud(classifier)
86
+ tags = active_tags.map { |tag, posts| [tag, posts.size] }
87
+ min, max = tags.map { |tag, size| size }.minmax
88
+ tags.sort!.map! { |tag, size| [tag, classifier.call(size, min, max)] }
89
+ end
90
+
91
+ def active_tags
92
+ threshold = (site.config["tag_threshold"] || '1').to_i
93
+ site.tags.reject { |tag, posts| (site.config["ignored_tags"] || "").include? tag or posts.size < threshold}
94
+ end
95
+
96
+ def pretty?
97
+ @pretty ||= (site.permalink_style == :pretty || site.config['tag_permalink_style'] == 'pretty')
98
+ end
99
+
100
+ end
101
+
102
+ class TagPage < Page
103
+
104
+ def initialize(site, base, dir, name, data = {})
105
+ self.content = data.delete('content') || ''
106
+ self.data = data
107
+
108
+ self.data['title'] = site.layouts[site.config['tag_page_layout']].data['title'] || site.config['tag_page_title'] || "Tag #{data['tag']}"
109
+
110
+ super(site, base, dir[-1, 1] == '/' ? dir : '/' + dir, name)
111
+ end
112
+
113
+ def read_yaml(*)
114
+ # Do nothing
115
+ end
116
+
117
+ end
118
+
119
+ module TaggingFilters
120
+ include Helpers
121
+ @@tag_cloud = nil
122
+
123
+ def tag_cloud(site)
124
+ @@tag_cloud ||= active_tag_data.map { |tag, set|
125
+ tag_link(tag, tag_url(tag), :class => "set-#{set}")
126
+ }.join(' ')
127
+ end
128
+
129
+ def tag_link(tag, url = tag_url(tag), html_opts = nil)
130
+ html_opts &&= ' ' << html_opts.map { |k, v| %Q{#{k}="#{v}"} }.join(' ')
131
+ %Q{<a href="#{url}"#{html_opts}>#{tag}</a>}
132
+ end
133
+
134
+ def tag_url(tag, type = :page, site = Tagger.site)
135
+ url = File.join('', site.config["baseurl"].to_s, site.config["tag_#{type}_dir"], ERB::Util.u(jekyll_tagging_slug(tag)))
136
+ site.permalink_style == :pretty || site.config['tag_permalink_style'] == 'pretty' ? url << '/' : url << '.html'
137
+ end
138
+
139
+ def tags(obj)
140
+ tags = obj['tags'].dup
141
+ tags.map! { |t| t.first } if tags.first.is_a?(Array)
142
+ tags.map! { |t| tag_link(t, tag_url(t), :rel => 'tag') if t.is_a?(String) }.compact!
143
+ tags.join(', ')
144
+ end
145
+
146
+ def keywords(obj)
147
+ return '' if not obj['tags']
148
+ tags = obj['tags'].dup
149
+ tags.join(',')
150
+ end
151
+
152
+ def active_tag_data(site = Tagger.site)
153
+ return site.config['tag_data'] unless site.config["ignored_tags"]
154
+ site.config["tag_data"].reject { |tag, set| site.config["ignored_tags"].include? tag }
155
+ end
156
+
157
+ end
158
+
159
+ end
160
+
161
+ Liquid::Template.register_filter(Jekyll::TaggingFilters)
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-tagging-lite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Arne Eilermann
8
+ - Jens Wille
9
+ - Mehdi Sadeghi
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2018-02-05 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nuggets
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: bundler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.16'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.16'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '10.0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '10.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '3.0'
71
+ description: Jekyll plugin to automatically generate a tag cloud and tag pages.
72
+ email:
73
+ - arne@kleinerdrei.net
74
+ - jens.wille@uni-koeln.de
75
+ - msk1361@gmail.com
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files:
79
+ - ChangeLog
80
+ files:
81
+ - ChangeLog
82
+ - README.md
83
+ - lib/jekyll-tagging-lite.rb
84
+ homepage: http://github.com/mehdisadeghi/jekyll-tagging-lite
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message: "\njekyll-tagging-lite [2018-03-05]:\n\n* This is jekyll-tagging
89
+ with some PRs merged and caching. \n\n"
90
+ rdoc_options:
91
+ - "--title"
92
+ - jekyll-tagging-lite docs
93
+ - "--line-numbers"
94
+ - "--all"
95
+ - "--main"
96
+ - ChangeLog
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.7.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Jekyll plugin to automatically generate a tag cloud and tag pages.
115
+ test_files: []