sutty-archives 2.4.1 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-archives.rb +61 -8
- data/lib/jekyll-archives/archive.rb +9 -5
- data/lib/jekyll-archives/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3918e23c7f0f639664eed1261c58a5973db93970f24e1af22ec7d030cf1496b6
|
4
|
+
data.tar.gz: 4711190c26d0aa7f9faed300fac83a95f9539c32a688f7f80debbf5785c8a4fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b4afccab4860c41e8e8114384ab24c3f0046d0d26200a91f4525198e6e21e20c123585442377ac96fa78fc7bffc1f75c87be5a8158360a5bf129704865da592
|
7
|
+
data.tar.gz: b70a075de1cf8488000c3de90ec38ed3bb2c932bf62d49076a6aeec84fc150f4bdb648c2cd1e079b397263aec7185b3c327cd41f4c872e51698b182cbe8a11e1
|
data/lib/jekyll-archives.rb
CHANGED
@@ -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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
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")
|
@@ -42,6 +42,10 @@ 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 = ""
|
46
50
|
|
47
51
|
# Replace the value with the archive except for date and
|
@@ -79,9 +83,9 @@ module Jekyll
|
|
79
83
|
if @title.is_a? Hash
|
80
84
|
placeholders = @title.merge(:type => @type)
|
81
85
|
|
82
|
-
|
83
|
-
|
84
|
-
|
86
|
+
unless date?
|
87
|
+
placeholders.transform_values! do |v|
|
88
|
+
Utils.slugify(v, mode: @config.dig('slug'))
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
@@ -115,7 +119,7 @@ module Jekyll
|
|
115
119
|
def title
|
116
120
|
if @title.is_a? String
|
117
121
|
@config.dig('titles', @title) || @title
|
118
|
-
elsif
|
122
|
+
elsif !date?
|
119
123
|
@title.values.join(@config.fetch('separator', ' / '))
|
120
124
|
end
|
121
125
|
end
|
@@ -163,7 +167,7 @@ module Jekyll
|
|
163
167
|
private
|
164
168
|
|
165
169
|
def replace?
|
166
|
-
@config['replace'] &&
|
170
|
+
@config['replace'] && !@type.is_a?(Hash)
|
167
171
|
end
|
168
172
|
|
169
173
|
def attribute
|
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
|
+
version: 2.5.0
|
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-
|
12
|
+
date: 2020-10-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jekyll
|