sutty-archives 2.2.2 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jekyll-archives.rb +89 -14
- data/lib/jekyll-archives/archive.rb +35 -9
- 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: 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
@@ -18,15 +18,18 @@ module Jekyll
|
|
18
18
|
|
19
19
|
DEFAULTS = {
|
20
20
|
"layout" => "archive",
|
21
|
+
"group" => false,
|
21
22
|
"enabled" => [],
|
23
|
+
"titles" => {},
|
24
|
+
"replace" => false,
|
22
25
|
"permalinks" => {
|
23
26
|
"year" => "/:year/",
|
24
27
|
"month" => "/:year/:month/",
|
25
28
|
"day" => "/:year/:month/:day/",
|
26
29
|
"tag" => "/tag/:name/",
|
27
30
|
"category" => "/category/:name/",
|
28
|
-
"category-tag" => "/category/:category/tag/:tag/"
|
29
|
-
}
|
31
|
+
"category-tag" => "/category/:category/tag/:tag/",
|
32
|
+
}
|
30
33
|
}.freeze
|
31
34
|
|
32
35
|
def initialize(config = {})
|
@@ -54,14 +57,15 @@ module Jekyll
|
|
54
57
|
read
|
55
58
|
@site.pages.concat(@archives)
|
56
59
|
|
57
|
-
@site.config["archives"] = @archives
|
60
|
+
@site.config["archives"] = @archives unless group?
|
58
61
|
end
|
59
62
|
|
60
63
|
# Read archive data from posts
|
61
64
|
def read
|
65
|
+
read_combined if combined?
|
62
66
|
read_attrs
|
63
|
-
read_categories_tags
|
64
67
|
read_dates
|
68
|
+
read_types if group?
|
65
69
|
end
|
66
70
|
|
67
71
|
# Read and group by attributes, using the legacy names when
|
@@ -74,6 +78,12 @@ module Jekyll
|
|
74
78
|
next unless attr_title_enabled? attr, title
|
75
79
|
|
76
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
|
77
87
|
end
|
78
88
|
end
|
79
89
|
end
|
@@ -90,17 +100,57 @@ module Jekyll
|
|
90
100
|
end
|
91
101
|
end
|
92
102
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
103
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
|
104
154
|
end
|
105
155
|
end
|
106
156
|
end
|
@@ -117,6 +167,21 @@ module Jekyll
|
|
117
167
|
end
|
118
168
|
end
|
119
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
|
+
|
120
185
|
# Return the front matter attributes to archive by, using the
|
121
186
|
# legacy names unless specified and leaving out the date
|
122
187
|
# attributes.
|
@@ -131,6 +196,16 @@ module Jekyll
|
|
131
196
|
@enabled == true || @enabled == "all" || (@enabled.is_a?(Array) && @enabled.include?(archive))
|
132
197
|
end
|
133
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
|
+
|
134
209
|
# Custom `post_attr_hash` method for years
|
135
210
|
def years
|
136
211
|
date_attr_hash(@posts.docs, "%Y")
|
@@ -40,10 +40,24 @@ module Jekyll
|
|
40
40
|
@path = relative_path
|
41
41
|
@name = File.basename(relative_path, @ext)
|
42
42
|
|
43
|
-
@data = {
|
44
|
-
|
45
|
-
|
43
|
+
@data = { "layout" => layout }
|
44
|
+
|
45
|
+
if title.is_a?(Hash) && !date?
|
46
|
+
@data.merge! title
|
47
|
+
end
|
48
|
+
|
46
49
|
@content = ""
|
50
|
+
|
51
|
+
# Replace the value with the archive except for date and
|
52
|
+
# category-tag. For category-tag, do we want to replace the
|
53
|
+
# category or the tag?
|
54
|
+
return unless replace?
|
55
|
+
@posts.each do |post|
|
56
|
+
case post.data[attribute]
|
57
|
+
when Array then post.data[attribute].map!{|v| (v == title) ? self : v }
|
58
|
+
else post.data[attribute] = self
|
59
|
+
end
|
60
|
+
end
|
47
61
|
end
|
48
62
|
|
49
63
|
# The template of the permalink.
|
@@ -51,7 +65,7 @@ module Jekyll
|
|
51
65
|
# Returns the template String.
|
52
66
|
def template
|
53
67
|
t = @config.dig("permalinks", type)
|
54
|
-
t = t.is_a?(Hash) ? t[title] : t
|
68
|
+
t = t.is_a?(Hash) ? t[@title] : t
|
55
69
|
|
56
70
|
t || "/#{type}/:name/"
|
57
71
|
end
|
@@ -69,9 +83,9 @@ module Jekyll
|
|
69
83
|
if @title.is_a? Hash
|
70
84
|
placeholders = @title.merge(:type => @type)
|
71
85
|
|
72
|
-
|
73
|
-
|
74
|
-
|
86
|
+
unless date?
|
87
|
+
placeholders.transform_values! do |v|
|
88
|
+
Utils.slugify(v, mode: @config.dig('slug'))
|
75
89
|
end
|
76
90
|
end
|
77
91
|
|
@@ -104,8 +118,8 @@ module Jekyll
|
|
104
118
|
# date-based archives.
|
105
119
|
def title
|
106
120
|
if @title.is_a? String
|
107
|
-
@title
|
108
|
-
elsif
|
121
|
+
@config.dig('titles', @title) || @title
|
122
|
+
elsif !date?
|
109
123
|
@title.values.join(@config.fetch('separator', ' / '))
|
110
124
|
end
|
111
125
|
end
|
@@ -152,6 +166,18 @@ module Jekyll
|
|
152
166
|
|
153
167
|
private
|
154
168
|
|
169
|
+
def replace?
|
170
|
+
@config['replace'] && !@type.is_a?(Hash)
|
171
|
+
end
|
172
|
+
|
173
|
+
def attribute
|
174
|
+
case type
|
175
|
+
when 'tag' then 'tags'
|
176
|
+
when 'category' then 'categories'
|
177
|
+
else type
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
155
181
|
# Generate slug if @title attribute is a string.
|
156
182
|
#
|
157
183
|
# 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.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-
|
12
|
+
date: 2020-10-06 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.
|