jekyll-post-tags 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 82dd827934df79ac51aef7b21aac284c6b25e53f
4
+ data.tar.gz: ed13ea925f73f25e96bb1c27f2010bbe4ea4a2ce
5
+ SHA512:
6
+ metadata.gz: dd010d97fbe32465b007517ac794b7a6e6ffe1eb208c1a80c0663c58ac7cf21ab5b5917fe8c778c67ae1961ccac1160bc19cb78f56e75c814f673e2e732e7407
7
+ data.tar.gz: b2b62853fa92a1c29663ff639976c17d9c36aca219a39d4ce0d5b0867acb0d6790620822b0de0a9f42017b2b9d7c9c184960d1d91da3cc4f2fc0502520179906
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ gem "rake"
5
+ gem "pry"
6
+
7
+ if ENV["JEKYLL_VERSION"]
8
+ # So we can test across all our supported.
9
+ gem "jekyll", "~> #{ENV["JEKYLL_VERSION"]}"
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015-2017 Jordon Bedwell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to
8
+ do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ <p align=center>
2
+ <a href=https://goo.gl/BhrgjW>
3
+ <img src=https://envygeeks.io/badges/paypal-large_1.png alt=Donate>
4
+ </a>
5
+ <br>
6
+ <a href=https://travis-ci.org/envygeeks/jekyll-post-tags>
7
+ <img src="https://travis-ci.org/envygeeks/jekyll-post-tags.svg?branch=master">
8
+ </a>
9
+ </div>
10
+
11
+ # Jekyll Post Tags
12
+
13
+ Jekyll post tags turns your Jekyll tags into drops without disrupting the way that Jekyll flows... or the way that you work with Jekyll's own tagging system. It also acts as a generator for tag pages, with custom templates (no defaults,) and custom pathing. It is different than other tagging platforms in that it works within what Jekyll already does and might not require you to change your code that much (if at all in some cases.)
14
+
15
+ ## Usage
16
+ #### From Within Your Templates
17
+ ##### All Tags
18
+ ```html
19
+ <ul class="tags">
20
+ {% for tag in site.tags %}
21
+ <li class="weight-{{ tag[0].weight | round }}">
22
+ <a title="Site Tag: {{ tag[0] }}" href="{{ tag[0].url | pretty }}">
23
+ {{ tag[0] }}
24
+ </a>
25
+ </li>
26
+ {% endfor %}
27
+ </ul>
28
+ ```
29
+
30
+ ##### Post Tags
31
+ ```html
32
+ <ul class="tags">
33
+ {% for tag in post.tags %}
34
+ <li class="weight-{{ tag.weight | round }}">
35
+ <a title="Site Tag: {{ tag }}" href="{{ tag.url | pretty }}">
36
+ {{ tag }}
37
+ </a>
38
+ </li>
39
+ {% endfor %}
40
+ </ul>
41
+ ```
@@ -0,0 +1,7 @@
1
+ # Frozen-String-Literal: true
2
+ # Copyright 2015 - 2017 Jordon Bedwell - MIT License
3
+ # Encoding: UTF-8
4
+
5
+ require "rspec/core/rake_task"
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => [:spec]
@@ -0,0 +1,5 @@
1
+ # Frozen-String-Literal: true
2
+ # Copyright 2015 - 2017 Jordon Bedwell - MIT License
3
+ # Encoding: UTF-8
4
+
5
+ require_relative "jekyll/post/tags"
@@ -0,0 +1,17 @@
1
+ # Frozen-String-Literal: true
2
+ # Copyright 2015 - 2017 Jordon Bedwell - MIT License
3
+ # Encoding: UTF-8
4
+
5
+ require "jekyll"
6
+
7
+ module Jekyll
8
+ module Post
9
+ module Tags
10
+ require_relative "tags/drop"
11
+ require_relative "tags/generator"
12
+ require_relative "tags/version"
13
+ require_relative "tags/page"
14
+ require_relative "tags/hook"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,58 @@
1
+ # Frozen-String-Literal: true
2
+ # Copyright 2016 - 2017 Jordon Bedwell - MIT License
3
+ # Encoding: UTF-8
4
+
5
+ require_relative "helpers"
6
+ require "liquid/drop/str"
7
+
8
+ module Jekyll
9
+ module Post
10
+ module Tags
11
+
12
+ # --
13
+ # @see https://github.com/envygeeks/liquid-string-drop
14
+ # Provides a string drop that we can wrap directly
15
+ # back into Jekyll without disrupting the ways users
16
+ # work, and without disrupting the way Jekyll currently
17
+ # works with it's own stuff.
18
+ # --
19
+ class Drop < Liquid::Drop::Str
20
+ attr_reader :weight, :site
21
+ extend Forwardable::Extended
22
+ rb_delegate :name, to: :@tag, alias_of: :to_s
23
+ include Helpers
24
+
25
+ # --
26
+ def initialize(tag, site:, weight: 1)
27
+ super(tag)
28
+
29
+ @site = site
30
+ @weight = weight
31
+ @tag = tag
32
+ end
33
+
34
+ # --
35
+ def url
36
+ File.join(*tag_path)
37
+ end
38
+
39
+ # --
40
+ # @return [[]] the tags.
41
+ # Loop through tags, set them up and then, pass
42
+ # them back out.
43
+ # --
44
+ def self.to_tags(site:)
45
+ div = 4.0 / site.tags.values.max_by(&:size).size
46
+ site.tags.each_with_object([]) do |(k, v), o|
47
+ weight = format("%.2f", div * v.size)
48
+
49
+ o << new(k, {
50
+ weight: weight.to_f,
51
+ site: site,
52
+ })
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,48 @@
1
+ # Frozen-String-Literal: true
2
+ # Copyright 2016 - 2017 Jordon Bedwell - MIT License
3
+ # Encoding: UTF-8
4
+
5
+ require "jekyll/generator"
6
+
7
+ module Jekyll
8
+ module Post
9
+ module Tags
10
+
11
+ # --
12
+ # @see https://github.com/jekyll/jekyll
13
+ # Generates the sites tags, using Jekyll's
14
+ # generators this is controlled by them and we don't
15
+ # really need to do that much after that.
16
+ #
17
+ # @example
18
+ # ```yaml
19
+ # # _config.yml
20
+ # tag_layout: custom_layout
21
+ # ```
22
+ # --
23
+ class Generator < Jekyll::Generator
24
+ def generate(site)
25
+ # @note this belongs in your `_config.yml`
26
+ key = (site.config["tag_layout"] || "default").chomp(".html")
27
+
28
+ if site.layouts.has_key?(key)
29
+ return site.tags.keys.each do |v|
30
+ tag = Doc.new(v, site: site)
31
+ tag.render(site.layouts, site.site_payload)
32
+ tag.write(site.dest)
33
+ site.pages << tag
34
+ end
35
+
36
+ # This error should be configurable or removed entirely
37
+ # because at the end of the day if there is no default.html
38
+ # or a specific tag layout, the user knows this...
39
+
40
+ else
41
+ Jekyll.logger.error "", "Could not find '#{key}.html' " \
42
+ "Skipping tags."
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,43 @@
1
+ # Frozen-String-Literal: true
2
+ # Copyright 2016 - 2017 Jordon Bedwell - MIT License
3
+ # Encoding: UTF-8
4
+
5
+ module Jekyll
6
+ module Post
7
+ module Tags
8
+ module Helpers
9
+
10
+ # --
11
+ # Provides the layout path.
12
+ # --
13
+ private
14
+ def tag_layout
15
+ return @tag_layout ||= begin
16
+ File.join("_layouts", (site.config["tag_layout"] \
17
+ ||= "default.html").gsub(/^_layouts\//, ""))
18
+ end
19
+ end
20
+
21
+ # --
22
+ # Provide the write path to the tag.
23
+ # @return [Array<Base,Path>]
24
+ # --
25
+ private
26
+ def tag_path
27
+ return @tag_path ||= begin
28
+ path = @site.config["tag_path"] || "/tag/:tag.html"
29
+ path = path.sub(":tag", @tag).split("/")
30
+ unless path.last =~ /\.html$/
31
+ path << "/index.html"
32
+ end
33
+
34
+ [
35
+ path[0...-1].join("/"),
36
+ path.last
37
+ ]
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ # Frozen-String-Literal: true
2
+ # Copyright 2016 - 2017 Jordon Bedwell - MIT License
3
+ # Encoding: UTF-8
4
+
5
+ Jekyll::Hooks.register :site, :pre_render, priority: 99 do |s, p|
6
+ tags = Jekyll::Post::Tags::Drop.to_tags(site: s)
7
+
8
+ s.posts.docs.each do |d|
9
+ d.data["tags"] = d.data["tags"].map do |t|
10
+ o = tags.find do |v|
11
+ v == t
12
+ end
13
+
14
+ o
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,69 @@
1
+ # Frozen-String-Literal: true
2
+ # Copyright 2015 - 2017 Jordon Bedwell - MIT License
3
+ # Encoding: UTF-8
4
+
5
+ require_relative "helpers"
6
+
7
+ module Jekyll
8
+ module Post
9
+ module Tags
10
+
11
+ # --
12
+ # Provides the base page for all tags that get built,
13
+ # this is mostly modeled after Jekyll's own pages, posts
14
+ # documents and otherwise.
15
+ # --
16
+ class Doc < Jekyll::Page
17
+ attr_accessor :site, :base, :tag, :dir, :name
18
+ include Helpers
19
+
20
+ # --
21
+ # Initialize a new instance.
22
+ # @return [Page]
23
+ # --
24
+ def initialize(tag, site:)
25
+ @site = site
26
+ @tag = tag
27
+ @base = site.source
28
+ @dir, @name = tag_path
29
+ process_tag_template
30
+ setup_defaults
31
+ end
32
+
33
+ # --
34
+ # Since this class is dynamic, and it's path being
35
+ # dynamic too, we provide a "realpath" method so that
36
+ # anything using Git, or otherwise can determine
37
+ # what the actual path is.
38
+ # @return [String]
39
+ # --
40
+ def realpath
41
+ @site.tags[@tag].sort_by { |v| v.data["date"] \
42
+ }.first.relative_path
43
+ end
44
+
45
+ # --
46
+ # Pull out the base data from within the layout.
47
+ # Most of the time this will simply just be empty.
48
+ # @return [Hash]
49
+ # --
50
+ private
51
+ def process_tag_template
52
+ read_yaml(@base, tag_layout)
53
+ process(@name)
54
+ end
55
+
56
+ # --
57
+ # Set the defaults.
58
+ # --
59
+ private
60
+ def setup_defaults
61
+ @data["type"] = "tag"
62
+ @data["description"] ||= "Post Tag: #{@tag}"
63
+ @data["title"] ||= "Post Tag: #{@tag}"
64
+ @data["tag"] = @tag
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,11 @@
1
+ # Frozen-String-Literal: true
2
+ # Copyright 2015 - 2017 Jordon Bedwell - MIT License
3
+ # Encoding: UTF-8
4
+
5
+ module Jekyll
6
+ module Post
7
+ module Tags
8
+ VERSION = "1.0.0"
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-post-tags
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jordon Bedwell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-12 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.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: luna-rspec-formatters
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: liquid-string-drop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ description: Reusable Post Tags for Jekyll
70
+ email:
71
+ - jordon@envygeeks.io
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - lib/jekyll-post-tags.rb
81
+ - lib/jekyll/post/tags.rb
82
+ - lib/jekyll/post/tags/drop.rb
83
+ - lib/jekyll/post/tags/generator.rb
84
+ - lib/jekyll/post/tags/helpers.rb
85
+ - lib/jekyll/post/tags/hook.rb
86
+ - lib/jekyll/post/tags/page.rb
87
+ - lib/jekyll/post/tags/version.rb
88
+ homepage: http://github.com/envygeeks/jekyll-post-tags
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.6.11
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Post Tags for Jekyll
112
+ test_files: []