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 +4 -4
- data/lib/jekyll-archives.rb +86 -12
- data/lib/jekyll-archives/archive.rb +35 -4
- data/lib/jekyll-archives/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 413366df4f9c1af2ee08ab9917418ec8c7698584622beedada89b61bc6dc8caa
|
4
|
+
data.tar.gz: bc6943836ab1aef4d5863521affaea867fdc8b51acc68e80e0a3ae5a183b0cda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75254b9af7f51d8871be7328b3b3ac7474b0f30525ae1c2d858819be7ef14b21b3b16789e95d8f27d4b72f33579d5ac65e46b0ef6516dd3a52b84b63088e06ee
|
7
|
+
data.tar.gz: cf09bcc54730dd7a1c3f4daf74ce1e3366a28eaea0241f7034acc1b1b31a06a27ddb94a7a2bbd59260349dd726ebee51f67ff3e9c468a589824de71c1702150c
|
data/lib/jekyll-archives.rb
CHANGED
@@ -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
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
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
|
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
|
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.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-
|
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.
|
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.
|