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 +4 -4
- data/lib/jekyll-archives.rb +61 -8
- data/lib/jekyll-archives/archive.rb +16 -6
- 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: bb592daa06ca58bbf77f312f433ed257ccfe66dbb90e804534b3197ef568bd4e
|
4
|
+
data.tar.gz: 54fb504accc7dce42d17ed9705b7945fa60af35462c0bf720e1b23798bd35205
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8039d82af08b99146d2e42e101a18e368d6cf685e1e1372d50356eb9e04bc2f65551c58da40414c169b1108f375a2f21d6a0ac45a279bf5960b6b961c21817e
|
7
|
+
data.tar.gz: 4d909fd87f301e7b901a0beb073eb8109aeaae0fb909474beaf1eb2c3dfaf312ede520044d70592b78332395480e85b3e977f9a94e65447c300aa4846f6ce399
|
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")
|
@@ -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
|
-
|
83
|
-
|
84
|
-
|
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
|
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'] &&
|
176
|
+
@config['replace'] && !@type.is_a?(Hash) && attribute != 'layout'
|
167
177
|
end
|
168
178
|
|
169
179
|
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
|
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:
|
12
|
+
date: 2021-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jekyll
|