sutty-archives 2.2.1 → 2.4.1

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: de531ca1b1088e2b311d795bb399e76d4d472c13b146b4c87d711d0ff7f30612
4
- data.tar.gz: 465b830b25c64e795503d591012e37268059265a1fb16b0d6d1d289fdf40dfae
3
+ metadata.gz: 0d8ab803634bfa88c376d923c7a899074bbc92ae78bb61864e7ebc0defebbbf2
4
+ data.tar.gz: 7c582de4ff9d9178c45590829d62ed2134785b26724442d2edeb51e7e5441f3a
5
5
  SHA512:
6
- metadata.gz: 4cd9ad72c38bf0a4fccad60781a6d2d161e42754d7e98262d15ca037e8c125ac3cfd3f312b2f58f52a0cb3b3e2a2a1f1cdfccf881180d9dd689238b154ec25ef
7
- data.tar.gz: 82dc16f23c07788f6c69e592e3045a3d49f03987a556694825b005a9c0e7b66d3e9a203eeb73baf2d70287ec69dc44097a82b600f004d993a282ebb6cb926a5b
6
+ metadata.gz: 84275c56a027c307d3bcb8367e92ad8dabde13da114250d7f9dda90d5c62c1de3bec5da8a1da86e8555f1f61f58a6d6beffe179f0f62df444c86a86da04de79f
7
+ data.tar.gz: e17da6c402e748a19083be9a0e38081897a037932b3b9c4aa8e985d801be0c8f0c0a124d5ccc217c1fbecaf18ed468ee6b06eacd366b822e09e5555b0fb9aa26
@@ -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
62
65
  read_attrs
63
- read_categories_tags
66
+ read_categories_tags if enabled? "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
@@ -71,22 +75,40 @@ module Jekyll
71
75
  post_attr_hash(attr).each do |title, posts|
72
76
  attr = LEGACY_ATTRS[attr] if LEGACY_ATTRS[attr]
73
77
 
78
+ next unless attr_title_enabled? attr, title
79
+
74
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
75
87
  end
76
88
  end
77
89
  end
78
90
 
91
+ # If the permalink is a hash of value => template, check if it
92
+ # isn't disabled.
93
+ def attr_title_enabled?(attr, value)
94
+ permalinks = @config.dig('permalinks', attr)
95
+
96
+ if permalinks.is_a?(Hash)
97
+ !!permalinks.dig(value)
98
+ else
99
+ true
100
+ end
101
+ end
102
+
79
103
  def read_categories_tags
80
- if enabled? "categories-tags"
81
- categories.each do |category, posts|
82
- posts.map { |post| post.data['tags'] }.flatten.uniq.compact.each do |tag|
83
- category_tag_posts = posts.select do |post|
84
- post.data['categories'].include?(category) &&
85
- post.data['tags'].include?(tag)
86
- end
87
-
88
- @archives << Archive.new(@site, { category: category, tag: tag }, "category-tag", category_tag_posts)
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)
89
109
  end
110
+
111
+ @archives << Archive.new(@site, { category: category, tag: tag }, "category-tag", category_tag_posts)
90
112
  end
91
113
  end
92
114
  end
@@ -103,6 +125,15 @@ module Jekyll
103
125
  end
104
126
  end
105
127
 
128
+ # Generates Archives by Archive type
129
+ def read_types
130
+ @config['enabled'].each do |type|
131
+ type = LEGACY_ATTRS[type] if LEGACY_ATTRS[type]
132
+
133
+ @archives << Archive.new(@site, type, 'group', @site.config['archives'][type].map(&:posts).flatten.uniq)
134
+ end
135
+ end
136
+
106
137
  # Return the front matter attributes to archive by, using the
107
138
  # legacy names unless specified and leaving out the date
108
139
  # attributes.
@@ -117,6 +148,11 @@ module Jekyll
117
148
  @enabled == true || @enabled == "all" || (@enabled.is_a?(Array) && @enabled.include?(archive))
118
149
  end
119
150
 
151
+ # Checks if we want grouped archives
152
+ def group?
153
+ @config['group']
154
+ end
155
+
120
156
  # Custom `post_attr_hash` method for years
121
157
  def years
122
158
  date_attr_hash(@posts.docs, "%Y")
@@ -40,17 +40,30 @@ module Jekyll
40
40
  @path = relative_path
41
41
  @name = File.basename(relative_path, @ext)
42
42
 
43
- @data = {
44
- "layout" => layout,
45
- }
43
+ @data = { "layout" => layout }
44
+
46
45
  @content = ""
46
+
47
+ # Replace the value with the archive except for date and
48
+ # category-tag. For category-tag, do we want to replace the
49
+ # category or the tag?
50
+ return unless replace?
51
+ @posts.each do |post|
52
+ case post.data[attribute]
53
+ when Array then post.data[attribute].map!{|v| (v == title) ? self : v }
54
+ else post.data[attribute] = self
55
+ end
56
+ end
47
57
  end
48
58
 
49
59
  # The template of the permalink.
50
60
  #
51
61
  # Returns the template String.
52
62
  def template
53
- @config.dig("permalinks", type) || "/#{type}/:name/"
63
+ t = @config.dig("permalinks", type)
64
+ t = t.is_a?(Hash) ? t[@title] : t
65
+
66
+ t || "/#{type}/:name/"
54
67
  end
55
68
 
56
69
  # The layout to use for rendering
@@ -101,7 +114,7 @@ module Jekyll
101
114
  # date-based archives.
102
115
  def title
103
116
  if @title.is_a? String
104
- @title
117
+ @config.dig('titles', @title) || @title
105
118
  elsif @type == 'category-tag'
106
119
  @title.values.join(@config.fetch('separator', ' / '))
107
120
  end
@@ -111,7 +124,7 @@ module Jekyll
111
124
  #
112
125
  # Returns a Date.
113
126
  def date
114
- return unless @title.is_a?(Hash)
127
+ return unless date?
115
128
 
116
129
  @date ||= begin
117
130
  args = @title.values.map(&:to_i)
@@ -143,8 +156,24 @@ module Jekyll
143
156
  "#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
144
157
  end
145
158
 
159
+ def date?
160
+ %w[year month day].include? @type
161
+ end
162
+
146
163
  private
147
164
 
165
+ def replace?
166
+ @config['replace'] && !(date? || @type == 'category-tag')
167
+ end
168
+
169
+ def attribute
170
+ case type
171
+ when 'tag' then 'tags'
172
+ when 'category' then 'categories'
173
+ else type
174
+ end
175
+ end
176
+
148
177
  # Generate slug if @title attribute is a string.
149
178
  #
150
179
  # Note: mode other than those expected by Jekyll returns the given string after
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Archives
5
- VERSION = "2.2.1"
5
+ VERSION = "2.4.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sutty-archives
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alfred Xing
8
8
  - f
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-10 00:00:00.000000000 Z
12
+ date: 2020-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll
@@ -116,7 +116,7 @@ dependencies:
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  description: Automatically generate post archives by dates, and any front matter attribute.
119
- email:
119
+ email:
120
120
  executables: []
121
121
  extensions: []
122
122
  extra_rdoc_files: []
@@ -129,7 +129,7 @@ homepage: https://0xacab.org/sutty/jekyll/sutty-archives
129
129
  licenses:
130
130
  - MIT
131
131
  metadata: {}
132
- post_install_message:
132
+ post_install_message:
133
133
  rdoc_options: []
134
134
  require_paths:
135
135
  - lib
@@ -144,8 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
- rubygems_version: 3.0.3
148
- signing_key:
147
+ rubygems_version: 3.1.2
148
+ signing_key:
149
149
  specification_version: 4
150
150
  summary: Post archives for Jekyll. Fork of jekyll-archives.
151
151
  test_files: []