sutty-archives 2.2.3 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb321000de02f19e06eeeb4c87cb3e631a5e587a8eaa1c8f8b1d1ca5f122035d
4
- data.tar.gz: 7c246d8580ac25397faf9408c70baebc7297deee7ad4c4e678d8c0e7de0012a5
3
+ metadata.gz: 413366df4f9c1af2ee08ab9917418ec8c7698584622beedada89b61bc6dc8caa
4
+ data.tar.gz: bc6943836ab1aef4d5863521affaea867fdc8b51acc68e80e0a3ae5a183b0cda
5
5
  SHA512:
6
- metadata.gz: c0aa4305061361e3aee1ed18a230f09f0dbea26458fbb97f98c72399afe29d4180e7ad51b688716824ae6f820464f49e34eb9d1810a5023a228840e611fed87d
7
- data.tar.gz: 8d2a98375dcb61f3af31fe0c6168366fa5525311f10ab07f6ec3926feb652c48a3750940d9b6c8937cf83add40145a0e97298fbb115264a834b927995fe8530b
6
+ metadata.gz: 75254b9af7f51d8871be7328b3b3ac7474b0f30525ae1c2d858819be7ef14b21b3b16789e95d8f27d4b72f33579d5ac65e46b0ef6516dd3a52b84b63088e06ee
7
+ data.tar.gz: cf09bcc54730dd7a1c3f4daf74ce1e3366a28eaea0241f7034acc1b1b31a06a27ddb94a7a2bbd59260349dd726ebee51f67ff3e9c468a589824de71c1702150c
@@ -18,8 +18,10 @@ module Jekyll
18
18
 
19
19
  DEFAULTS = {
20
20
  "layout" => "archive",
21
+ "group" => false,
21
22
  "enabled" => [],
22
23
  "titles" => {},
24
+ "replace" => false,
23
25
  "permalinks" => {
24
26
  "year" => "/:year/",
25
27
  "month" => "/:year/:month/",
@@ -55,14 +57,15 @@ module Jekyll
55
57
  read
56
58
  @site.pages.concat(@archives)
57
59
 
58
- @site.config["archives"] = @archives
60
+ @site.config["archives"] = @archives unless group?
59
61
  end
60
62
 
61
63
  # Read archive data from posts
62
64
  def read
65
+ read_combined if combined?
63
66
  read_attrs
64
- read_categories_tags
65
67
  read_dates
68
+ read_types if group?
66
69
  end
67
70
 
68
71
  # Read and group by attributes, using the legacy names when
@@ -75,6 +78,12 @@ module Jekyll
75
78
  next unless attr_title_enabled? attr, title
76
79
 
77
80
  @archives << Archive.new(@site, title, attr, posts)
81
+
82
+ next unless group?
83
+
84
+ @site.config['archives'] ||= {}
85
+ @site.config['archives'][attr] ||= []
86
+ @site.config['archives'][attr] << @archives.last
78
87
  end
79
88
  end
80
89
  end
@@ -91,17 +100,57 @@ module Jekyll
91
100
  end
92
101
  end
93
102
 
94
- def read_categories_tags
95
- if enabled? "categories-tags"
96
- @site.categories.each do |category, posts|
97
- posts.map { |post| post.data['tags'] }.flatten.uniq.compact.each do |tag|
98
- category_tag_posts = posts.select do |post|
99
- post.data['categories'].include?(category) &&
100
- post.data['tags'].include?(tag)
101
- end
102
-
103
- @archives << Archive.new(@site, { category: category, tag: tag }, "category-tag", category_tag_posts)
103
+ # Archive posts by a combination of attributes.
104
+ def read_combined
105
+ # We can have many combination archives
106
+ @config['combined'].each do |type, combined|
107
+ # This is an empty map so we can have all keys on the result
108
+ empty_combination = Hash[combined.map{|k| [k,nil]}]
109
+
110
+ # We collect all posts
111
+ @posts.docs.map do |post|
112
+ # Array of Jekyll::Document and Hash of values, some may be
113
+ # empty.
114
+ [ post, empty_combination.merge(**post.data.slice(*combined)) ]
115
+ end.select do |combination|
116
+ # We skip Documents that don't have any of the attributes
117
+ combination.last.none? do |_, e|
118
+ # TODO: Move to its own method
119
+ e.nil? || (e.respond_to?(:empty?) && e.empty?) || (e.respond_to?(:blank?) && e.blank?) || (e.respond_to?(:zero?) && e.zero?)
120
+ end
121
+ end.map do |post, data|
122
+ # Since the values can be Arrays, we'll generate all
123
+ # combinations
124
+ data.values.reduce do |memo, value|
125
+ # XXX: Ensure value is an Array, it could be a String or other
126
+ # value.
127
+ (memo.is_a?(Array) ? memo : [memo]).product([value].flatten)
128
+ end.map(&:flatten).map do |v|
129
+ # Recreate a Hash of attribute and single value for each
130
+ # combination
131
+ data.keys.zip(v)
132
+ end.map do |hash|
133
+ # Recreate the first collection of Document and Hash for
134
+ # each combination.
135
+ [ post, Hash[hash] ]
136
+ end
137
+ end.flatten(1).group_by(&:last).transform_values(&:flatten).transform_values do |v|
138
+ # Create groups by value combinations and select only
139
+ # Documents
140
+ v.select do |p|
141
+ p.is_a? Jekyll::Document
104
142
  end
143
+ end.each do |combination, posts|
144
+ # Then create Archives for them.
145
+ archive = Archive.new(@site, combination, type, posts)
146
+
147
+ @archives << archive
148
+
149
+ next unless group?
150
+
151
+ @site.config['archives'] ||= {}
152
+ @site.config['archives'][type] ||= []
153
+ @site.config['archives'][type] << archive
105
154
  end
106
155
  end
107
156
  end
@@ -118,6 +167,21 @@ module Jekyll
118
167
  end
119
168
  end
120
169
 
170
+ # Generates Archives by Archive type
171
+ def read_types
172
+ @config['enabled'].each do |type|
173
+ type = LEGACY_ATTRS[type] if LEGACY_ATTRS[type]
174
+
175
+ @archives << Archive.new(@site, type, 'group', @site.config['archives'][type].map(&:posts).flatten.uniq)
176
+ end
177
+
178
+ return unless combined?
179
+
180
+ @config['combined'].each do |type, _|
181
+ @archives << Archive.new(@site, type, 'group', @site.config['archives'][type].map(&:posts).flatten.uniq)
182
+ end
183
+ end
184
+
121
185
  # Return the front matter attributes to archive by, using the
122
186
  # legacy names unless specified and leaving out the date
123
187
  # attributes.
@@ -132,6 +196,16 @@ module Jekyll
132
196
  @enabled == true || @enabled == "all" || (@enabled.is_a?(Array) && @enabled.include?(archive))
133
197
  end
134
198
 
199
+ # Checks if we want grouped archives
200
+ def group?
201
+ @config['group']
202
+ end
203
+
204
+ # Check if we have combined archives
205
+ def combined?
206
+ @config['combined'].is_a?(Hash)
207
+ end
208
+
135
209
  # Custom `post_attr_hash` method for years
136
210
  def years
137
211
  date_attr_hash(@posts.docs, "%Y")
@@ -42,7 +42,26 @@ module Jekyll
42
42
 
43
43
  @data = { "layout" => layout }
44
44
 
45
+ if title.is_a?(Hash) && !date?
46
+ @data.merge! title
47
+ end
48
+
45
49
  @content = ""
50
+
51
+ data.default_proc = proc do |_, key|
52
+ site.frontmatter_defaults.find(relative_path, type, key)
53
+ end
54
+
55
+ # Replace the value with the archive except for date and
56
+ # category-tag. For category-tag, do we want to replace the
57
+ # category or the tag?
58
+ return unless replace?
59
+ @posts.each do |post|
60
+ case post.data[attribute]
61
+ when Array then post.data[attribute].map!{|v| (v == title) ? self : v }
62
+ else post.data[attribute] = self
63
+ end
64
+ end
46
65
  end
47
66
 
48
67
  # The template of the permalink.
@@ -68,9 +87,9 @@ module Jekyll
68
87
  if @title.is_a? Hash
69
88
  placeholders = @title.merge(:type => @type)
70
89
 
71
- if @type == 'category-tag'
72
- %i[category tag].each do |k|
73
- placeholders[k] = Utils.slugify(@title[k], mode: @config.dig('slug'))
90
+ unless date?
91
+ placeholders.transform_values! do |v|
92
+ Utils.slugify(v, mode: @config.dig('slug'))
74
93
  end
75
94
  end
76
95
 
@@ -104,7 +123,7 @@ module Jekyll
104
123
  def title
105
124
  if @title.is_a? String
106
125
  @config.dig('titles', @title) || @title
107
- elsif @type == 'category-tag'
126
+ elsif !date?
108
127
  @title.values.join(@config.fetch('separator', ' / '))
109
128
  end
110
129
  end
@@ -151,6 +170,18 @@ module Jekyll
151
170
 
152
171
  private
153
172
 
173
+ def replace?
174
+ @config['replace'] && !@type.is_a?(Hash)
175
+ end
176
+
177
+ def attribute
178
+ case type
179
+ when 'tag' then 'tags'
180
+ when 'category' then 'categories'
181
+ else type
182
+ end
183
+ end
184
+
154
185
  # Generate slug if @title attribute is a string.
155
186
  #
156
187
  # Note: mode other than those expected by Jekyll returns the given string after
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Archives
5
- VERSION = "2.2.3"
5
+ VERSION = "2.5.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sutty-archives
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alfred Xing
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-08-26 00:00:00.000000000 Z
12
+ date: 2020-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
- rubygems_version: 3.0.3
147
+ rubygems_version: 3.1.2
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: Post archives for Jekyll. Fork of jekyll-archives.