sutty-archives 2.4.0 → 2.5.3

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: 4cc14da399823bcacdb254eb2a61dc1da3ef87787da6e7873ac2a119d2ce9eb1
4
- data.tar.gz: c36acd59da6ec7e2cf8ed837c4989371e3c6edf2a4b65a087ea211f3df59f4e6
3
+ metadata.gz: 89fc03fd9fff85a88a73cb5847f0e6427216b14f1c9af207254a560742e0b771
4
+ data.tar.gz: 2987fa0535baaea98ab919184b89e8d01c25796c1a45a4dffe4966126c61d163
5
5
  SHA512:
6
- metadata.gz: 0b8c2af7c4ba9b48932bccda9cc8bb47a560ed1d3c4d573d487a5444c26052fcb8340014ed766bdec9c2802627d5b2afd4c2a3472ec0b87a245e17a1be06cadd
7
- data.tar.gz: 51caab8fb1756dd2f77c752c36d2fe70ed14ce863932ac6a953c1ec26edaa0d862dca7d310aa7749fea198ed2e5319f0d9f4abd3c5a2019f76bc3a0aa123a485
6
+ metadata.gz: 192e025c68cf91285f43e4ddb95c9f4552200e7472a1e1585b9275c9b1e4b8f0ee8b933381c4a6f1c0c93b138930034642625a8ce79b23f1c9fba9237230d64f
7
+ data.tar.gz: c0b46364fc8bd7e406ad218c4d6296774e5a62d278f131e8c033fb6dff996d03aa9fad6911d0d521d4cf9518974ba675b073e9f97acbfe21ca7f86605ea3ee5c
@@ -62,8 +62,8 @@ module Jekyll
62
62
 
63
63
  # Read archive data from posts
64
64
  def read
65
+ read_combined if combined?
65
66
  read_attrs
66
- read_categories_tags if enabled? "categories-tags"
67
67
  read_dates
68
68
  read_types if group?
69
69
  end
@@ -82,7 +82,8 @@ module Jekyll
82
82
  next unless group?
83
83
 
84
84
  @site.config['archives'] ||= {}
85
- @site.config['archives'][attr] = @archives.last
85
+ @site.config['archives'][attr] ||= []
86
+ @site.config['archives'][attr] << @archives.last
86
87
  end
87
88
  end
88
89
  end
@@ -99,15 +100,57 @@ module Jekyll
99
100
  end
100
101
  end
101
102
 
102
- def read_categories_tags
103
- @site.categories.each do |category, posts|
104
- posts.map { |post| post.data['tags'] }.flatten.uniq.compact.each do |tag|
105
- category_tag_posts = posts.select do |post|
106
- post.data['categories'].include?(category) &&
107
- post.data['tags'].include?(tag)
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?)
108
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
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
109
148
 
110
- @archives << Archive.new(@site, { category: category, tag: tag }, "category-tag", category_tag_posts)
149
+ next unless group?
150
+
151
+ @site.config['archives'] ||= {}
152
+ @site.config['archives'][type] ||= []
153
+ @site.config['archives'][type] << archive
111
154
  end
112
155
  end
113
156
  end
@@ -129,7 +172,13 @@ module Jekyll
129
172
  @config['enabled'].each do |type|
130
173
  type = LEGACY_ATTRS[type] if LEGACY_ATTRS[type]
131
174
 
132
- @archives << Archive.new(@site, type, 'type', @archives[type].posts)
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)
133
182
  end
134
183
  end
135
184
 
@@ -152,6 +201,11 @@ module Jekyll
152
201
  @config['group']
153
202
  end
154
203
 
204
+ # Check if we have combined archives
205
+ def combined?
206
+ @config['combined'].is_a?(Hash)
207
+ end
208
+
155
209
  # Custom `post_attr_hash` method for years
156
210
  def years
157
211
  date_attr_hash(@posts.docs, "%Y")
@@ -42,8 +42,17 @@ module Jekyll
42
42
 
43
43
  @data = { "layout" => layout }
44
44
 
45
+ if title.is_a?(Hash) && !date?
46
+ title['_layout'] = title.delete 'layout'
47
+ @data.merge! title
48
+ end
49
+
45
50
  @content = ""
46
51
 
52
+ data.default_proc = proc do |_, key|
53
+ site.frontmatter_defaults.find(relative_path, type, key)
54
+ end
55
+
47
56
  # Replace the value with the archive except for date and
48
57
  # category-tag. For category-tag, do we want to replace the
49
58
  # category or the tag?
@@ -79,9 +88,9 @@ module Jekyll
79
88
  if @title.is_a? Hash
80
89
  placeholders = @title.merge(:type => @type)
81
90
 
82
- if @type == 'category-tag'
83
- %i[category tag].each do |k|
84
- placeholders[k] = Utils.slugify(@title[k], mode: @config.dig('slug'))
91
+ unless date?
92
+ placeholders.transform_values! do |v|
93
+ Utils.slugify(v, mode: @config.dig('slug'))
85
94
  end
86
95
  end
87
96
 
@@ -115,7 +124,7 @@ module Jekyll
115
124
  def title
116
125
  if @title.is_a? String
117
126
  @config.dig('titles', @title) || @title
118
- elsif @type == 'category-tag'
127
+ elsif !date?
119
128
  @title.values.join(@config.fetch('separator', ' / '))
120
129
  end
121
130
  end
@@ -162,8 +171,9 @@ module Jekyll
162
171
 
163
172
  private
164
173
 
174
+ # Layout is a special attribute that can't be replaced
165
175
  def replace?
166
- @config['replace'] && !(date? || @type == 'category-tag')
176
+ @config['replace'] && !@type.is_a?(Hash) && attribute != 'layout'
167
177
  end
168
178
 
169
179
  def attribute
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Archives
5
- VERSION = "2.4.0"
5
+ VERSION = "2.5.3"
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.4.0
4
+ version: 2.5.3
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-10-02 00:00:00.000000000 Z
12
+ date: 2021-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll