sutty-archives 2.4.1 → 2.5.4

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: 0d8ab803634bfa88c376d923c7a899074bbc92ae78bb61864e7ebc0defebbbf2
4
- data.tar.gz: 7c582de4ff9d9178c45590829d62ed2134785b26724442d2edeb51e7e5441f3a
3
+ metadata.gz: bb592daa06ca58bbf77f312f433ed257ccfe66dbb90e804534b3197ef568bd4e
4
+ data.tar.gz: 54fb504accc7dce42d17ed9705b7945fa60af35462c0bf720e1b23798bd35205
5
5
  SHA512:
6
- metadata.gz: 84275c56a027c307d3bcb8367e92ad8dabde13da114250d7f9dda90d5c62c1de3bec5da8a1da86e8555f1f61f58a6d6beffe179f0f62df444c86a86da04de79f
7
- data.tar.gz: e17da6c402e748a19083be9a0e38081897a037932b3b9c4aa8e985d801be0c8f0c0a124d5ccc217c1fbecaf18ed468ee6b06eacd366b822e09e5555b0fb9aa26
6
+ metadata.gz: a8039d82af08b99146d2e42e101a18e368d6cf685e1e1372d50356eb9e04bc2f65551c58da40414c169b1108f375a2f21d6a0ac45a279bf5960b6b961c21817e
7
+ data.tar.gz: 4d909fd87f301e7b901a0beb073eb8109aeaae0fb909474beaf1eb2c3dfaf312ede520044d70592b78332395480e85b3e977f9a94e65447c300aa4846f6ce399
@@ -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
@@ -100,15 +100,57 @@ module Jekyll
100
100
  end
101
101
  end
102
102
 
103
- def read_categories_tags
104
- @site.categories.each do |category, posts|
105
- posts.map { |post| post.data['tags'] }.flatten.uniq.compact.each do |tag|
106
- category_tag_posts = posts.select do |post|
107
- post.data['categories'].include?(category) &&
108
- 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?)
109
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
110
148
 
111
- @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
112
154
  end
113
155
  end
114
156
  end
@@ -132,6 +174,12 @@ module Jekyll
132
174
 
133
175
  @archives << Archive.new(@site, type, 'group', @site.config['archives'][type].map(&:posts).flatten.uniq)
134
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
135
183
  end
136
184
 
137
185
  # Return the front matter attributes to archive by, using the
@@ -153,6 +201,11 @@ module Jekyll
153
201
  @config['group']
154
202
  end
155
203
 
204
+ # Check if we have combined archives
205
+ def combined?
206
+ @config['combined'].is_a?(Hash)
207
+ end
208
+
156
209
  # Custom `post_attr_hash` method for years
157
210
  def years
158
211
  date_attr_hash(@posts.docs, "%Y")
@@ -40,10 +40,19 @@ module Jekyll
40
40
  @path = relative_path
41
41
  @name = File.basename(relative_path, @ext)
42
42
 
43
- @data = { "layout" => layout }
43
+ @data = { "layout" => layout, "title" => title }
44
+
45
+ if title.is_a?(Hash) && !date?
46
+ title['_layout'] = title.delete 'layout'
47
+ @data.merge! title
48
+ end
44
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.1"
5
+ VERSION = "2.5.4"
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.1
4
+ version: 2.5.4
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-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll