jekyll_all_collections 0.3.2 → 0.3.4
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/.rubocop.yml +20 -13
- data/CHANGELOG.md +35 -9
- data/README.md +151 -83
- data/Rakefile +2 -2
- data/jekyll_all_collections.gemspec +5 -5
- data/lib/all_collections_hooks.rb +13 -10
- data/lib/all_collections_tag.rb +45 -31
- data/lib/jekyll_all_collections/version.rb +1 -1
- data/lib/jekyll_all_collections.rb +2 -2
- data/spec/{all_collections_tag_sort_spec.rb → all_collections_tag/all_collections_tag_sort_spec.rb} +13 -19
- data/spec/spec_helper.rb +1 -2
- data/spec/status_persistence.txt +23 -20
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48527cdeb305237310b14a6748a3a95aab2fea5a837a650d277a8d9c93daed97
|
4
|
+
data.tar.gz: 98b3eebd250c4d16e2141b9aaac2c211a54ff9478eafe4a5cbb68f7de905cc6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ebd2507129ca1d62ca6fba8bbeb3bce545c100093ed1bab1390f03c5d495b7dd51fcb0780e8438253fcbf87a74cb57f54034b526fe54d290338f3b732b325c1
|
7
|
+
data.tar.gz: 30b284bb7cb19a4ef0cb246c052e2818086343fc722e4713065c4b9f5cb9a0fd0d807d0df1d7a5e16cb0cf08993ed56ddad3bd006f93175393b27d81305740a9
|
data/.rubocop.yml
CHANGED
@@ -7,11 +7,11 @@ require:
|
|
7
7
|
|
8
8
|
AllCops:
|
9
9
|
Exclude:
|
10
|
-
-
|
10
|
+
- binstub/**/*
|
11
|
+
- demo/_site/*
|
11
12
|
- vendor/**/*
|
12
13
|
- Gemfile*
|
13
14
|
NewCops: enable
|
14
|
-
TargetRubyVersion: 2.6
|
15
15
|
|
16
16
|
Gemspec/DeprecatedAttributeAssignment:
|
17
17
|
Enabled: false
|
@@ -19,6 +19,9 @@ Gemspec/DeprecatedAttributeAssignment:
|
|
19
19
|
Gemspec/RequireMFA:
|
20
20
|
Enabled: false
|
21
21
|
|
22
|
+
Gemspec/RequiredRubyVersion:
|
23
|
+
Enabled: false
|
24
|
+
|
22
25
|
Layout/HashAlignment:
|
23
26
|
EnforcedColonStyle: table
|
24
27
|
EnforcedHashRocketStyle: table
|
@@ -27,7 +30,7 @@ Layout/LineLength:
|
|
27
30
|
Max: 150
|
28
31
|
|
29
32
|
Metrics/AbcSize:
|
30
|
-
Max:
|
33
|
+
Max: 45
|
31
34
|
|
32
35
|
Metrics/BlockLength:
|
33
36
|
Exclude:
|
@@ -47,21 +50,25 @@ Naming/FileName:
|
|
47
50
|
Exclude:
|
48
51
|
- Rakefile
|
49
52
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
Style/FrozenStringLiteralComment:
|
54
|
-
Enabled: false
|
55
|
-
|
56
|
-
Style/TrailingCommaInHashLiteral:
|
57
|
-
EnforcedStyleForMultiline: comma
|
53
|
+
RSpec/ExampleLength:
|
54
|
+
Max: 30
|
58
55
|
|
59
56
|
RSpec/FilePath:
|
57
|
+
Enabled: false
|
60
58
|
IgnoreMethods: true
|
61
59
|
SpecSuffixOnly: true
|
62
60
|
|
63
|
-
RSpec/
|
64
|
-
|
61
|
+
RSpec/IndexedLet:
|
62
|
+
Enabled: false
|
65
63
|
|
66
64
|
RSpec/MultipleExpectations:
|
67
65
|
Max: 15
|
66
|
+
|
67
|
+
Style/Documentation:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
Style/FrozenStringLiteralComment:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Style/TrailingCommaInHashLiteral:
|
74
|
+
EnforcedStyleForMultiline: comma
|
data/CHANGELOG.md
CHANGED
@@ -1,25 +1,51 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.3.4 / 2023-12-24
|
4
|
+
|
5
|
+
* Changed dependency to Jekyll >= 4.3.2
|
6
|
+
|
7
|
+
|
8
|
+
## 0.3.3 / 2023-05-22
|
9
|
+
|
10
|
+
* Corrected key presence checks in APage.initialize
|
11
|
+
* Using `warn_short_trace` from `jekyll_plugin_support` for non-fatal errors.
|
12
|
+
|
13
|
+
|
1
14
|
## 0.3.2 / 2023-04-05
|
2
|
-
|
15
|
+
|
16
|
+
* Modified dependency `'jekyll_plugin_support', '>= 0.5.0'`
|
17
|
+
|
3
18
|
|
4
19
|
## 0.3.1 / 2023-03-16
|
5
|
-
|
20
|
+
|
21
|
+
* Reduced the verbosity of the `@logger` message
|
6
22
|
|
7
23
|
## 0.3.0 / 2023-02-16
|
8
|
-
|
24
|
+
|
25
|
+
* Updated dependency `'jekyll_plugin_support', '~> 0.5.0'`
|
9
26
|
|
10
27
|
## 0.2.2 / 2023-02-12
|
11
|
-
|
28
|
+
|
29
|
+
* Updated dependency `'jekyll_plugin_support', '~> 0.4.0'`
|
30
|
+
|
12
31
|
|
13
32
|
## 0.2.1 / 2023-02-12
|
14
|
-
|
33
|
+
|
34
|
+
* Reduced the verbosity of log output from `info` to `debug`
|
35
|
+
|
15
36
|
|
16
37
|
## 0.2.0 / 2023-02-04
|
17
|
-
|
18
|
-
|
38
|
+
|
39
|
+
* Returns Array[APage] instead of a collection of different types of objects.
|
40
|
+
* Converted the plugin to a `:site, :post_read` hook instead of a tag,
|
19
41
|
so explicit initialization is no longer required.
|
20
42
|
|
43
|
+
|
21
44
|
## 0.1.1 / 2022-04-27
|
22
|
-
|
45
|
+
|
46
|
+
* Changed invocation from a `:site` hook to an idempotent method invocation.
|
47
|
+
|
23
48
|
|
24
49
|
## 0.1.0 / 2022-04-26
|
25
|
-
|
50
|
+
|
51
|
+
* Initial version published
|
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
`jekyll_all_collections`
|
2
|
-
|
3
|
-
===========
|
1
|
+
# `jekyll_all_collections` [](https://badge.fury.io/rb/jekyll_all_collections)
|
2
|
+
|
4
3
|
|
5
4
|
`Jekyll_all_collections` is a Jekyll plugin that adds a new property called `all_collections` to `site`.
|
6
5
|
It also provides a new Jekyll tag called `all_collections`,
|
@@ -15,39 +14,68 @@ The collection consists of an array of objects with the following properties:
|
|
15
14
|
Pages that are not in any collection are not included.
|
16
15
|
|
17
16
|
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
group :jekyll_plugins do
|
23
|
+
gem 'jekyll_all_collections'
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
```shell
|
30
|
+
$ bundle
|
31
|
+
```
|
32
|
+
|
33
|
+
|
18
34
|
## Requirements
|
19
|
-
|
35
|
+
|
36
|
+
All the pages in the Jekyll website must have an implicit date
|
37
|
+
(for example, all posts are assigned this property by Jekyll),
|
20
38
|
or an explicit `date` set in front matter, like this:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
|
40
|
+
```html
|
41
|
+
---
|
42
|
+
date: 2022-01-01
|
43
|
+
---
|
44
|
+
```
|
45
|
+
|
46
|
+
If a front matter variable called `last_modified` or `last_modified_at` exists,
|
47
|
+
its value will be converted to a Ruby `Date`:
|
48
|
+
|
49
|
+
```html
|
50
|
+
---
|
51
|
+
last_modified: 2023-01-01
|
52
|
+
---
|
53
|
+
```
|
54
|
+
|
55
|
+
Or:
|
56
|
+
|
57
|
+
```html
|
58
|
+
---
|
59
|
+
last_modified_at: 2023-01-01
|
60
|
+
---
|
61
|
+
```
|
62
|
+
|
63
|
+
Otherwise, if `last_modified` or `last_modified_at` is not present in the front matter for a page,
|
64
|
+
the `date` value will be used last modified date value.
|
65
|
+
|
41
66
|
|
42
67
|
## Usage
|
43
68
|
|
44
69
|
### `Site.all_collections`
|
70
|
+
|
45
71
|
No explicit initialization or setup is required.
|
46
72
|
Jekyll plugins can access the value of `site.all_collections`, however Liquid code in Jekyll pages and documents cannot.
|
47
73
|
|
48
74
|
|
49
75
|
### `All_collections` Tag
|
76
|
+
|
50
77
|
Add the following CSS to your stylesheet:
|
78
|
+
|
51
79
|
```css
|
52
80
|
.posts {
|
53
81
|
display: flex;
|
@@ -68,70 +96,110 @@ Add the following CSS to your stylesheet:
|
|
68
96
|
}
|
69
97
|
```
|
70
98
|
|
99
|
+
|
71
100
|
#### Excluding Pages
|
72
|
-
|
73
|
-
|
101
|
+
|
102
|
+
Adding the following entry to a page’s front matter causes that page to be excluded
|
103
|
+
from the collection created by this plugin:
|
104
|
+
|
105
|
+
```html
|
74
106
|
---
|
75
107
|
exclude_from_all: true
|
76
108
|
---
|
77
109
|
```
|
78
110
|
|
111
|
+
|
79
112
|
#### General Form
|
113
|
+
|
80
114
|
The general form of the Jekyll tag is:
|
115
|
+
|
116
|
+
```html
|
117
|
+
{% all_collections
|
118
|
+
date_column='date|last_modified'
|
119
|
+
heading='All Posts'
|
120
|
+
id='asdf'
|
121
|
+
sort_by='SORT_KEYS'
|
122
|
+
%}
|
81
123
|
```
|
82
|
-
|
83
|
-
```
|
124
|
+
|
84
125
|
|
85
126
|
#### `date_column` Attribute
|
127
|
+
|
86
128
|
One of two date columns can be displayed in the generated HTML:
|
87
129
|
either `date` (when the article was originally written),
|
88
130
|
or `last_modified`.
|
89
131
|
The default value for the `date_column` attribute is `date`.
|
90
132
|
|
91
133
|
|
92
|
-
#### `
|
93
|
-
If your Jekyll layout employs [`jekyll-toc`](https://github.com/allejo/jekyll-toc), then `id` attributes are important.
|
94
|
-
The `jekyll-toc` include checks for `id` attributes in `h2` ... `h6` tags, and if found, and if the attribute value is enclosed in double quotes (`id="my_id"`, not `id='my_id'`),
|
95
|
-
then the heading is included in the table of contents.
|
96
|
-
|
97
|
-
To suppress an `id` from being generated,
|
98
|
-
and thereby preventing the heading from appearing in the automatically generated table of contents from `jekyll-toc`,
|
99
|
-
specify an empty string for the value of `id`, like this:
|
100
|
-
```
|
101
|
-
{% all_collections id='' %}
|
102
|
-
```
|
134
|
+
#### `heading` Attribute
|
103
135
|
|
136
|
+
If no `heading` attribute is specified, a heading will automatically be generated, which contains the `sort_by` values,
|
137
|
+
for example:
|
104
138
|
|
105
|
-
|
106
|
-
If no `heading` attribute is specified, a heading will automatically be generated, which contains the `sort_by` values, for example:
|
107
|
-
```
|
139
|
+
```html
|
108
140
|
{% all_collections id='abcdef' sort_by="last_modified" %}
|
109
141
|
```
|
142
|
+
|
110
143
|
Generates a heading like:
|
111
|
-
|
112
|
-
|
144
|
+
|
145
|
+
```html
|
146
|
+
<h2 id="abcdef">All Posts Sorted By last_modified</h2>
|
113
147
|
```
|
114
148
|
|
115
149
|
To suppress both a `h2` heading (and the enclosed `id`) from being generated,
|
116
150
|
specify an empty string for the value of `heading`:
|
117
|
-
|
151
|
+
|
152
|
+
```html
|
118
153
|
{% all_collections heading='' %}
|
119
154
|
```
|
120
155
|
|
121
156
|
|
157
|
+
#### `id` Attribute
|
158
|
+
|
159
|
+
If your Jekyll layout employs [`jekyll-toc`](https://github.com/allejo/jekyll-toc), then `id` attributes are important.
|
160
|
+
The `jekyll-toc` include checks for `id` attributes in `h2` ... `h6` tags, and if found,
|
161
|
+
and if the attribute value is enclosed in double quotes (`id="my_id"`, not `id='my_id'`),
|
162
|
+
then the heading is included in the table of contents.
|
163
|
+
|
164
|
+
To suppress an `id` from being generated,
|
165
|
+
and thereby preventing the heading from appearing in the automatically generated table of contents from `jekyll-toc`,
|
166
|
+
specify an empty string for the value of `id`, like this:
|
167
|
+
|
168
|
+
```html
|
169
|
+
{% all_collections id='' %}
|
170
|
+
```
|
171
|
+
|
172
|
+
|
122
173
|
#### `SORT_KEYS` Values
|
174
|
+
|
123
175
|
`SORT_KEYS` specifies how to sort the collection.
|
124
176
|
Values can include one or more of the following attributes:
|
125
|
-
`date`, `destination`, `draft`, `label`, `last_modified`, `
|
177
|
+
`date`, `destination`, `draft`, `label`, `last_modified`, `last_modified_at`, `path`, `relative_path`,
|
178
|
+
`title`, `type`, and `url`.
|
126
179
|
Ascending sorts are the default, however a descending sort can be achieved by prepending `-` before an attribute.
|
127
180
|
|
128
|
-
To specify more than one sort key, provide
|
181
|
+
To specify more than one sort key, provide a comma-delimited string of values.
|
182
|
+
Included spaces are ignored.
|
183
|
+
For example, specify the primary sort key as `draft`,
|
184
|
+
the secondary sort key as `last_modified`,
|
185
|
+
and the tertiary key as `label`:
|
186
|
+
|
187
|
+
```html
|
188
|
+
{% all_collections
|
189
|
+
date_column='last_modified'
|
190
|
+
heading='All Posts'
|
191
|
+
id='asdf'
|
192
|
+
sort_by='draft, last_modified, label'
|
193
|
+
%}
|
194
|
+
```
|
129
195
|
|
130
196
|
|
131
197
|
#### Usage Examples
|
198
|
+
|
132
199
|
Here is a short Jekyll page, including front matter,
|
133
200
|
demonstrating this plugin being invoked with all default attribute values:
|
134
|
-
|
201
|
+
|
202
|
+
```html
|
135
203
|
---
|
136
204
|
description: "
|
137
205
|
Dump of all collections, sorted by date originally written, newest to oldest.
|
@@ -145,51 +213,62 @@ title: Testing, 1, 2, 3
|
|
145
213
|
|
146
214
|
Explicitly express the default sort
|
147
215
|
(sort by the date originally written, newest to oldest):
|
148
|
-
|
216
|
+
|
217
|
+
```html
|
149
218
|
{% all_collections sort_by="-date" %}
|
150
219
|
```
|
151
220
|
|
152
221
|
Sort by date, from oldest to newest:
|
153
|
-
|
222
|
+
|
223
|
+
```html
|
154
224
|
{% all_collections sort_by="date" %}
|
155
225
|
```
|
156
226
|
|
157
227
|
Sort by the date last modified, oldest to newest:
|
158
|
-
|
228
|
+
|
229
|
+
```html
|
159
230
|
{% all_collections sort_by="last_modified" %}
|
160
231
|
```
|
161
232
|
|
162
233
|
Sort by the date last modified, newest to oldest:
|
163
|
-
|
234
|
+
|
235
|
+
```html
|
164
236
|
{% all_collections sort_by="-last_modified" %}
|
165
237
|
```
|
166
238
|
|
167
239
|
Several attributes can be specified as sort criteria by passing them as a comma-delimited string.
|
168
240
|
Included spaces are ignored:
|
169
|
-
|
241
|
+
|
242
|
+
```html
|
170
243
|
{% all_collections sort_by="-last_modified, -date" %}
|
171
244
|
{% all_collections sort_by="-last_modified, title" %}
|
172
245
|
{% all_collections sort_by="-last_modified, -date, title" %}
|
173
246
|
```
|
174
247
|
|
175
248
|
The following two examples produce the same output:
|
176
|
-
|
249
|
+
|
250
|
+
```html
|
177
251
|
{% all_collections sort_by="-last_modified,-date" %}
|
178
252
|
{% all_collections sort_by="-last_modified, -date" %}
|
179
253
|
```
|
180
254
|
|
181
255
|
|
182
256
|
## Demo
|
257
|
+
|
183
258
|
The [`demo`](./demo) directory contains a demonstration website, which uses the plugin.
|
184
259
|
To run, type:
|
260
|
+
|
185
261
|
```console
|
186
262
|
$ demo/_bin/debug -r
|
187
263
|
```
|
264
|
+
|
188
265
|
Now point your web browser to http://localhost:4444
|
189
266
|
|
190
267
|
|
191
268
|
## Debugging
|
269
|
+
|
192
270
|
You can control the verbosity of log output by adding the following to `_config.yml` in your Jekyll project:
|
271
|
+
|
193
272
|
```yaml
|
194
273
|
plugin_loggers:
|
195
274
|
AllCollectionsTag::AllCollectionsTag: warn
|
@@ -199,7 +278,8 @@ plugin_loggers:
|
|
199
278
|
1. You have two options for initiating a debug session:
|
200
279
|
|
201
280
|
1. Run `demo/_bin/debug`, without the `-r` options shown above.
|
202
|
-
|
281
|
+
|
282
|
+
```console
|
203
283
|
... lots of output as bundle update runs...
|
204
284
|
Bundle updated!
|
205
285
|
|
@@ -216,6 +296,7 @@ plugin_loggers:
|
|
216
296
|
|
217
297
|
2. Run `bin/attach` and pass the directory name of a Jekyll website that has a suitable script called `_bin/debug`.
|
218
298
|
The `demo` subdirectory fits this description.
|
299
|
+
|
219
300
|
```console
|
220
301
|
$ bin/attach demo
|
221
302
|
Successfully uninstalled jekyll_all_collections-0.1.2
|
@@ -233,26 +314,11 @@ plugin_loggers:
|
|
233
314
|
|
234
315
|
|
235
316
|
## Additional Information
|
317
|
+
|
236
318
|
More information is available on Mike Slinn's website about
|
237
319
|
[Jekyll plugins](https://www.mslinn.com/blog/index.html#Jekyll).
|
238
320
|
|
239
321
|
|
240
|
-
## Installation
|
241
|
-
This has already been done for the demo;
|
242
|
-
these instructions are for incorporating the plugin(s) into other Jekyll websites.
|
243
|
-
Add this line to your application's Gemfile:
|
244
|
-
|
245
|
-
```ruby
|
246
|
-
group :jekyll_plugins do
|
247
|
-
gem 'jekyll_all_collections'
|
248
|
-
end
|
249
|
-
```
|
250
|
-
|
251
|
-
And then execute:
|
252
|
-
|
253
|
-
$ bundle install
|
254
|
-
|
255
|
-
|
256
322
|
## Development
|
257
323
|
|
258
324
|
After checking out the repo, run `bin/setup` to install dependencies.
|
@@ -261,12 +327,9 @@ You can also run `bin/console` for an interactive prompt that will allow you to
|
|
261
327
|
|
262
328
|
|
263
329
|
### Build and Install Locally
|
330
|
+
|
264
331
|
To build and install this gem onto your local machine, run:
|
265
|
-
```shell
|
266
|
-
$ rake install
|
267
|
-
```
|
268
332
|
|
269
|
-
The following also does the same thing:
|
270
333
|
```shell
|
271
334
|
$ bundle exec rake install
|
272
335
|
jekyll_all_collections 0.1.0 built to pkg/jekyll_all_collections-0.1.0.gem.
|
@@ -274,6 +337,7 @@ jekyll_all_collections (0.1.0) installed.
|
|
274
337
|
```
|
275
338
|
|
276
339
|
Examine the newly built gem:
|
340
|
+
|
277
341
|
```shell
|
278
342
|
$ gem info jekyll_all_collections
|
279
343
|
|
@@ -290,15 +354,19 @@ jekyll_all_collections (0.1.0)
|
|
290
354
|
|
291
355
|
|
292
356
|
### Build and Push to RubyGems
|
357
|
+
|
293
358
|
To release a new version,
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
359
|
+
|
360
|
+
1. Update the version number in `version.rb`.
|
361
|
+
2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
|
362
|
+
3. Run the following:
|
363
|
+
|
364
|
+
```shell
|
365
|
+
$ bundle exec rake release
|
366
|
+
```
|
367
|
+
|
368
|
+
The above creates a git tag for the version, commits the created tag,
|
369
|
+
and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
|
302
370
|
|
303
371
|
|
304
372
|
## Contributing
|
data/Rakefile
CHANGED
@@ -4,17 +4,17 @@ Gem::Specification.new do |spec|
|
|
4
4
|
github = 'https://github.com/mslinn/jekyll_all_collections'
|
5
5
|
|
6
6
|
spec.authors = ['Mike Slinn']
|
7
|
-
spec.bindir = '
|
7
|
+
spec.bindir = 'exe'
|
8
8
|
spec.description = <<~END_OF_DESC
|
9
9
|
Provides a collection of all collections in site.all_collections.
|
10
10
|
END_OF_DESC
|
11
|
-
spec.email = ['
|
11
|
+
spec.email = ['mslinn@mslinn.com']
|
12
12
|
spec.executables = []
|
13
13
|
|
14
14
|
# Specify which files should be added to the gem when it is released.
|
15
15
|
spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
|
16
16
|
|
17
|
-
spec.homepage =
|
17
|
+
spec.homepage = 'https://www.mslinn.com/jekyll_plugins/jekyll_all_collections.html'
|
18
18
|
spec.license = 'MIT'
|
19
19
|
spec.metadata = {
|
20
20
|
'allowed_push_host' => 'https://rubygems.org',
|
@@ -30,6 +30,6 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.version = JekyllAllCollectionsVersion::VERSION
|
31
31
|
|
32
32
|
spec.add_dependency 'jekyll', '>= 3.5.0'
|
33
|
-
spec.add_dependency 'jekyll_draft', '
|
34
|
-
spec.add_dependency 'jekyll_plugin_support', '>= 0.
|
33
|
+
spec.add_dependency 'jekyll_draft', '>= 1.1.1'
|
34
|
+
spec.add_dependency 'jekyll_plugin_support', '>= 0.7.0'
|
35
35
|
end
|
@@ -73,15 +73,18 @@ module AllCollectionsHooks
|
|
73
73
|
def initialize(obj) # rubocop:disable Metrics/AbcSize
|
74
74
|
@data = obj.data if obj.respond_to? :data
|
75
75
|
|
76
|
-
@categories = @data['categories'] if
|
76
|
+
@categories = @data['categories'] if @data.key? 'categories'
|
77
77
|
@content = obj.content if obj.respond_to? :content
|
78
|
-
@date = @data['date'].to_date if
|
79
|
-
@description = @data['description'] if
|
80
|
-
|
78
|
+
@date = (@data['date'].to_date if @data&.key?('date')) || Date.today
|
79
|
+
@description = @data['description'] if @data.key? 'description'
|
80
|
+
|
81
|
+
# TODO: What _config.yml setting should be passed to destination()?
|
82
|
+
@destination = obj.destination('') if obj.respond_to? :destination
|
83
|
+
|
81
84
|
@draft = Jekyll::Draft.draft?(obj)
|
82
|
-
@excerpt = @data['excerpt'] if
|
83
|
-
@ext = @data['ext'] if
|
84
|
-
@label = obj.collection.label if obj.respond_to? :label
|
85
|
+
@excerpt = @data['excerpt'] if @data.key? 'excerpt'
|
86
|
+
@ext = @data['ext'] if @data.key? 'ext'
|
87
|
+
@label = obj.collection.label if obj&.collection.respond_to? :label
|
85
88
|
@last_modified = @data['last_modified'] || @data['last_modified_at'] || @date
|
86
89
|
@last_modified_field = case @data
|
87
90
|
when @data.key?('last_modified')
|
@@ -89,11 +92,11 @@ module AllCollectionsHooks
|
|
89
92
|
when @data.key?('last_modified_at')
|
90
93
|
'last_modified_at'
|
91
94
|
end
|
92
|
-
@layout = @data['layout'] if
|
95
|
+
@layout = @data['layout'] if @data.key? 'layout'
|
93
96
|
@path = obj.path if obj.respond_to? :path
|
94
97
|
@relative_path = obj.relative_path if obj.respond_to? :relative_path
|
95
|
-
@tags = @data['tags'] if
|
96
|
-
@title = @data['title'] if
|
98
|
+
@tags = @data['tags'] if @data.key? 'tags'
|
99
|
+
@title = @data['title'] if @data.key? 'title'
|
97
100
|
@type = obj.type if obj.respond_to? :type
|
98
101
|
@url = obj.url
|
99
102
|
end
|
data/lib/all_collections_tag.rb
CHANGED
@@ -8,8 +8,7 @@ class NullBinding < BasicObject
|
|
8
8
|
def min_binding
|
9
9
|
::Kernel
|
10
10
|
.instance_method(:binding)
|
11
|
-
.
|
12
|
-
.call
|
11
|
+
.bind_call(self)
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|
@@ -18,6 +17,7 @@ end
|
|
18
17
|
module AllCollectionsTag
|
19
18
|
PLUGIN_NAME = 'all_collections'.freeze
|
20
19
|
CRITERIA = %w[date destination draft label last_modified last_modified_at path relative_path title type url].freeze
|
20
|
+
DRAFT_HTML = '<i class="jekyll_draft">Draft</i>'.freeze
|
21
21
|
|
22
22
|
class AllCollectionsTag < JekyllSupport::JekyllTag
|
23
23
|
include JekyllAllCollectionsVersion
|
@@ -28,18 +28,22 @@ module AllCollectionsTag
|
|
28
28
|
AllCollectionsHooks.compute(@site) unless @site.class.method_defined? :all_collections
|
29
29
|
|
30
30
|
@date_column = @helper.parameter_specified?('date_column') || 'date'
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
unless %w[date last_modified].include?(@date_column)
|
32
|
+
# TODO: should this just issue a warning and return instead of dieing?
|
33
|
+
abort "Error: the date_column attribute must either have value 'date' or 'last_modified', " \
|
34
|
+
"but '#{@date_column}' was specified"
|
35
|
+
end
|
34
36
|
@id = @helper.parameter_specified?('id') || SecureRandom.hex(10)
|
35
|
-
sort_by_param = @helper.parameter_specified?
|
36
|
-
sort_by = (sort_by_param&.
|
37
|
+
sort_by_param = @helper.parameter_specified? 'sort_by'
|
38
|
+
sort_by = (sort_by_param&.delete(' ')&.split(',') if sort_by_param != false) || ['-date']
|
37
39
|
@heading = @helper.parameter_specified?('heading') || self.class.default_head(sort_by)
|
38
40
|
sort_lambda_string = self.class.create_lambda_string(sort_by)
|
39
|
-
@logger.debug
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
@logger.debug do
|
42
|
+
"#{@page['path']} sort_by_param=#{sort_by_param} " \
|
43
|
+
"sort_lambda_string = #{sort_lambda_string}\n"
|
44
|
+
end
|
45
|
+
sort_lambda = self.class.evaluate sort_lambda_string
|
46
|
+
generate_output sort_lambda
|
43
47
|
end
|
44
48
|
|
45
49
|
def self.default_head(sort_by)
|
@@ -57,9 +61,9 @@ module AllCollectionsTag
|
|
57
61
|
criteria_lhs_array = []
|
58
62
|
criteria_rhs_array = []
|
59
63
|
verify_sort_by_type(criteria).each do |c|
|
60
|
-
descending_sort = c.start_with?
|
64
|
+
descending_sort = c.start_with? '-'
|
61
65
|
c.delete_prefix! '-'
|
62
|
-
abort("Error: '#{c}' is not a valid sort field. Valid field names are: #{CRITERIA.join
|
66
|
+
abort("Error: '#{c}' is not a valid sort field. Valid field names are: #{CRITERIA.join ', '}") \
|
63
67
|
unless CRITERIA.include?(c)
|
64
68
|
criteria_lhs_array << (descending_sort ? "b.#{c}" : "a.#{c}")
|
65
69
|
criteria_rhs_array << (descending_sort ? "a.#{c}" : "b.#{c}")
|
@@ -92,32 +96,42 @@ module AllCollectionsTag
|
|
92
96
|
|
93
97
|
private
|
94
98
|
|
95
|
-
def
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
# "#{post.relative_path}: last_modified=#{post.last_modified}(#{post.last_modified.class}) date=#{post.date}(#{post.date.class})"
|
101
|
-
# end
|
102
|
-
@logger.debug { "Error: #{post.relative_path} has no value for last_modified" if post.last_modified.to_s.empty? }
|
99
|
+
def last_modified_value(post)
|
100
|
+
@logger.debug do
|
101
|
+
" post.last_modified='#{post.last_modified}'; " \
|
102
|
+
"post.last_modified_at='#{post.last_modified_at}'; " \
|
103
|
+
"@date_column='#{@date_column}'"
|
103
104
|
end
|
105
|
+
last_modified = if @date_column == 'last_modified' && post.respond_to?(:last_modified)
|
106
|
+
post.last_modified
|
107
|
+
elsif post.respond_to? :last_modified_at
|
108
|
+
post.last_modified_at
|
109
|
+
else
|
110
|
+
post.date
|
111
|
+
end
|
112
|
+
last_modified ||= post.date || Date.today
|
113
|
+
last_modified
|
114
|
+
end
|
115
|
+
|
116
|
+
def generate_output(sort_lambda)
|
117
|
+
id = @id.to_s.strip.empty? ? '' : " id='#{@id}'"
|
118
|
+
heading = @heading.strip.to_s.empty? ? '' : "<h2#{id}>#{@heading}</h2>"
|
104
119
|
collection = @site.all_collections.sort(&sort_lambda)
|
105
120
|
<<~END_TEXT
|
106
121
|
#{heading}
|
107
122
|
<div class="posts">
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
123
|
+
#{(collection.map do |post|
|
124
|
+
last_modified = last_modified_value post
|
125
|
+
date = last_modified.strftime '%Y-%m-%d'
|
126
|
+
draft = post.draft ? DRAFT_HTML : ''
|
127
|
+
href = "<a href='#{post.url}'>#{post.title}</a>"
|
128
|
+
@logger.debug { " date='#{date}' #{post.title}\n" }
|
129
|
+
" <span>#{date}</span><span>#{href}#{draft}</span>"
|
130
|
+
end).join "\n"}
|
116
131
|
</div>
|
117
132
|
END_TEXT
|
118
133
|
rescue ArgumentError => e
|
119
|
-
|
120
|
-
@logger.warn { e.backtrace.join("\n") }
|
134
|
+
warn_short_trace e
|
121
135
|
end
|
122
136
|
|
123
137
|
JekyllPluginHelper.register(self, PLUGIN_NAME)
|
data/spec/{all_collections_tag_sort_spec.rb → all_collections_tag/all_collections_tag_sort_spec.rb}
RENAMED
@@ -20,7 +20,7 @@ def show(lambda_string, result, expected)
|
|
20
20
|
end
|
21
21
|
|
22
22
|
# See https://stackoverflow.com/a/75388137/553865
|
23
|
-
RSpec.describe(AllCollectionsTag) do
|
23
|
+
RSpec.describe(AllCollectionsTag::AllCollectionsTag) do
|
24
24
|
let(:o1) { APageStub.new('2020-01-01', '2020-01-01', 'a_A') }
|
25
25
|
let(:o2) { APageStub.new('2021-01-01', '2020-01-01', 'b_A') }
|
26
26
|
let(:o3) { APageStub.new('2021-01-01', '2023-01-01', 'b_B') }
|
@@ -40,12 +40,6 @@ RSpec.describe(AllCollectionsTag) do
|
|
40
40
|
expect(result).to eq([o1, o2, o3, o4])
|
41
41
|
end
|
42
42
|
|
43
|
-
it 'defines sort_by lambda with array of last_modified' do
|
44
|
-
sort_lambda = ->(a, b) { [a.last_modified] <=> [b.last_modified] }
|
45
|
-
result = objs.sort(&sort_lambda)
|
46
|
-
expect(result).to eq([o1, o2, o3, o4])
|
47
|
-
end
|
48
|
-
|
49
43
|
it 'makes sort_by lambdas from stringified array of last_modified' do
|
50
44
|
sort_lambda = eval '->(a, b) { [a.last_modified] <=> [b.last_modified] }',
|
51
45
|
NullBinding.new.min_binding, __FILE__, __LINE__ - 1
|
@@ -62,8 +56,8 @@ RSpec.describe(AllCollectionsTag) do
|
|
62
56
|
end
|
63
57
|
|
64
58
|
it 'create_lambda with 1 date key, descending' do
|
65
|
-
lambda_string =
|
66
|
-
sort_lambda =
|
59
|
+
lambda_string = described_class.create_lambda_string('-last_modified')
|
60
|
+
sort_lambda = described_class.evaluate(lambda_string)
|
67
61
|
result = objs.sort(&sort_lambda)
|
68
62
|
expected = [o3, o4, o1, o2]
|
69
63
|
# show(lambda_string, result, expected)
|
@@ -71,8 +65,8 @@ RSpec.describe(AllCollectionsTag) do
|
|
71
65
|
end
|
72
66
|
|
73
67
|
it 'create_lambda with 1 date key, ascending' do
|
74
|
-
lambda_string =
|
75
|
-
sort_lambda =
|
68
|
+
lambda_string = described_class.create_lambda_string('date')
|
69
|
+
sort_lambda = described_class.evaluate(lambda_string)
|
76
70
|
result = objs.sort(&sort_lambda)
|
77
71
|
expected = [o1, o2, o3, o4]
|
78
72
|
# show(lambda_string, result, expected)
|
@@ -80,8 +74,8 @@ RSpec.describe(AllCollectionsTag) do
|
|
80
74
|
end
|
81
75
|
|
82
76
|
it 'create_lambda with 2 date keys, both ascending' do
|
83
|
-
lambda_string =
|
84
|
-
sort_lambda =
|
77
|
+
lambda_string = described_class.create_lambda_string(%w[date last_modified])
|
78
|
+
sort_lambda = described_class.evaluate(lambda_string)
|
85
79
|
result = objs.sort(&sort_lambda)
|
86
80
|
expected = [o1, o2, o3, o4]
|
87
81
|
# show(lambda_string, result, expected)
|
@@ -89,8 +83,8 @@ RSpec.describe(AllCollectionsTag) do
|
|
89
83
|
end
|
90
84
|
|
91
85
|
it 'create_lambda with 2 date keys, both descending' do
|
92
|
-
lambda_string =
|
93
|
-
sort_lambda =
|
86
|
+
lambda_string = described_class.create_lambda_string(['-date', '-last_modified'])
|
87
|
+
sort_lambda = described_class.evaluate(lambda_string)
|
94
88
|
result = objs.sort(&sort_lambda)
|
95
89
|
expected = [o4, o3, o2, o1]
|
96
90
|
# show(lambda_string, result, expected)
|
@@ -98,8 +92,8 @@ RSpec.describe(AllCollectionsTag) do
|
|
98
92
|
end
|
99
93
|
|
100
94
|
it 'create_lambda with 2 date keys, first descending and second ascending' do
|
101
|
-
lambda_string =
|
102
|
-
sort_lambda =
|
95
|
+
lambda_string = described_class.create_lambda_string(['-date', 'last_modified'])
|
96
|
+
sort_lambda = described_class.evaluate(lambda_string)
|
103
97
|
result = objs.sort(&sort_lambda)
|
104
98
|
expected = [o4, o2, o3, o1]
|
105
99
|
# show(lambda_string, result, expected)
|
@@ -107,8 +101,8 @@ RSpec.describe(AllCollectionsTag) do
|
|
107
101
|
end
|
108
102
|
|
109
103
|
it 'create_lambda with 2 date keys, first ascending and second descending' do
|
110
|
-
lambda_string =
|
111
|
-
sort_lambda =
|
104
|
+
lambda_string = described_class.create_lambda_string(['date', '-last_modified'])
|
105
|
+
sort_lambda = described_class.evaluate(lambda_string)
|
112
106
|
result = objs.sort(&sort_lambda)
|
113
107
|
expected = [o1, o3, o2, o4]
|
114
108
|
# show(lambda_string, result, expected)
|
data/spec/spec_helper.rb
CHANGED
@@ -6,9 +6,8 @@ require_relative '../lib/jekyll_all_collections'
|
|
6
6
|
Jekyll.logger.log_level = :info
|
7
7
|
|
8
8
|
RSpec.configure do |config|
|
9
|
-
config.filter_run :focus
|
10
9
|
# config.order = 'random'
|
11
|
-
config.
|
10
|
+
config.filter_run_when_matching focus: true
|
12
11
|
|
13
12
|
# See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
|
14
13
|
config.example_status_persistence_file_path = 'spec/status_persistence.txt'
|
data/spec/status_persistence.txt
CHANGED
@@ -1,20 +1,23 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
./spec/
|
4
|
-
./spec/
|
5
|
-
./spec/
|
6
|
-
./spec/
|
7
|
-
./spec/
|
8
|
-
./spec/
|
9
|
-
./spec/
|
10
|
-
./spec/
|
11
|
-
./spec/
|
12
|
-
./spec/
|
13
|
-
./spec/
|
14
|
-
./spec/
|
15
|
-
./spec/
|
16
|
-
./spec/
|
17
|
-
./spec/
|
18
|
-
./spec/
|
19
|
-
./spec/
|
20
|
-
./spec/
|
1
|
+
example_id | status | run_time |
|
2
|
+
-------------------------------- | ------ | --------------- |
|
3
|
+
./spec/date_sort_spec.rb[1:1] | passed | 0.00111 seconds |
|
4
|
+
./spec/date_sort_spec.rb[1:2] | passed | 0.00019 seconds |
|
5
|
+
./spec/date_sort_spec.rb[1:3] | passed | 0.00014 seconds |
|
6
|
+
./spec/date_sort_spec.rb[1:4] | passed | 0.00016 seconds |
|
7
|
+
./spec/date_sort_spec.rb[1:5] | passed | 0.00016 seconds |
|
8
|
+
./spec/date_sort_spec.rb[1:6] | passed | 0.00015 seconds |
|
9
|
+
./spec/date_sort_spec.rb[1:7] | passed | 0.00014 seconds |
|
10
|
+
./spec/date_sort_spec.rb[1:8] | passed | 0.00014 seconds |
|
11
|
+
./spec/date_sort_spec.rb[1:9] | passed | 0.00016 seconds |
|
12
|
+
./spec/date_sort_spec.rb[1:10] | passed | 0.00015 seconds |
|
13
|
+
./spec/lambda_sort_spec.rb[1:1] | passed | 0.00017 seconds |
|
14
|
+
./spec/lambda_sort_spec.rb[1:2] | passed | 0.00022 seconds |
|
15
|
+
./spec/lambda_sort_spec.rb[1:3] | passed | 0.00029 seconds |
|
16
|
+
./spec/lambda_sort_spec.rb[1:4] | passed | 0.0002 seconds |
|
17
|
+
./spec/lambda_sort_spec.rb[1:5] | passed | 0.00018 seconds |
|
18
|
+
./spec/lambda_sort_spec.rb[1:6] | passed | 0.0002 seconds |
|
19
|
+
./spec/lambda_sort_spec.rb[1:7] | passed | 0.00019 seconds |
|
20
|
+
./spec/lambda_sort_spec.rb[1:8] | passed | 0.00019 seconds |
|
21
|
+
./spec/lambda_sort_spec.rb[1:9] | passed | 0.00019 seconds |
|
22
|
+
./spec/lambda_sort_spec.rb[1:10] | passed | 0.00019 seconds |
|
23
|
+
./spec/lambda_sort_spec.rb[1:11] | passed | 0.00036 seconds |
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_all_collections
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Slinn
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
name: jekyll_draft
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.1.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.1.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -44,19 +44,19 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.7.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.7.0
|
55
55
|
description: 'Provides a collection of all collections in site.all_collections.
|
56
56
|
|
57
57
|
'
|
58
58
|
email:
|
59
|
-
-
|
59
|
+
- mslinn@mslinn.com
|
60
60
|
executables: []
|
61
61
|
extensions: []
|
62
62
|
extra_rdoc_files: []
|
@@ -71,18 +71,18 @@ files:
|
|
71
71
|
- lib/all_collections_tag.rb
|
72
72
|
- lib/jekyll_all_collections.rb
|
73
73
|
- lib/jekyll_all_collections/version.rb
|
74
|
-
- spec/all_collections_tag_sort_spec.rb
|
74
|
+
- spec/all_collections_tag/all_collections_tag_sort_spec.rb
|
75
75
|
- spec/date_sort_spec.rb
|
76
76
|
- spec/spec_helper.rb
|
77
77
|
- spec/status_persistence.txt
|
78
|
-
homepage: https://
|
78
|
+
homepage: https://www.mslinn.com/jekyll_plugins/jekyll_all_collections.html
|
79
79
|
licenses:
|
80
80
|
- MIT
|
81
81
|
metadata:
|
82
82
|
allowed_push_host: https://rubygems.org
|
83
83
|
bug_tracker_uri: https://github.com/mslinn/jekyll_all_collections/issues
|
84
84
|
changelog_uri: https://github.com/mslinn/jekyll_all_collections/CHANGELOG.md
|
85
|
-
homepage_uri: https://
|
85
|
+
homepage_uri: https://www.mslinn.com/jekyll_plugins/jekyll_all_collections.html
|
86
86
|
source_code_uri: https://github.com/mslinn/jekyll_all_collections
|
87
87
|
post_install_message:
|
88
88
|
rdoc_options: []
|