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.
@@ -10,7 +10,7 @@ module Jekyll
10
10
  :page_trail, :pages, :paginated, :previous_is_first,
11
11
  :prev_is_first, :previous_page, :prev_page, :previous_page_path,
12
12
  :previous_path, :prev_path, :prev_section, :previous_section,
13
- :section, :seo, :single_page, :toc, :total_pages, :view_all
13
+ :section, :section_id, :seo, :single_page, :toc, :total_pages, :view_all
14
14
 
15
15
  def initialize(data)
16
16
  data.each do |k,v|
@@ -45,6 +45,7 @@ module Jekyll
45
45
  'seo' => seo,
46
46
  'single_page' => single_page,
47
47
  'section' => section,
48
+ 'section_id' => section_id,
48
49
  'toc' => toc,
49
50
  'next_section' => next_section,
50
51
  'previous_section' => previous_section,
@@ -10,23 +10,34 @@ module Jekyll
10
10
  @items = []
11
11
  @skipped = false
12
12
 
13
- source_prefix = item.is_a?(Jekyll::Page) ? site.source : ''
13
+ is_page = item.is_a?(Jekyll::Page)
14
+
15
+ source_prefix = is_page ? site.source : ''
14
16
  source = File.join(source_prefix, item.path)
15
17
  html = item.destination('')
16
18
 
17
- final_config = {}.merge(config)
19
+ final_config = config.dup
18
20
  if item.data.has_key?('paginate_content')
21
+ fm_config = {}
19
22
  item.data['paginate_content'].each do |k,v|
20
23
  s = k.downcase.strip.to_sym
21
- final_config[s] = v
24
+ fm_config[s] = v
22
25
  end
26
+
27
+ Jekyll::Utils.deep_merge_hashes!(final_config, fm_config)
23
28
  end
29
+
24
30
  @config = final_config
25
31
 
26
- if @config[:force] || (!File.exist?(html) || (File.mtime(html) < File.mtime(source)))
27
- self.split(item)
28
- else
32
+ if !@config[:force] && (cached_items = Generator::Cache.items(site, item))
33
+ @items = cached_items
29
34
  @skipped = true
35
+
36
+ else
37
+ split_pages = self.split(item)
38
+
39
+ # Store for later retrieval during regeneration
40
+ Generator::Cache.items(site, item, split_pages)
30
41
  end
31
42
  end
32
43
 
@@ -36,6 +47,7 @@ module Jekyll
36
47
 
37
48
  def split(item)
38
49
  sep = @config[:separator].downcase.strip
50
+
39
51
  # Update the header IDs the original document
40
52
  content = item.content
41
53
 
@@ -63,7 +75,12 @@ module Jekyll
63
75
  content.scan(/(^|\r?\n)((#+)\s*([^\r\n#]+)#*\r?\n|([^\r\n]+)\r?\n(=+|\-{4,})\s*\r?\n|<h([1-6])[^>]*>([^\r\n<]+)(\s*<\/h\7>))/mi).each do |m|
64
76
  header = m[3] || m[4] || m[7]
65
77
 
78
+ # Parse any Liquid page variables here so the ids also get the resulting text
79
+ header_template = Liquid::Template.parse(header)
80
+ header = header_template.render({ "page" => item.data })
81
+
66
82
  next if @config[:toc_exclude] && @config[:toc_exclude].include?(header)
83
+ next if header == '_last_'
67
84
 
68
85
  markup = m[1].strip
69
86
 
@@ -256,7 +273,7 @@ module Jekyll
256
273
  page_data = item.data
257
274
  end
258
275
 
259
- paginator.merge!(page_data)
276
+ Jekyll::Utils.deep_merge_hashes!(paginator, page_data)
260
277
  new_part = Page.new(item, @site, dirname, filename)
261
278
  else
262
279
  new_part = Document.new(item, @site, @collection)
@@ -284,6 +301,11 @@ module Jekyll
284
301
  end
285
302
 
286
303
  paginator['section'] = section
304
+ if last && section == '_last_'
305
+ paginator['section_id'] = section
306
+ else
307
+ paginator['section_id'] = section.downcase.gsub(/[[:punct:]]/, '').gsub(/\s+/, '-')
308
+ end
287
309
 
288
310
  paginator['paginated'] = true
289
311
  paginator['page_num'] = num
@@ -340,9 +362,8 @@ module Jekyll
340
362
  _set_properties(item, new_part, 'part', user_props) if !first && !last
341
363
 
342
364
  # Don't allow these to be overriden,
343
- # i.e. set/reset layout, date, title, permalink
365
+ # i.e. set/reset date, title, permalink
344
366
 
345
- new_part.data['layout'] = item.data['layout']
346
367
  new_part.data['date'] = item.data['date']
347
368
  new_part.data['permalink'] = plink
348
369
 
@@ -356,10 +377,13 @@ module Jekyll
356
377
  'id' => id
357
378
  }
358
379
 
380
+ if last && (section == "_last_")
381
+ page.sub!(/^\s*#+\s+_last_/, '')
382
+ end
383
+
359
384
  new_part.content = header + page + footer
360
385
 
361
386
  new_items << new_part
362
-
363
387
  num += 1
364
388
  end
365
389
 
@@ -425,6 +449,7 @@ module Jekyll
425
449
  single.data['layout'] = item.data['layout']
426
450
  single.data['date'] = item.data['date']
427
451
  single.data['title'] = item.data['title']
452
+ single.data['regenerate'] = false;
428
453
 
429
454
  # Just some limited data for the single page
430
455
  seo = @config[:seo_canonical] ?
@@ -445,6 +470,8 @@ module Jekyll
445
470
  single.pager = Pager.new(single_paginator)
446
471
  single.content = item.content
447
472
 
473
+ single.content.sub!(/^\s*#+\s+_last_/, '<a id="_last_"></a>')
474
+
448
475
  new_items << single
449
476
  end
450
477
 
@@ -517,11 +544,10 @@ module Jekyll
517
544
  end
518
545
 
519
546
  def _set_properties(original, item, stage, user_props = nil)
520
- stage_props = {}
521
- stage_props.merge!(@config[:properties][stage])
547
+ stage_props = (@config[:properties][stage] || {}).dup
522
548
 
523
549
  if user_props && user_props.has_key?(stage)
524
- stage_props.merge!(user_props[stage])
550
+ Jekyll::Utils.deep_merge_hashes!(stage_props, user_props[stage])
525
551
  end
526
552
 
527
553
  return if stage_props.empty?
@@ -541,12 +567,7 @@ module Jekyll
541
567
  end
542
568
  end
543
569
 
544
- if item.respond_to?('merge_data')
545
- item.merge_data!(stage_props)
546
- else
547
- item.data.merge!(stage_props)
548
- end
549
-
570
+ Jekyll::Utils.deep_merge_hashes!(item.data, stage_props)
550
571
  end
551
572
 
552
573
  def _adjust_links(new_items, content, a_locations, num)
@@ -569,6 +590,7 @@ module Jekyll
569
590
  end
570
591
 
571
592
  end
593
+
572
594
  end
573
595
 
574
596
  end
@@ -1,7 +1,7 @@
1
1
  module Jekyll
2
2
  module Paginate
3
3
  module Content
4
- VERSION = "1.0.4"
4
+ VERSION = "1.1.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-paginate-content
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Ibrado
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-24 00:00:00.000000000 Z
11
+ date: 2018-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -59,9 +59,34 @@ files:
59
59
  - Rakefile
60
60
  - bin/console
61
61
  - bin/setup
62
+ - example/.gitignore
63
+ - example/404.html
64
+ - example/Gemfile
65
+ - example/_config.yml
66
+ - example/_demos/jpc-3page-auto.md
67
+ - example/_includes/header.html
68
+ - example/_includes/slides.js
69
+ - example/_layouts/default.html
70
+ - example/_layouts/home.html
71
+ - example/_layouts/slides.html
72
+ - example/_posts/2018-01-27-manual.md
73
+ - example/_posts/2018-01-27-welcome-to-jekyll.markdown
74
+ - example/about.md
75
+ - example/assets/css/fontello.css
76
+ - example/assets/css/slides.css
77
+ - example/assets/css/syntax.scss
78
+ - example/assets/font/fontello.eot
79
+ - example/assets/font/fontello.svg
80
+ - example/assets/font/fontello.ttf
81
+ - example/assets/font/fontello.woff
82
+ - example/assets/font/fontello.woff2
83
+ - example/assets/images/slidebg.png
84
+ - example/index.md
85
+ - example/slides.md
62
86
  - jekyll-paginate-content.gemspec
63
87
  - lib/jekyll-paginate-content.rb
64
88
  - lib/jekyll-paginate-content/documentpage.rb
89
+ - lib/jekyll-paginate-content/generator-cache.rb
65
90
  - lib/jekyll-paginate-content/generator.rb
66
91
  - lib/jekyll-paginate-content/pager.rb
67
92
  - lib/jekyll-paginate-content/paginator.rb