jekyll_draft 2.0.0 → 2.0.2
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/CHANGELOG.md +30 -2
- data/README.md +428 -57
- data/jekyll_draft.gemspec +1 -1
- data/lib/draft.rb +49 -24
- data/lib/draft_html.rb +19 -5
- data/lib/else.rb +10 -4
- data/lib/filters.rb +21 -0
- data/lib/if_draft.rb +17 -7
- data/lib/jekyll_draft/version.rb +1 -1
- data/lib/jekyll_draft.rb +3 -1
- metadata +6 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b8b48bd7048b0c4eb3836226b81c8da703f6573e5a564bf5c9ef22733be35167
|
|
4
|
+
data.tar.gz: 0ebe1a2cbbea83bb3f47fb3e512203a6aebfde0248cff99266e74a66536c99d7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4383047a610783981f175d29ccc86212c9b76a571ef587d06d29b487c3895e3e73737559ceeea25f4d849fe3a1fd5c64994b035378095ad355948f0bffe032b5
|
|
7
|
+
data.tar.gz: d2b9ec0decefb9c1b238c498c5a36735b1033362ff327c3d06760c9d0ce6a4e26bd2f657758403664f0b8a04914e8ad9396bdf6f383cac031849a2534d4e89dd
|
data/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,37 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 2.0.2 / 2024-07-24
|
|
4
|
+
|
|
5
|
+
* Compatible with `jekyll_plugin_support` v1.0.0
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## 2.0.1 / 2024-02-07
|
|
9
|
+
|
|
10
|
+
* Added Jekyll block tags `if_secret` and `unless_secret`.
|
|
11
|
+
* Added Jekyll inline tags: `unless_draft_only`, `else_if_secret` and `else_if_not_secret`.
|
|
12
|
+
* Added Liquid filter: `is_secret`.
|
|
13
|
+
* Added method `draft_only?` and `secret?` to API module `Jekyll::Draft`.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## 2.0.1 / 2023-11-30
|
|
17
|
+
|
|
18
|
+
* Jekyll block tags: `if_draft` and `unless_draft`.
|
|
19
|
+
* Jekyll inline tags: `else_if_not_draft` and `else_if_draft`.
|
|
20
|
+
* Jekyll inline tag `draft_html`.
|
|
21
|
+
* Liquid filters:
|
|
22
|
+
* `is_draft`
|
|
23
|
+
* `draft_html`
|
|
24
|
+
* Module `Jekyll::Draft` defines an API with the following methods:
|
|
25
|
+
* `draft?` returns a boolean indicating if the document passed to it is a draft.
|
|
26
|
+
* `draft_html` returns the same string the `draft_html` tag returns,
|
|
27
|
+
indicating if the document passed to it is a draft.
|
|
28
|
+
|
|
29
|
+
|
|
3
30
|
## 2.0.0 / 2023-11-29
|
|
4
31
|
|
|
5
|
-
*
|
|
6
|
-
|
|
32
|
+
* This version was published prematurely by accident.
|
|
33
|
+
It is broken, do not use it.
|
|
34
|
+
* This is a complete rewrite, incompatible with previous versions.
|
|
7
35
|
|
|
8
36
|
|
|
9
37
|
## 1.1.2 / 2023-02-25
|
data/README.md
CHANGED
|
@@ -1,59 +1,379 @@
|
|
|
1
1
|
# jekyll_draft [](https://badge.fury.io/rb/jekyll_draft)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Jekyll has various ways of specifying that a page or document is
|
|
4
|
+
visible when the website is published in `production` mode.
|
|
5
|
+
The Jekyll documentation is scattered and incomplete regarding this topic.
|
|
6
|
+
This plugin’s filters provide a simple means for marking draft pages in `development` mode.
|
|
7
|
+
|
|
8
|
+
A secret document is a special form of a draft document.
|
|
9
|
+
Secrets are always drafts, but not the converse.
|
|
10
|
+
|
|
11
|
+
`Jekyll_draft` provides the following:
|
|
12
|
+
|
|
13
|
+
* Jekyll block tags: `if_draft` and `unless_draft`.
|
|
14
|
+
* Jekyll block tags: `if_secret` and `unless_secret`.
|
|
15
|
+
* Jekyll inline tags: `else_if_not_draft`, `else_if_draft`, `else_if_not_secret` and `else_if_secret`.
|
|
16
|
+
These are meant for use within `if_draft`, `unless_draft`, `if_secret` and `unless_secret`, respectively.
|
|
17
|
+
Both of them are identical; they are both provided so usage seems natural.
|
|
18
|
+
* Jekyll inline tag `draft_html`, which generates HTML that indicates if the document
|
|
19
|
+
it is embedded within is a draft or a secret.
|
|
20
|
+
* Liquid filters:
|
|
21
|
+
* `is_draft` returns a boolean indicating if the document passed to it is a draft.
|
|
22
|
+
* `is_secret` returns a boolean indicating if the document passed to it is a secret.
|
|
23
|
+
* `draft_html` returns the same string the `draft_html` tag returns,
|
|
24
|
+
indicating if the document passed to it is a draft.
|
|
25
|
+
* Module `Jekyll::Draft` defines an API that your plugin can call.
|
|
26
|
+
It has the following methods:
|
|
27
|
+
* `draft?` returns a boolean indicating if the document passed to it is a draft or a secret.
|
|
28
|
+
* `draft_only?` returns a boolean indicating if the document passed to it is a draft and not a secret.
|
|
29
|
+
* `draft_html` returns the same string that `draft_html` tag returns;
|
|
30
|
+
the response indicates if the document passed to it is a draft.
|
|
31
|
+
* `root` returns the path to the root of the collection that the document passed to it is a member of.
|
|
32
|
+
This method is not functionally related to Jekyll draft documents;
|
|
33
|
+
it should be packaged separately ... maybe one day...
|
|
34
|
+
* `secret?` returns a boolean indicating if the document passed to it is a draft.
|
|
35
|
+
|
|
36
|
+
The difference between the tag called `draft_html` and the filter of the same name
|
|
37
|
+
is that the tag only works on the document that it is embedded in,
|
|
38
|
+
while the filter works on any document passed to it.
|
|
39
|
+
Both the tag and the filter call the same API methods defined in the `Jekyll::Draft` module.
|
|
40
|
+
|
|
41
|
+
More information is available on [Mike Slinn’s website](https://www.mslinn.com/jekyll_plugins/jekyll_draft.html).
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Front Matter
|
|
45
|
+
|
|
46
|
+
To mark a blog as a draft, put it in the `_drafts` directory.
|
|
47
|
+
|
|
48
|
+
To mark any other article as a draft, add the following to its front matter:
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
published: false
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
To mark any article (including blog posts) as a secret, add the following to its front matter:
|
|
55
|
+
|
|
56
|
+
```text
|
|
57
|
+
secret: true
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Secret documents are a type of draft document, so the above implies:
|
|
61
|
+
|
|
62
|
+
```text
|
|
63
|
+
published: false
|
|
64
|
+
secret: true
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## Demo
|
|
69
|
+
|
|
70
|
+
The [demo](demo) subdirectory has working examples of this Jekyll plugin's functionality
|
|
71
|
+
in a demonstration website.
|
|
72
|
+
It can be used to debug the plugin or it can run freely.
|
|
73
|
+
Please examine the <code>HTML</code> files in the demo to see how the plugin works.
|
|
74
|
+
|
|
75
|
+
To run the demo freely from the command line, type:
|
|
76
|
+
|
|
77
|
+
```console
|
|
78
|
+
$ demo/_bin/debug -r
|
|
79
|
+
```
|
|
4
80
|
|
|
5
|
-
|
|
81
|
+
Now point your web browser to http://localhost:4444.
|
|
82
|
+
You should see:
|
|
83
|
+
|
|
84
|
+

|
|
85
|
+
|
|
86
|
+
When the demonstration is running, any time you modify the <code>.html</code> files,
|
|
87
|
+
the demo website will regenerate.
|
|
88
|
+
Each time you make a change, the website instantly regenerates.
|
|
89
|
+
This helps the learning experience.
|
|
90
|
+
|
|
91
|
+
Please play with the contents of the <code>.html</code> files,
|
|
92
|
+
so you can learn how to write Jekyll pages that include this functionality.
|
|
6
93
|
|
|
7
94
|
|
|
8
95
|
## Installation
|
|
9
96
|
|
|
10
|
-
|
|
97
|
+
### For Use In A Jekyll Website
|
|
98
|
+
|
|
99
|
+
1. Add the CSS found in [`demo/assets/css/jekyll_draft.css`](demo/assets/css/jekyll_draft.css) to your Jekyll layout(s).
|
|
100
|
+
|
|
101
|
+
2. Add the following to your Jekyll website's `Gemfile`, within the `jekyll_plugins` group:
|
|
102
|
+
|
|
103
|
+
```ruby
|
|
104
|
+
group :jekyll_plugins do
|
|
105
|
+
gem 'jekyll_draft', '>2.0.0' # v2.0.0 was a dud, do not use it
|
|
106
|
+
end
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
3. Type:
|
|
110
|
+
|
|
111
|
+
```shell
|
|
112
|
+
$ bundle
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
### For Use In a Gem
|
|
117
|
+
|
|
118
|
+
1. Add the following to your gem’s `.gemspec`:
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
spec.add_dependency 'jekyll_draft', '>2.0.0' # v2.0.0 was a dud, do not use it
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
2. Type:
|
|
125
|
+
|
|
126
|
+
```shell
|
|
127
|
+
$ bundle
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
## Usage in a Web Page
|
|
11
132
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
133
|
+
### `if_draft`, `unless_draft`, `if_secret` and `unless_secret` Block Tags
|
|
134
|
+
|
|
135
|
+
The `if_draft` and `if_secret` block tags acts as `if-then` or `if-then-else` programming constructs.
|
|
136
|
+
|
|
137
|
+
The following generates `<p>This is a draft or a secret document!</p>`
|
|
138
|
+
if the document it is embedded in is a draft, and the Jekyll website generation was performed in development mode:
|
|
139
|
+
|
|
140
|
+
```html
|
|
141
|
+
{% if_draft %}
|
|
142
|
+
<p>This is a draft or a secret document!</p>
|
|
143
|
+
{% endif_draft %}
|
|
20
144
|
```
|
|
21
145
|
|
|
22
|
-
|
|
146
|
+
The following generates `<p>This is a draft document!</p>`
|
|
147
|
+
if the document it is embedded in is a draft and not a secret, and the Jekyll website generation was performed in development mode:
|
|
23
148
|
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
149
|
+
```html
|
|
150
|
+
{% if_draft_only %}
|
|
151
|
+
<p>This is a draft document!</p>
|
|
152
|
+
{% endif_draft %}
|
|
28
153
|
```
|
|
29
154
|
|
|
30
|
-
|
|
155
|
+
The following generates `<p>This is a secret document!</p>`
|
|
156
|
+
if the document it is embedded in is a secret, and the Jekyll website generation was performed in development mode:
|
|
31
157
|
|
|
32
|
-
```
|
|
33
|
-
|
|
158
|
+
```html
|
|
159
|
+
{% if_secret %}
|
|
160
|
+
<p>This is a secret document!</p>
|
|
161
|
+
{% endif_draft %}
|
|
34
162
|
```
|
|
35
163
|
|
|
164
|
+
The following enhances the previous example by also generating `<p>This is not a draft or a secret document!</p>`
|
|
165
|
+
when in production mode:
|
|
36
166
|
|
|
37
|
-
|
|
167
|
+
```html
|
|
168
|
+
{% if_draft %}
|
|
169
|
+
<p>This is a draft or a secret document!</p>
|
|
170
|
+
{% else_if_not_secret %}
|
|
171
|
+
<p>This is not a secret document, but might be a draft!</p>
|
|
172
|
+
{% else_if_not_draft %}
|
|
173
|
+
<p>This is not a draft or a secret document!</p>
|
|
174
|
+
{% endif_draft %}
|
|
175
|
+
```
|
|
38
176
|
|
|
39
|
-
|
|
177
|
+
The `unless_draft`, `unless_draft_only` and `unless_secret` block tags acts as Ruby
|
|
178
|
+
[unless-then](https://rubystyle.guide/#unless-for-negatives) or
|
|
179
|
+
an [unless-then-else](https://rubystyle.guide/#no-else-with-unless) programming constructs.
|
|
40
180
|
|
|
41
|
-
|
|
42
|
-
|
|
181
|
+
```html
|
|
182
|
+
{% unless_draft %}
|
|
183
|
+
<p>This is not a draft or a secret document!</p>
|
|
184
|
+
{% endunless_draft %}
|
|
185
|
+
```
|
|
43
186
|
|
|
44
187
|
```html
|
|
45
|
-
{
|
|
188
|
+
{% unless_draft_only %}
|
|
189
|
+
<p>This is not a draft document, but might be a secret!</p>
|
|
190
|
+
{% endunless_draft %}
|
|
46
191
|
```
|
|
47
192
|
|
|
48
|
-
|
|
193
|
+
```html
|
|
194
|
+
{% unless_secret %}
|
|
195
|
+
<p>This is not a secret document, but might be a draft!</p>
|
|
196
|
+
{% endunless_draft %}
|
|
197
|
+
```
|
|
49
198
|
|
|
50
|
-
This
|
|
199
|
+
This is how you can specify an `else` clause for `unless_draft`:
|
|
200
|
+
|
|
201
|
+
```html
|
|
202
|
+
{% unless_draft %}
|
|
203
|
+
<p>This is not a draft document!</p>
|
|
204
|
+
{% else_if_draft %}
|
|
205
|
+
<p>This is a draft document!</p>
|
|
206
|
+
{% endunless_draft %}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
```html
|
|
210
|
+
{% unless_draft %}
|
|
211
|
+
<p>This is not a draft document!</p>
|
|
212
|
+
{% else_if_draft %}
|
|
213
|
+
<p>This is a draft or a secret document!</p>
|
|
214
|
+
{% else_if_draft_only %}
|
|
215
|
+
<p>This is a draft document!</p>
|
|
216
|
+
{% else_if_secret %}
|
|
217
|
+
<p>This is a secret document!</p>
|
|
218
|
+
{% endunless_draft %}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
You can use the keywords `else_if_draft` and `else_if_not_draft` interchangeably.
|
|
222
|
+
They are actually made by registering the same code twice with different subclass names.
|
|
223
|
+
Use the keyword that makes the most sense to you.
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
### `draft_html` Inline Tag
|
|
227
|
+
|
|
228
|
+
Here is an example of embedding the `draft_html` inline tag into an HTML document:
|
|
229
|
+
|
|
230
|
+
```html
|
|
231
|
+
<p>Is this a draft document? Look here to see: {% draft_html %}</p>
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
By default, if the document is a draft or a secret, and the Jekyll website generation was performed in development mode,
|
|
235
|
+
`draft_html` emits ` <i class='jekyll_draft>Draft</i>` or ` <i class='jekyll_secret>Secret</i>` ,
|
|
236
|
+
otherwise it does not emit anything.
|
|
237
|
+
|
|
238
|
+
You can change this behavior several ways:
|
|
239
|
+
|
|
240
|
+
* Add the `published_output` parameter to specify the HTML that should be emitted if the document is not a draft or a secret,
|
|
241
|
+
and the Jekyll website generation was performed in development mode.
|
|
242
|
+
The default message will continue to be output for draft documents when the `published_output` parameter is used.
|
|
243
|
+
|
|
244
|
+
```html
|
|
245
|
+
{% draft_html published_output="<p>Not a draft or a secret</p>" %}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
* Add the `draft_output` parameter to specify the HTML that should be emitted if the document is a draft,
|
|
249
|
+
the `secret_output` parameter to specify the HTML that should be emitted if the document is a secret,
|
|
250
|
+
and the Jekyll website generation was performed in development mode:
|
|
251
|
+
|
|
252
|
+
```html
|
|
253
|
+
{% draft_html
|
|
254
|
+
draft_output="<p>Is a draft</p>"
|
|
255
|
+
%}
|
|
256
|
+
{% draft_html
|
|
257
|
+
draft_output="<p>Is a draft</p>"
|
|
258
|
+
published_output="<p>Not a draft</p>"
|
|
259
|
+
%}
|
|
260
|
+
{% draft_html
|
|
261
|
+
secret_output="<p>Is a secret</p>"
|
|
262
|
+
%}
|
|
263
|
+
{% draft_html
|
|
264
|
+
draft_output="<p>Is a draft</p>"
|
|
265
|
+
published_output="<p>Not a draft or a secret</p>"
|
|
266
|
+
secret_output="<p>Is a secret</p>"
|
|
267
|
+
%}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
* Add the `draft_class` parameter to specify the CSS class that should be added
|
|
271
|
+
to the emitted HTML if the document is a draft,
|
|
272
|
+
add the `secret_class` parameter to specify the CSS class that should be added
|
|
273
|
+
to the emitted HTML if the document is a secret,
|
|
274
|
+
and the Jekyll website generation was performed in development mode:
|
|
275
|
+
|
|
276
|
+
```html
|
|
277
|
+
{% draft_html draft_class="my_draft_class" %}
|
|
278
|
+
{% draft_html
|
|
279
|
+
draft_class="my_draft_class"
|
|
280
|
+
published_output="<p>Not a draft or a secret</p>"
|
|
281
|
+
%}
|
|
282
|
+
{% draft_html draft_class="my_draft_class" secret_class="my_secret_class" %}
|
|
283
|
+
{% draft_html
|
|
284
|
+
draft_class="my_draft_class"
|
|
285
|
+
published_output="<p>Not a draft or a secret</p>"
|
|
286
|
+
secret_class="my_secret_class"
|
|
287
|
+
%}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
* Add the `draft_style` parameter to specify the CSS class that should be added
|
|
291
|
+
to the emitted HTML if the document is a draft,
|
|
292
|
+
and the Jekyll website generation was performed in development mode:
|
|
293
|
+
|
|
294
|
+
```html
|
|
295
|
+
{% draft_html draft_style="font-size: 24pt;" %}
|
|
296
|
+
{% draft_html secret_style="font-size: 24pt; color: red;" %}
|
|
297
|
+
{% draft_html
|
|
298
|
+
draft_class="my_draft_class"
|
|
299
|
+
draft_style="font-size: 24pt;"
|
|
300
|
+
secret_class="my_secret_class"
|
|
301
|
+
secret_style="font-size: 24pt; color: red;"
|
|
302
|
+
%}
|
|
303
|
+
{% draft_html
|
|
304
|
+
draft_class="my_draft_class"
|
|
305
|
+
draft_style="font-size: 24pt;"
|
|
306
|
+
published_output="<p>Not a draft or a secret</p>"
|
|
307
|
+
secret_class="my_secret_class"
|
|
308
|
+
secret_style="font-size: 24pt; color: red;"
|
|
309
|
+
%}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
### Liquid Filters
|
|
314
|
+
|
|
315
|
+
#### `draft_html`
|
|
316
|
+
|
|
317
|
+
By default, the draft_html Liquid filter generates HTML if a page is invisible when published in `production` mode.
|
|
51
318
|
If the page is not a draft then the empty string is returned.
|
|
52
|
-
|
|
53
|
-
`
|
|
319
|
+
|
|
320
|
+
The optional parameters for the `draft_html` inline tag are not available for
|
|
321
|
+
use with the `draft_html` filter.
|
|
322
|
+
|
|
323
|
+
The default generated HTML for draft pages is:<br>
|
|
324
|
+
`" <i class='jekyll_draft'>Draft</i>"`
|
|
325
|
+
|
|
326
|
+
The default generated HTML for secret pages is:<br>
|
|
327
|
+
`" <i class='jekyll_secret'>Secret</i>"`
|
|
328
|
+
|
|
329
|
+
Invoke the filter like the following; the output depends on whether the document is a draft or a secret:
|
|
330
|
+
|
|
331
|
+
```html
|
|
332
|
+
{{ page | draft_html }} => " <i class='jekyll_draft'>Draft</i>"
|
|
333
|
+
{{ page | draft_html }} => " <i class='jekyll_secret'>Secret</i>"
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Here is a code snippet that shows the <code>draft_html</code> filter in use:
|
|
337
|
+
|
|
338
|
+
```html
|
|
339
|
+
{% assign docs = site.myCollection | sort: "order" %}
|
|
340
|
+
<ol id="titles">
|
|
341
|
+
{% for doc in docs %}
|
|
342
|
+
<li>
|
|
343
|
+
<a href="{{doc.url}}" class="title">{{doc.title}}</a>{{ doc | draft_html }}
|
|
344
|
+
</li>
|
|
345
|
+
{% endfor %}
|
|
346
|
+
</ol>
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
#### `is_draft`
|
|
351
|
+
|
|
352
|
+
This filter detects if a page is invisible when published in `production` mode,
|
|
353
|
+
and either returns `true` or `false`.
|
|
354
|
+
|
|
355
|
+
```html
|
|
356
|
+
{{ page | is_draft }} <!-- true for draft and secret documents in development mode -->
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
#### `is_draft_only`
|
|
361
|
+
|
|
362
|
+
This filter detects if a page is invisible when published in `production` mode,
|
|
363
|
+
and either returns `true` or `false`.
|
|
364
|
+
|
|
365
|
+
```html
|
|
366
|
+
{{ page | is_draft_only }} <!-- true for draft documents in development mode, but not secret documents -->
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
#### `is_secret`
|
|
371
|
+
|
|
372
|
+
This filter detects if a page is invisible when published in `production` mode,
|
|
373
|
+
and either returns `true` or `false`.
|
|
54
374
|
|
|
55
375
|
```html
|
|
56
|
-
{{ page |
|
|
376
|
+
{{ page | is_secret }} <!-- true for secret documents in development mode, but not draft documents -->
|
|
57
377
|
```
|
|
58
378
|
|
|
59
379
|
|
|
@@ -62,32 +382,50 @@ The generated HTML for draft pages is:<br>
|
|
|
62
382
|
```ruby
|
|
63
383
|
require 'jekyll_draft'
|
|
64
384
|
|
|
65
|
-
puts 'Found a draft' if Jekyll::Draft.is_draft post
|
|
385
|
+
puts 'Found a draft or a secret' if Jekyll::Draft.is_draft post
|
|
66
386
|
|
|
67
|
-
|
|
387
|
+
draft_or_secret = Jekyll::Draft.draft_html post
|
|
68
388
|
```
|
|
69
389
|
|
|
70
390
|
|
|
71
|
-
##
|
|
391
|
+
## Usage in a Plugin
|
|
72
392
|
|
|
73
|
-
The
|
|
74
|
-
|
|
393
|
+
The methods in `lib/draft_html.rb` can be invoked by qualifying them with `Jekyll::Draft`.
|
|
394
|
+
Here is a complete example of a Jekyll Support plugin that displays an indication of whether the page is a draft or not:
|
|
75
395
|
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
|
|
396
|
+
```ruby
|
|
397
|
+
require 'jekyll_plugin_support'
|
|
398
|
+
|
|
399
|
+
module MyPluginTag
|
|
400
|
+
MyPluginError = JekyllSupport.define_error
|
|
401
|
+
PLUGIN_NAME = 'my_plugin'.freeze
|
|
402
|
+
VERSION = '0.1.0'.freeze
|
|
403
|
+
|
|
404
|
+
class MyPluginTag < JekyllSupport::JekyllTag
|
|
405
|
+
def render_impl
|
|
406
|
+
<<~HEREDOC
|
|
407
|
+
Draft or not? #{Jekyll::Draft.draft_html(@page)}
|
|
408
|
+
HEREDOC
|
|
409
|
+
end
|
|
410
|
+
end
|
|
411
|
+
end
|
|
79
412
|
|
|
80
|
-
|
|
413
|
+
Liquid::Template.register_tag(MyPluginTag::PLUGIN_NAME, MyPluginTag::MyPluginTag)
|
|
414
|
+
PluginMetaLogger.instance.info { "Loaded #{MyPluginTag::PLUGIN_NAME} v#{MyPluginTag::VERSION} plugin." }
|
|
415
|
+
```
|
|
81
416
|
|
|
82
417
|
|
|
83
418
|
## Development
|
|
84
419
|
|
|
85
|
-
|
|
420
|
+
### Setup
|
|
421
|
+
|
|
422
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
|
423
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
86
424
|
|
|
87
425
|
Install development dependencies like this:
|
|
88
426
|
|
|
89
427
|
```shell
|
|
90
|
-
$ BUNDLE_WITH=
|
|
428
|
+
$ BUNDLE_WITH=development bundle
|
|
91
429
|
```
|
|
92
430
|
|
|
93
431
|
To install this gem onto your local machine, run:
|
|
@@ -96,39 +434,72 @@ To install this gem onto your local machine, run:
|
|
|
96
434
|
$ bundle exec rake install
|
|
97
435
|
```
|
|
98
436
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
1. Update the version number in `version.rb`.
|
|
102
|
-
2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
|
|
103
|
-
3. Run the following:
|
|
104
|
-
|
|
105
|
-
```shell
|
|
106
|
-
$ bundle exec rake release
|
|
107
|
-
```
|
|
437
|
+
### Debugging The Demo
|
|
108
438
|
|
|
109
|
-
|
|
110
|
-
and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
|
|
439
|
+
Set breakpoints, then use the Visual Studio Code launch configuration called `Debug Demo`.
|
|
111
440
|
|
|
112
441
|
|
|
113
|
-
### Debugging
|
|
442
|
+
### Debugging From Another Jekyll Site
|
|
114
443
|
|
|
115
444
|
Run `bin/attach` and pass the directory name of a Jekyll website that has a suitable script called `_bin/debug`.
|
|
116
445
|
The `demo` subdirectory fits this description.
|
|
117
446
|
|
|
118
447
|
```console
|
|
119
448
|
$ bin/attach demo
|
|
120
|
-
Successfully uninstalled jekyll_draft-
|
|
121
|
-
|
|
122
|
-
jekyll_draft
|
|
123
|
-
|
|
449
|
+
Successfully uninstalled jekyll_draft-1.1.2
|
|
450
|
+
Successfully uninstalled jekyll_draft-2.0.0
|
|
451
|
+
jekyll_draft 2.0.0 built to pkg/jekyll_draft-2.0.0.gem.
|
|
452
|
+
jekyll_draft (2.0.0) installed.
|
|
453
|
+
jekyll_draft 2.0.0 built to pkg/jekyll_draft-2.0.0.gem.
|
|
454
|
+
jekyll_draft (2.0.0) installed.
|
|
455
|
+
Fetching gem metadata from https://rubygems.org/..........
|
|
456
|
+
Resolving dependencies...
|
|
457
|
+
Bundle complete! 21 Gemfile dependencies, 104 gems now installed.
|
|
458
|
+
Use `bundle info [gemname]` to see where a bundled gem is installed.
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
INFO PluginMetaLogger: Loaded else_if_draft v0.1.0 plugin.
|
|
462
|
+
INFO PluginMetaLogger: Loaded else_if_not_draft v0.1.0 plugin.
|
|
463
|
+
INFO PluginMetaLogger: Loaded String and String, v2.0.0 plugin.
|
|
464
|
+
INFO PluginMetaLogger: Loaded if_draft v2.0.0 plugin.
|
|
465
|
+
INFO PluginMetaLogger: Loaded unless_draft v2.0.0 plugin.
|
|
466
|
+
INFO PluginMetaLogger: Loaded String and String, v2.0.0 plugin.
|
|
467
|
+
INFO PluginMetaLogger: Loaded exec v1.4.2 plugin.
|
|
468
|
+
INFO PluginMetaLogger: Loaded noselect v1.4.2 plugin.
|
|
469
|
+
INFO PluginMetaLogger: Loaded pre v1.4.2 plugin.
|
|
470
|
+
INFO PluginMetaLogger: Loaded jekyll_pre v1.4.2 plugin.
|
|
471
|
+
Configuration file: /mnt/f/work/jekyll/my_plugins/jekyll_draft/demo/_config.yml
|
|
472
|
+
Cleaner: Removing /mnt/f/work/jekyll/my_plugins/jekyll_draft/demo/_site...
|
|
473
|
+
Cleaner: Removing /mnt/f/work/jekyll/my_plugins/jekyll_draft/demo/.jekyll-metadata...
|
|
474
|
+
Cleaner: Removing /mnt/f/work/jekyll/my_plugins/jekyll_draft/demo/.jekyll-cache...
|
|
475
|
+
Cleaner: Nothing to do for .sass-cache.
|
|
476
|
+
DEBUGGER: Debugger can attach via TCP/IP (127.0.0.1:45409)
|
|
477
|
+
DEBUGGER: wait for debugger connection...
|
|
124
478
|
```
|
|
125
479
|
|
|
126
480
|
Now attach to the debugger process.
|
|
127
|
-
This git repo includes a [Visual Studio Code launcher](
|
|
481
|
+
This git repo includes a [Visual Studio Code launcher](.vscode/launch.json) for this purpose labeled `Attach rdbg`.
|
|
482
|
+
It uses TCP/IP port 45409 to attach; you might need to modify that value.
|
|
128
483
|
|
|
129
484
|
Now point your web browser to http://localhost:4444
|
|
130
485
|
|
|
131
486
|
|
|
487
|
+
### Releasing A New Version
|
|
488
|
+
|
|
489
|
+
To release a new version,
|
|
490
|
+
|
|
491
|
+
1. Update the version number in `version.rb`.
|
|
492
|
+
2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
|
|
493
|
+
3. Run the following:
|
|
494
|
+
|
|
495
|
+
```shell
|
|
496
|
+
$ bundle exec rake release
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
The above creates a git tag for the version, commits the created tag,
|
|
500
|
+
and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
|
|
501
|
+
|
|
502
|
+
|
|
132
503
|
## Contributing
|
|
133
504
|
|
|
134
505
|
Bug reports and pull requests are welcome on GitHub at https://github.com/mslinn/jekyll_draft.
|
data/jekyll_draft.gemspec
CHANGED
|
@@ -32,5 +32,5 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
|
32
32
|
spec.version = DraftVersion::VERSION
|
|
33
33
|
|
|
34
34
|
spec.add_dependency 'jekyll', '>= 3.5.0'
|
|
35
|
-
spec.add_dependency 'jekyll_plugin_support'
|
|
35
|
+
spec.add_dependency 'jekyll_plugin_support', '>=1.0.0'
|
|
36
36
|
end
|
data/lib/draft.rb
CHANGED
|
@@ -1,29 +1,54 @@
|
|
|
1
|
+
require 'jekyll_plugin_logger'
|
|
2
|
+
|
|
1
3
|
# Define these methods outside of the JekyllDraft class so they can be invoked externally and tested more easily
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# - document front matter contains 'published: false'
|
|
6
|
-
def draft?(doc)
|
|
7
|
-
return true if doc.respond_to?(:draft) && doc.draft
|
|
8
|
-
return true if doc.key?('draft') && doc['draft'] # ignore !doc['draft']
|
|
9
|
-
return !doc['published'] if doc.key?('published')
|
|
10
|
-
|
|
11
|
-
false
|
|
12
|
-
rescue StandardError => e
|
|
13
|
-
@logger.error { e }
|
|
14
|
-
false
|
|
15
|
-
end
|
|
4
|
+
module Jekyll
|
|
5
|
+
module Draft
|
|
6
|
+
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
|
16
7
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
# @return true by checking in this order:
|
|
9
|
+
# - document is in _drafts directory, detectable by doc['draft']==true
|
|
10
|
+
# - document front matter contains 'published: false'
|
|
11
|
+
def draft?(doc)
|
|
12
|
+
if doc.respond_to? :data
|
|
13
|
+
return !doc.data['published'] if doc.data.key? 'published'
|
|
14
|
+
return doc.data['draft'] if doc.data.key? 'draft'
|
|
15
|
+
end
|
|
16
|
+
if doc.respond_to? :[]
|
|
17
|
+
return !doc['published'] if doc.key? 'published'
|
|
18
|
+
return doc['draft'] if doc.key? 'draft'
|
|
19
|
+
end
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
return doc.draft if doc.respond_to? :draft
|
|
22
|
+
|
|
23
|
+
false
|
|
24
|
+
rescue StandardError => e
|
|
25
|
+
@logger.error { e }
|
|
26
|
+
false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# @param doc [Jekyll::Drops::DocumentDrop]
|
|
30
|
+
# @return HTML that indicates if a doc is a draft or not
|
|
31
|
+
def draft_html(doc)
|
|
32
|
+
return '' unless draft? doc
|
|
27
33
|
|
|
28
|
-
|
|
34
|
+
" <i class='jekyll_draft'>Draft</i>"
|
|
35
|
+
rescue StandardError => e
|
|
36
|
+
@logger.error { e.full_message }
|
|
37
|
+
''
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @return path to root of the collection that doc is a member of
|
|
41
|
+
def root(doc, site)
|
|
42
|
+
return '/index.html' unless doc.respond_to?(:collection)
|
|
43
|
+
|
|
44
|
+
collection_name = doc.collection
|
|
45
|
+
docs = site.key?(collection_name) ? site[collection_name] : site.collections[collection_name].docs
|
|
46
|
+
index = docs.find { |d| d.url.end_with? 'index.html' }
|
|
47
|
+
return index.url if index
|
|
48
|
+
|
|
49
|
+
docs.min.url
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
module_function :draft?, :draft_html, :root
|
|
53
|
+
end
|
|
29
54
|
end
|
data/lib/draft_html.rb
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
require 'jekyll_plugin_support'
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class DraftHtml < JekyllSupport::JekyllTag
|
|
4
4
|
VERSION = '0.1.0'.freeze
|
|
5
|
-
|
|
5
|
+
DRAFT_HTML = 'draft_html'.freeze unless defined? Else::VERSION
|
|
6
6
|
|
|
7
7
|
def render_impl
|
|
8
|
-
|
|
8
|
+
is_draft = Jekyll::Draft.draft?(@page)
|
|
9
|
+
|
|
10
|
+
published_output = @helper.parameter_specified? 'published_output'
|
|
11
|
+
return published_output if !is_draft && published_output
|
|
12
|
+
return unless is_draft
|
|
13
|
+
|
|
14
|
+
draft_output = @helper.parameter_specified? 'draft_output'
|
|
15
|
+
return draft_output if draft_output
|
|
16
|
+
|
|
17
|
+
draft_class = @helper.parameter_specified? 'class'
|
|
18
|
+
dc = " #{draft_class}" if draft_class
|
|
19
|
+
|
|
20
|
+
draft_style = @helper.parameter_specified? 'style'
|
|
21
|
+
ds = " style='#{draft_style}'" if draft_style
|
|
22
|
+
|
|
23
|
+
" <i class='jekyll_draft#{dc}'#{ds}>Draft</i>"
|
|
9
24
|
end
|
|
10
25
|
|
|
11
|
-
JekyllPluginHelper.register(self,
|
|
12
|
-
PluginMetaLogger.instance.info { "Loaded #{PLUGIN_NAME.class} v#{DraftVersion::VERSION} plugin." }
|
|
26
|
+
::JekyllSupport::JekyllPluginHelper.register(self, DRAFT_HTML)
|
|
13
27
|
end
|
data/lib/else.rb
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
require 'jekyll_plugin_support'
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class ElseBase < JekyllSupport::JekyllTag
|
|
4
4
|
VERSION = '0.1.0'.freeze
|
|
5
|
-
|
|
5
|
+
ELSE_DRAFT = 'else_if_draft'.freeze
|
|
6
|
+
ELSE_NOT_DRAFT = 'else_if_not_draft'.freeze
|
|
6
7
|
|
|
7
8
|
def render_impl
|
|
8
9
|
RECORD_SEPARATOR
|
|
9
10
|
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class ElseDraft < ElseBase
|
|
14
|
+
::JekyllSupport::JekyllPluginHelper.register(self, ELSE_DRAFT)
|
|
15
|
+
end
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
class ElseNotDraft < ElseBase
|
|
18
|
+
::JekyllSupport::JekyllPluginHelper.register(self, ELSE_NOT_DRAFT)
|
|
13
19
|
end
|
data/lib/filters.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'jekyll_plugin_logger'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
# Jekyll filters that detect draft documents
|
|
5
|
+
module Jekyll
|
|
6
|
+
module DraftFilter
|
|
7
|
+
def is_draft(doc) # rubocop:disable Naming/PredicateName
|
|
8
|
+
Draft.draft? doc
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def draft_html(doc)
|
|
12
|
+
Draft.draft_html doc
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def root(doc, site)
|
|
16
|
+
Draft.root(doc, site)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
Liquid::Template.register_filter(DraftFilter)
|
|
21
|
+
end
|
data/lib/if_draft.rb
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
require 'jekyll_plugin_support'
|
|
2
2
|
|
|
3
|
-
# Jekyll
|
|
4
|
-
class
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
# Jekyll block tags that detect draft documents
|
|
4
|
+
class DraftBase < JekyllSupport::JekyllBlock
|
|
5
|
+
IF_DRAFT = 'if_draft'.freeze
|
|
6
|
+
UNLESS_DRAFT = 'unless_draft'.freeze
|
|
7
|
+
VERSION = DraftVersion::VERSION.freeze
|
|
7
8
|
|
|
8
9
|
def render_impl(content)
|
|
9
10
|
true_value, false_value, extra = content.split(RECORD_SEPARATOR)
|
|
10
11
|
raise DraftError, "Warning: More than one else clause detected" if extra
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
if @tag_name == IF_DRAFT
|
|
14
|
+
return ::Jekyll::Draft.draft?(@page) ? true_value : false_value
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
::Jekyll::Draft.draft?(@page) ? false_value : true_value
|
|
13
18
|
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class IfDraft < DraftBase
|
|
22
|
+
::JekyllSupport::JekyllPluginHelper.register(self, IF_DRAFT)
|
|
23
|
+
end
|
|
14
24
|
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
class UnlessDraft < DraftBase
|
|
26
|
+
::JekyllSupport::JekyllPluginHelper.register(self, UNLESS_DRAFT)
|
|
17
27
|
end
|
data/lib/jekyll_draft/version.rb
CHANGED
data/lib/jekyll_draft.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jekyll_draft
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Slinn
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-07-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jekyll
|
|
@@ -30,14 +30,14 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
33
|
+
version: 1.0.0
|
|
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
|
-
version:
|
|
40
|
+
version: 1.0.0
|
|
41
41
|
description: 'This Jekyll filter detects draft documents.
|
|
42
42
|
|
|
43
43
|
'
|
|
@@ -56,6 +56,7 @@ files:
|
|
|
56
56
|
- lib/draft.rb
|
|
57
57
|
- lib/draft_html.rb
|
|
58
58
|
- lib/else.rb
|
|
59
|
+
- lib/filters.rb
|
|
59
60
|
- lib/if_draft.rb
|
|
60
61
|
- lib/jekyll_draft.rb
|
|
61
62
|
- lib/jekyll_draft/version.rb
|
|
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
91
92
|
- !ruby/object:Gem::Version
|
|
92
93
|
version: '0'
|
|
93
94
|
requirements: []
|
|
94
|
-
rubygems_version: 3.
|
|
95
|
+
rubygems_version: 3.5.16
|
|
95
96
|
signing_key:
|
|
96
97
|
specification_version: 4
|
|
97
98
|
summary: This Jekyll filter detects draft documents.
|