jekyll-paginate-content 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
+ <svg xmlns="http://www.w3.org/2000/svg">
4
+ <metadata>Copyright (C) 2018 by original authors @ fontello.com</metadata>
5
+ <defs>
6
+ <font id="fontello" horiz-adv-x="1000" >
7
+ <font-face font-family="fontello" font-weight="400" font-stretch="normal" units-per-em="1000" ascent="850" descent="-150" />
8
+ <missing-glyph horiz-adv-x="1000" />
9
+ <glyph glyph-name="to-end-alt" unicode="&#xe800;" d="M25-71q-10-11-18-8t-7 18v822q0 14 7 18t18-8l396-396q5-5 8-10v396q0 14 7 18t18-8l396-396q5-5 7-10v378q0 14 11 25t25 11h71q15 0 25-11t11-25v-786q0-14-11-25t-25-11h-71q-15 0-25 11t-11 25v379q-2-6-7-11l-396-396q-11-11-18-8t-7 18v397q-3-6-8-11z" horiz-adv-x="1000" />
10
+
11
+ <glyph glyph-name="to-start-alt" unicode="&#xe801;" d="M975 771q11 11 18 8t7-18v-822q0-14-7-18t-18 8l-396 396q-5 5-8 11v-397q0-14-7-18t-18 8l-396 396q-5 5-7 11v-379q0-14-11-25t-25-11h-71q-15 0-25 11t-11 25v786q0 14 11 25t25 11h71q15 0 25-11t11-25v-378q2 5 7 10l396 396q11 11 18 8t7-18v-396q3 5 8 10z" horiz-adv-x="1000" />
12
+
13
+ <glyph glyph-name="fast-fw" unicode="&#xe802;" d="M25-71q-10-11-18-8t-7 18v822q0 14 7 18t18-8l396-396q5-5 8-10v396q0 14 7 18t18-8l396-396q11-10 11-25t-11-25l-396-396q-11-11-18-8t-7 18v397q-3-6-8-11z" horiz-adv-x="928.6" />
14
+
15
+ <glyph glyph-name="fast-bw" unicode="&#xe803;" d="M904 771q10 11 17 8t8-18v-822q0-14-8-18t-17 8l-397 396q-5 5-7 11v-397q0-14-7-18t-18 8l-396 396q-11 11-11 25t11 25l396 396q11 11 18 8t7-18v-396q2 5 7 10z" horiz-adv-x="928.6" />
16
+
17
+ <glyph glyph-name="twitter" unicode="&#xf099;" d="M904 622q-37-54-90-93 0-8 0-23 0-73-21-145t-64-139-103-117-144-82-181-30q-151 0-276 81 19-2 43-2 126 0 224 77-59 1-105 36t-64 89q19-3 34-3 24 0 48 6-63 13-104 62t-41 115v2q38-21 82-23-37 25-59 64t-22 86q0 49 25 91 68-83 164-133t208-55q-5 21-5 41 0 75 53 127t127 53q79 0 132-57 61 12 115 44-21-64-80-100 52 6 104 28z" horiz-adv-x="928.6" />
18
+
19
+ <glyph glyph-name="github-circled" unicode="&#xf09b;" d="M429 779q116 0 215-58t156-156 57-215q0-140-82-252t-211-155q-15-3-22 4t-7 17q0 1 0 43t0 75q0 54-29 79 32 3 57 10t53 22 45 37 30 58 11 84q0 67-44 115 21 51-4 114-16 5-46-6t-51-25l-21-13q-52 15-107 15t-108-15q-8 6-23 15t-47 22-47 7q-25-63-5-114-44-48-44-115 0-47 12-83t29-59 45-37 52-22 57-10q-21-20-27-58-12-5-25-8t-32-3-36 12-31 35q-11 18-27 29t-28 14l-11 1q-12 0-16-2t-3-7 5-8 7-6l4-3q12-6 24-21t18-29l6-13q7-21 24-34t37-17 39-3 31 1l13 3q0-22 0-50t1-30q0-10-8-17t-22-4q-129 43-211 155t-82 252q0 117 58 215t155 156 216 58z m-267-616q2 4-3 7-6 1-8-1-1-4 4-7 5-3 7 1z m18-19q4 3-1 9-6 5-9 2-4-3 1-9 5-6 9-2z m16-25q6 4 0 11-4 7-9 3-5-3 0-10t9-4z m24-23q4 4-2 10-7 7-11 2-5-5 2-11 6-6 11-1z m32-14q1 6-8 9-8 2-10-4t7-9q8-3 11 4z m35-3q0 7-10 6-9 0-9-6 0-7 10-6 9 0 9 6z m32 5q-1 7-10 5-9-1-8-8t10-4 8 7z" horiz-adv-x="857.1" />
20
+
21
+ <glyph glyph-name="smile" unicode="&#xf118;" d="M633 250q-21-67-77-109t-127-41-128 41-77 109q-4 14 3 27t21 18q14 4 27-2t17-22q14-44 52-72t85-28 84 28 52 72q4 15 18 22t27 2 21-18 2-27z m-276 243q0-30-21-51t-50-21-51 21-21 51 21 50 51 21 50-21 21-50z m286 0q0-30-21-51t-51-21-50 21-21 51 21 50 50 21 51-21 21-50z m143-143q0 73-29 139t-76 114-114 76-138 28-139-28-114-76-76-114-29-139 29-139 76-113 114-77 139-28 138 28 114 77 76 113 29 139z m71 0q0-117-57-215t-156-156-215-58-216 58-155 156-58 215 58 215 155 156 216 58 215-58 156-156 57-215z" horiz-adv-x="857.1" />
22
+ </font>
23
+ </defs>
24
+ </svg>
@@ -0,0 +1,6 @@
1
+ ---
2
+ # You don't need to edit this file, it's empty on purpose.
3
+ # Edit theme's home layout instead if you wanna make some changes
4
+ # See: https://jekyllrb.com/docs/themes/#overriding-theme-defaults
5
+ layout: home
6
+ ---
@@ -0,0 +1,305 @@
1
+ ---
2
+ layout: page
3
+ title: Simple Slides in Jekyll
4
+ description: "A demonstration of _Jekyll::Paginate::Content_ v1.1.0"
5
+ author: "Alexander J. N. Ibrado"
6
+ permalink: "/slides/"
7
+ paginate_content:
8
+ separator: h2
9
+ trail:
10
+ before: 2
11
+ after: 3
12
+ title: ":title - :num/:max :section"
13
+ properties:
14
+ all:
15
+ layout: slides
16
+ single:
17
+ layout: $
18
+ ---
19
+
20
+ # {{ page.title }}
21
+
22
+ **{{ page.description }}** \\
23
+ by {{ page.author }}{% if paginator.paginated %}
24
+ {:.subtitle}
25
+
26
+ *Navigation:* &#x2b05; Previous; &#x2b95; Next; &#x2b06; Single-page version
27
+ {:.navigation}
28
+ {% endif %}
29
+
30
+ ## What is Paginate::Content (JPC)?
31
+
32
+ A plugin for [Jekyll](https://jekyllrb.com) that:
33
+
34
+ - Automatically splits pages, posts, and other content at a separator like `<!--page-->`, or HTML headers (`h1`..`h6`)
35
+ - Self-adjusts internal links, and provides a multipage-aware Table Of Contents
36
+ - Keeps a single-page version and generates `<link rel>` tags for SEO
37
+ - Has several methods for navigation
38
+
39
+ JPC is available on [GitHub] and [RubyGems].
40
+
41
+ ## About this demo
42
+
43
+ This demo shows that it is possible to:
44
+ - Have different layouts for the same content;
45
+ - Have different content for slides vs the single-page view;
46
+ - And still have a *single* source document:{% raw %}
47
+ * `{% if paginator.paginated %}` .. `{% endif %}` \\
48
+ ... for content that only shows up in the slide view
49
+ * `{% unless paginator.paginated %}` .. `{% endunless %}` \\
50
+ ... for content that only shows up in the single-page view{% endraw %}
51
+
52
+ {% if paginator.paginated %}
53
+ *Press &#x2b06; at any time for the [single-page version].*
54
+ {% endif %}
55
+
56
+ ## Creating slides
57
+
58
+ 1. Make a slide template and some styles
59
+ 2. Set up `paginate_content` properties
60
+ 3. Add navigation
61
+
62
+ ## 1. Make a slide template...
63
+
64
+ ```html{% raw %}
65
+ <!DOCTYPE html>
66
+ <html>
67
+ <head>
68
+ <title>{{ page.title }}</title>
69
+ <link href="/assets/css/slides.css" rel="stylesheet">
70
+ </head>
71
+ <body>
72
+ <div class="slide-box">
73
+ <div class="content">{{ content }}</div>
74
+ </div>
75
+ </body>
76
+ </html>{% endraw %}
77
+ ```
78
+
79
+ This goes into the `_templates` folder.
80
+
81
+ ## ...and some styles
82
+
83
+ {% if paginator.paginated %}
84
+ ```css
85
+ h1 {
86
+ color: #ffcc00;
87
+ text-shadow: 2px 2px #777;
88
+ text-align: center;
89
+ font-size: 2.8em;
90
+ }
91
+
92
+ h2 { /* ... */ }
93
+
94
+ li { /* ... */ }
95
+
96
+ /* etc... */
97
+ ```
98
+
99
+ {% else %}
100
+
101
+ ```css
102
+ .slide-box {
103
+ position: absolute;
104
+ margin: auto;
105
+ top: 0;
106
+ right: 0;
107
+ bottom: 0;
108
+ left: 0;
109
+ background: #122b3b url(slidebg.png) no-repeat;
110
+ background-position: right bottom;
111
+ padding: 50px;
112
+ width: calc(100% - 100px); /* Twice padding */
113
+ height: auto;
114
+
115
+ /*border: 3px solid #000;
116
+ border-radius: 5px;
117
+ box-shadow: 3px 3px #ccc;
118
+ max-width: 80%;
119
+ min-height: 80%; */
120
+ }
121
+
122
+ h1 {
123
+ color: #ffcc00;
124
+ font-family: serif;
125
+ text-shadow: 2px 2px #777;
126
+ text-align: center;
127
+ font-size: 2.8em;
128
+ margin-top: 25vh;
129
+ margin-left: auto;
130
+ }
131
+
132
+ h2 {
133
+ color: #ffcc00;
134
+ font-family: serif;
135
+ text-shadow: 2px 2px #777;
136
+ font-size: 5vw;
137
+ margin-top: 0;
138
+ }
139
+
140
+ li {
141
+ margin-left: 20px;
142
+ padding-bottom: 5px;
143
+ font-size: 1.2em;
144
+ }
145
+
146
+ /* etc... */
147
+ ```
148
+ {% endif %}
149
+
150
+ This goes with other CSS files, e.g. in `assets/css`.
151
+
152
+ ## 2. Set up properties
153
+
154
+ ```yaml
155
+ ---
156
+ layout: page
157
+ title: My presentation
158
+ paginate_content:
159
+ separator: h2
160
+ title: ":title - :num/:max :section"
161
+ trail:
162
+ before: 2
163
+ after: 3
164
+ properties:
165
+ all:
166
+ layout: slides
167
+ single:
168
+ layout: $
169
+ ---
170
+ ```
171
+ {:style="font-size: 0.8em"}
172
+
173
+ Most of these options can be set in `_config.yml` instead of the front matter.
174
+
175
+ {% unless paginator.paginated %}
176
+ Notice that `properties:all:layout` was set to `slides`, but `single:layout` was set to `$`, [meaning](https://ibrado.org/jpc/readme/5/#special-values) the original layout (`page`).
177
+ {% endunless %}
178
+
179
+ ## 3. Add navigation
180
+
181
+ This can be via
182
+ - A [pagination trail](https://ibrado.org/jpc/readme/6/#pagination-trails)
183
+ - A [page flipper](https://ibrado.org/jpc/readme/6/#page-flipper) *and/or*
184
+ - Javascript
185
+
186
+ ## Pagination trails
187
+
188
+ ```liquid{% raw %}
189
+ {% if paginator.page_trail %}
190
+ <ul class="pager">
191
+ {% for trail in paginator.page_trail %}
192
+ <li {% if page.url == trail.path %}class="selected"{% endif %}>
193
+ <a href="{{ trail.path }}" title="{{ trail.title }}">{{ trail.num }}</a>
194
+ </li>
195
+ {% endfor %}
196
+ </ul>
197
+ {% endif %}{% endraw %}
198
+ ```
199
+ {:style="font-size: 0.8em"}
200
+
201
+ {% if paginator.paginated %} There's an enhanced pagination trail at the bottom-left of this slide. {% endif %} The appearance is dictated by the `trail` properties:
202
+
203
+ ```yaml
204
+ paginate_content:
205
+ trail:
206
+ before: 2
207
+ after: 3
208
+ ```
209
+ {:style="font-size: 0.8em"}
210
+
211
+ ## Page flipper
212
+
213
+ ```liquid{% raw %}
214
+ <div>
215
+ {% if paginator.previous_section %}
216
+ &laquo; <a href="{{ paginator.previous_path }}">{{ paginator.previous_section }}</a>
217
+ {% endif %}
218
+ {% if paginator.previous_section and paginator.next_section %} | {% endif %}
219
+ {% if paginator.next_section %}
220
+ <a href="{{ paginator.next_path }}">{{ paginator.next_section }}</a> &raquo;
221
+ {% endif %}
222
+ </div>{% endraw %}
223
+ ```
224
+ {:style="font-size: 0.8em"}
225
+
226
+ {% if paginator.paginated %}
227
+ Here's it is, live:
228
+
229
+ <div>
230
+ {% if paginator.previous_section %}
231
+ &laquo; <a href="{{ paginator.previous_path }}">{{ paginator.previous_section }}</a>
232
+ {% endif %}
233
+ {% if paginator.previous_section and paginator.next_section %} | {% endif %}
234
+ {% if paginator.next_section %}
235
+ <a href="{{ paginator.next_path }}">{{ paginator.next_section }}</a> &raquo;
236
+ {% endif %}
237
+ </div>
238
+ {% endif %}
239
+
240
+ ## Javascript
241
+
242
+ ```javascript{% raw %}
243
+ function setup_keypress() {
244
+ document.onkeydown = function(e) {
245
+ switch (e.keyCode) {
246
+ {% if paginator.has_previous %}
247
+ case 37: // left
248
+ document.location.href = "{{ paginator.previous_path }}";
249
+ break;
250
+ {% endif %}
251
+ case 38: // up
252
+ document.location.href = "{{ paginator.single_page }}#{{ paginator.section_id }}";
253
+ break;
254
+ {% if paginator.has_next %}
255
+ case 39: // right
256
+ document.location.href = "{{ paginator.next_path }}";
257
+ break;
258
+ {% endif %}
259
+ }
260
+ }
261
+ }
262
+ {% endraw %}
263
+ ```
264
+ {:style="font-size: 0.6em"}
265
+
266
+ ```html
267
+ <body onload="setup_keypress()">
268
+ ```
269
+ {:style="font-size: 0.7em"}
270
+
271
+ {% unless paginator.paginated %}
272
+ This captures keypresses and redirects to the appropriate page.
273
+ {% endunless %}
274
+
275
+ See source code for full example and code attribution.
276
+
277
+ ## Javascript gotcha
278
+
279
+ > Since we need the `paginator` and `page` properties, such Javascript files should not be included via `<script src="...">` .. `</script>`.
280
+ >
281
+ > Instead, save these in the `_includes` folder and `{% raw %}{% include filename.js %}{% endraw %}` somewhere in the template, e.g. the `<head>` section.
282
+
283
+ ## Resources
284
+
285
+ The full source code and resources for this demo are available in the gem and on GitHub.
286
+
287
+ > <https://github.com/ibrado/jekyll-paginate-content>
288
+
289
+
290
+ ## _last_
291
+
292
+ # Thank you!
293
+
294
+ Alex Ibrado \| <i class="demo-icon icon-twitter" aria-hidden="true"></i> [@ibrado](https://twitter.com/ibrado) \| <i class="demo-icon icon-github-circled" aria-hidden="true"></i> [github](https://github.com/ibrado)
295
+ {:.subtitle}
296
+
297
+ <!--page_footer-->
298
+
299
+ {% if paginator.paginated %}
300
+ [single-page version]: {{ paginator.single_page }}
301
+ {% endif %}
302
+
303
+ [GitHub]: https://github.com/ibrado/jekyll-paginate-content
304
+ [RubyGems]: https://rubygems.org/gems/jekyll-paginate-content
305
+
@@ -1,6 +1,8 @@
1
1
  require "jekyll-paginate-content/version"
2
2
 
3
3
  require "jekyll-paginate-content/generator"
4
+ require "jekyll-paginate-content/generator-cache"
5
+
4
6
  require "jekyll-paginate-content/documentpage"
5
7
  require "jekyll-paginate-content/pager"
6
8
  require "jekyll-paginate-content/paginator"
@@ -0,0 +1,28 @@
1
+ module Jekyll
2
+ module Paginate::Content
3
+
4
+ module Generator::Cache
5
+ @cache = {}
6
+
7
+ def self.items(site, item, items = nil)
8
+ return if !item.respond_to?('path')
9
+
10
+ prefix = item.is_a?(Jekyll::Page) ? site.source : ''
11
+ source = File.join(prefix, item.path)
12
+ dest = item.destination(site.dest)
13
+
14
+ if !@cache[source]
15
+ @cache[source] = items
16
+
17
+ elsif !File.exists?(dest) || (File.mtime(source) > File.mtime(dest))
18
+ @cache.delete(source)
19
+ return
20
+
21
+ else
22
+ return @cache[source]
23
+ end
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -11,11 +11,10 @@ module Jekyll
11
11
  return unless sconfig["enabled"].nil? || sconfig["enabled"]
12
12
 
13
13
  @debug = sconfig["debug"]
14
+ @force = @force.nil?
14
15
 
15
- sconfig['collection'] = sconfig['collection'].split(/,\s*/) if sconfig['collection'].is_a?(String)
16
-
17
- collections = [ sconfig['collection'], sconfig["collections"] ].flatten.compact.uniq;
18
- collections = [ "posts", "pages" ] if collections.empty?
16
+ collections = config_values(sconfig, 'collection')
17
+ debug "Checking the following: #{collections.inspect}"
19
18
 
20
19
  # Use this hash syntax to facilite merging _config.yml overrides
21
20
  properties = {
@@ -62,7 +61,9 @@ module Jekyll
62
61
  :toc_exclude => sconfig['toc_exclude'],
63
62
 
64
63
  :properties => properties,
65
- :user_props => sconfig['properties'] || {}
64
+ :user_props => sconfig['properties'] || {},
65
+
66
+ :force => @force
66
67
  }
67
68
 
68
69
  # Run through each specified collection
@@ -91,7 +92,7 @@ module Jekyll
91
92
  process = items.select { |item| item.content.include?(@config[:separator]) }
92
93
  end
93
94
  else
94
- process = items.select { |item| item.data['paginate'] }
95
+ process = items.select { |item| item.data['paginate'] || item.data['paginate_content'] }
95
96
  end
96
97
 
97
98
  process.each do |item|
@@ -107,9 +108,12 @@ module Jekyll
107
108
 
108
109
  next if paginator.items.empty?
109
110
 
110
- debug "[#{collection}] \"#{item.data['title']}\", #{paginator.items.length-1}+1 pages"
111
- total_parts += paginator.items.length-1;
112
- total_copies += 1
111
+ if !paginator.skipped && paginator.items.length > 1
112
+ debug "[#{collection}] \"#{item.data['title']}\", #{paginator.items.length-1}+1 pages"
113
+ total_parts += paginator.items.length-1;
114
+ total_copies += 1
115
+ end
116
+
113
117
  new_items << paginator.items
114
118
  old_items << item
115
119
  end
@@ -125,7 +129,7 @@ module Jekyll
125
129
  items << new_item
126
130
  end
127
131
 
128
- info "[#{collection}] Generated #{total_parts}+#{total_copies} pages"
132
+ info "[#{collection}] Generated #{total_parts}+#{total_copies} pages" if total_copies > 0
129
133
  end
130
134
  end
131
135
 
@@ -136,7 +140,7 @@ module Jekyll
136
140
 
137
141
  if total_single > 0
138
142
  s = (total_single == 1 ? '' : 's')
139
- info "#{total_single} page#{s} could not be split"
143
+ info "#{total_single} item#{s} could not be split (no separators?)"
140
144
  end
141
145
 
142
146
  runtime = "%.6f" % (Time.now - start_time).to_f
@@ -155,6 +159,29 @@ module Jekyll
155
159
  def debug(msg)
156
160
  Jekyll.logger.warn "PaginateContent:", msg if @debug
157
161
  end
162
+
163
+ # Constructs the plural for a key
164
+ def plural(config_key)
165
+ (config_key =~ /s$/) ? config_key :
166
+ (config_key.dup.sub!(/y$/, 'ies') || "#{config_key}s")
167
+ end
168
+
169
+ # Converts a string or array to a downcased, stripped array
170
+ def config_array(config, key, keepcase = nil)
171
+ [ config[key] ].flatten.compact.uniq.map { |c|
172
+ c.split(/[,;]\s*/).map { |v|
173
+ keepcase ? v.to_s.strip : v.to_s.downcase.strip
174
+ }
175
+ }.flatten.uniq
176
+ end
177
+
178
+ # Merges singular and plural config values into an array
179
+ def config_values(config, key, keepcase = nil)
180
+ singular = config_array(config, key, keepcase)
181
+ plural = config_array(config, plural(key), keepcase)
182
+ [ singular, plural ].flatten.uniq
183
+ end
184
+
158
185
  end
159
186
 
160
187