jekyll-tagories 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4bbf2194099e21e2dc77a311012e932955d2830ea05cf94afc1ee9d45d489938
4
+ data.tar.gz: 140efd114dc36efff9be4eb1b89a9a4ff9b8f05ae00e3849a4a9e7e702d315ae
5
+ SHA512:
6
+ metadata.gz: 88ce830573812a8516d8e8bab5780138a17bcce71cb93f8b5153db86d8ca893a46d159a185f606f3a2002a0189dc94ca461f1668941e4d71c9fd239ea7aeaf9a
7
+ data.tar.gz: 6f11f4722c820093ce6e860033503ccf64226d7f63531dc96013d377f7e0b675daca0a5b70c1ba3f7724958ed36e233d023882739c7e743e820abd82663f3ae8
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) 2020 Ashwin Maroli
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.
@@ -0,0 +1,41 @@
1
+ # Jekyll Tagories
2
+
3
+ A Jekyll plugin that enhances `site.tags` and `site.categories` to include documents from user-defined collections and easily
4
+ *select* documents based on a given tag or category.
5
+
6
+ ## Installation
7
+
8
+ Add `jekyll-tagories` to your `Gemfile` and then run `bundle install` on your terminal. However, if your site doesn't have
9
+ a Gemfile, you may install it directly by running `gem install jekyll-tagories`.
10
+
11
+ ## Usage
12
+
13
+ To enable this plugin, add it to your configuration file before building your site:
14
+
15
+ ```yaml
16
+ plugins:
17
+ - jekyll-tagories
18
+ ```
19
+
20
+ Once enabled, `{{ site.tags }}` and `{{ site.categories }}` will include documents from your collections if they have been
21
+ tagged or categorized via their front matter.
22
+
23
+ *Note: The support for categories are limited to just the document's front matter and will not consider a document's
24
+ superdirectories as categories like your posts.*
25
+
26
+ ### Liquid filters
27
+
28
+ The plugin also exposes two Liquid filters to ease handling of the grouped pages and documents:
29
+
30
+ * **`tagged`** — retrieve documents that are tagged.
31
+ * **input:** an array of objects that have a `data` attribute.
32
+ * **optional parameter:** a single tag name
33
+ * **examples:**
34
+ * `{{ site.recipes | tagged }}`
35
+ * `{{ site.recipes | tagged: 'cake' }}`
36
+ * **`categorized`** — retrieve documents that are categorized.
37
+ * **input:** an array of objects that have a `data` attribute.
38
+ * **optional parameter:** a single category name
39
+ * **examples:**
40
+ * `{{ site.recipes | categorized }}`
41
+ * `{{ site.recipes | categorized: 'cakes' }}`
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "jekyll/tagories/site_xtension"
4
+ require_relative "jekyll/tagories/filters"
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Tagories
5
+ module LiquidFilters
6
+ def tagged(input, tag = nil)
7
+ return input unless input.is_a?(Array)
8
+
9
+ input.select do |item|
10
+ next false unless item.respond_to?(:data)
11
+ next false if item.data["tags"].empty?
12
+ next true if tag.nil?
13
+
14
+ item.data["tags"].include?(tag)
15
+ end
16
+ end
17
+
18
+ def categorized(input, category = nil)
19
+ return input unless input.is_a?(Array)
20
+
21
+ input.select do |item|
22
+ next false unless item.respond_to?(:data)
23
+ next false if item.data["categories"].empty?
24
+ next true if category.nil?
25
+
26
+ item.data["categories"].include?(category)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ Liquid::Template.register_filter(Jekyll::Tagories::LiquidFilters)
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Tagories
5
+ module SiteXtension
6
+ def tags
7
+ register_tags_and_categories unless @tags
8
+ @tags
9
+ end
10
+
11
+ def categories
12
+ register_tags_and_categories unless @categories
13
+ @categories
14
+ end
15
+
16
+ private
17
+
18
+ def register_tags_and_categories
19
+ @tags = {}
20
+ @categories = {}
21
+
22
+ documents.each do |doc|
23
+ next unless doc.is_a?(Jekyll::Document)
24
+
25
+ segregate_doc_by_attr_list(doc, doc.data["tags"], @tags)
26
+ segregate_doc_by_attr_list(doc, doc.data["categories"], @categories)
27
+ end
28
+ end
29
+
30
+ def segregate_doc_by_attr_list(doc, list, stash)
31
+ Array(list).each_with_object(stash) do |item, hash|
32
+ hash[item] ||= []
33
+ hash[item] << doc
34
+ end
35
+ end
36
+ end
37
+
38
+ Jekyll::Site.prepend(SiteXtension)
39
+ private_constant :SiteXtension
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-tagories
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ashwin Maroli
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-27 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.7'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.7'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: cucumber
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rubocop-jekyll
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.11.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.11.0
75
+ description: A Jekyll plugin that allows iterating through tagged or categorized documents
76
+ in user-defined collections
77
+ email:
78
+ - ashmaroli@gmail.com
79
+ executables: []
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - LICENSE
84
+ - README.md
85
+ - lib/jekyll-tagories.rb
86
+ - lib/jekyll/tagories/filters.rb
87
+ - lib/jekyll/tagories/site_xtension.rb
88
+ homepage: https://github.com/ashmaroli/jekyll-tagories
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: 2.4.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.0.6
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Jekyll plugin to allow iterating through tagged or categorized documents
111
+ test_files: []