jekyll-multiple-languages 1.0.1 → 1.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 +8 -8
- data/lib/jekyll-multiple-languages.rb +2 -105
- data/lib/jekyll-multiple-languages/pager.rb +61 -0
- data/lib/jekyll-multiple-languages/pagination.rb +51 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2UwMjlhMDZhNDA4MGJlZTJiNTljOTU3NTk5YjEzNDkzZmYyYmYzZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmViOWVhYjQyOTRlZWYxNWQ0Njc4MmExZmY2MWUxZDdjZmZmNjkxMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTQ1NWJhMjAwMzkyOTk1Y2IyYTlkY2UzMmQ4NmRlYzU0YjlkMWI4MTU1MTZh
|
10
|
+
MzgwMTQ4NzE5ZTA5MWY4NDQ1Y2FmOWI5MDc4M2JjYjNjM2EwN2Y1ZmJlYjM3
|
11
|
+
MzUzNjg2MWU3ZDc4NmJlZTY5Mzg5MGM2ZTIxZDJhNGIzYjkwYmY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzNjNDg0NWEwZDgwOTRjM2Q3MDQzM2NjZGQzNTYyYTA4ZGI5NTQzNTVkODkz
|
14
|
+
OGYwYjNmOGUwNDFlMDMyMmNiMzJiZjExZWZiMDYyMGNiNzZlOGIxZGZmOTc5
|
15
|
+
OTIyNzU3ZTZlMWE5YTQyMTNkODAyN2E4NTA3NGRhOWQ2ODBkYmE=
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "jekyll-multiple-languages/pager"
|
2
|
+
require "jekyll-multiple-languages/pagination"
|
1
3
|
module Jekyll
|
2
4
|
module MultiLang
|
3
5
|
attr_accessor :language, :name_no_language, :is_default_language, :url_no_language, :dir_source
|
@@ -221,109 +223,4 @@ module Jekyll
|
|
221
223
|
|
222
224
|
end
|
223
225
|
|
224
|
-
module Generators
|
225
|
-
|
226
|
-
# index.$lang.html / index.html
|
227
|
-
#
|
228
|
-
# => /$lang/... /...
|
229
|
-
#
|
230
|
-
class Pagination < Generator
|
231
|
-
def generate(site)
|
232
|
-
if Pager.pagination_enabled?(site)
|
233
|
-
pages = find_template_pages(site)
|
234
|
-
if pages && !pages.empty?
|
235
|
-
pages.each {|page| paginate_for_language(site, page)}
|
236
|
-
else
|
237
|
-
Jekyll.logger.warn "Pagination:", "Pagination is enabled, but I couldn't find " +
|
238
|
-
"an index.html page to use as the pagination template. Skipping pagination."
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
def paginate_for_language(site, the_template_page)
|
244
|
-
lang = the_template_page.language
|
245
|
-
all_posts = site.posts_by_language[lang] || {}
|
246
|
-
all_posts = all_posts.values.sort { |a, b| b <=> a }
|
247
|
-
pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i)
|
248
|
-
(1..pages).each do |num_page|
|
249
|
-
pager = Pager.new(site, the_template_page, num_page, all_posts, pages)
|
250
|
-
if num_page > 1
|
251
|
-
newpage = Page.new(site, site.source, the_template_page.dir_source, the_template_page.name)
|
252
|
-
newpage.pager = pager
|
253
|
-
newpage.dir = Pager.calc_paginate_path(site, the_template_page, num_page)
|
254
|
-
site.pages << newpage
|
255
|
-
else
|
256
|
-
the_template_page.pager = pager
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
# Find all the cadidate pages
|
262
|
-
#
|
263
|
-
def find_template_pages(site)
|
264
|
-
site.pages.dup.select do |page|
|
265
|
-
Pager.pagination_candidate?(site.config, page)
|
266
|
-
end.sort do |one, two|
|
267
|
-
two.path.size <=> one.path.size
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
class Pager
|
274
|
-
|
275
|
-
# Static: Return the pagination path of the page
|
276
|
-
#
|
277
|
-
# site - the Jekyll::Site object
|
278
|
-
# the_template_page - template page
|
279
|
-
# num_page - the pagination page number
|
280
|
-
#
|
281
|
-
# Returns the pagination path as a string
|
282
|
-
def self.calc_paginate_path(site, the_template_page, num_page)
|
283
|
-
return nil if num_page.nil?
|
284
|
-
return the_template_page.url if num_page <= 1
|
285
|
-
format = site.config['paginate_path']
|
286
|
-
format = format.sub(':num', num_page.to_s)
|
287
|
-
path = ensure_leading_slash(format)
|
288
|
-
path
|
289
|
-
end
|
290
|
-
|
291
|
-
def self.calc_paginate_path_with_lang(site, the_template_page, num_page)
|
292
|
-
path = self.calc_paginate_path(site, the_template_page, num_page)
|
293
|
-
return nil if path.nil?
|
294
|
-
lang_prefix = '/' + the_template_page.language
|
295
|
-
if !the_template_page.is_default_language && (path && path.index(lang_prefix) != 0)
|
296
|
-
path = '/' + the_template_page.language + path
|
297
|
-
end
|
298
|
-
path
|
299
|
-
end
|
300
|
-
|
301
|
-
def self.pagination_candidate?(config, page)
|
302
|
-
page_dir = File.dirname(File.expand_path(remove_leading_slash(page.path), config['source']))
|
303
|
-
paginate_path = remove_leading_slash(config['paginate_path'])
|
304
|
-
paginate_path = File.expand_path(paginate_path, config['source'])
|
305
|
-
page.basename == 'index' &&
|
306
|
-
in_hierarchy(config['source'], page_dir, File.dirname(paginate_path))
|
307
|
-
end
|
308
|
-
|
309
|
-
def initialize(site, the_template_page, page, all_posts, num_pages = nil)
|
310
|
-
@page = page
|
311
|
-
@per_page = site.config['paginate'].to_i
|
312
|
-
@total_pages = num_pages || Pager.calculate_pages(all_posts, @per_page)
|
313
|
-
|
314
|
-
if @page > @total_pages
|
315
|
-
raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}"
|
316
|
-
end
|
317
|
-
|
318
|
-
init = (@page - 1) * @per_page
|
319
|
-
offset = (init + @per_page - 1) >= all_posts.size ? all_posts.size : (init + @per_page - 1)
|
320
|
-
|
321
|
-
@total_posts = all_posts.size
|
322
|
-
@posts = all_posts[init..offset]
|
323
|
-
@previous_page = @page != 1 ? @page - 1 : nil
|
324
|
-
@previous_page_path = Pager.calc_paginate_path_with_lang(site, the_template_page, @previous_page)
|
325
|
-
@next_page = @page != @total_pages ? @page + 1 : nil
|
326
|
-
@next_page_path = Pager.calc_paginate_path_with_lang(site, the_template_page, @next_page)
|
327
|
-
end
|
328
|
-
end
|
329
226
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Paginate
|
3
|
+
class Pager
|
4
|
+
|
5
|
+
# Static: Return the pagination path of the page
|
6
|
+
#
|
7
|
+
# site - the Jekyll::Site object
|
8
|
+
# the_template_page - template page
|
9
|
+
# num_page - the pagination page number
|
10
|
+
#
|
11
|
+
# Returns the pagination path as a string
|
12
|
+
def self.calc_paginate_path(site, the_template_page, num_page)
|
13
|
+
return nil if num_page.nil?
|
14
|
+
return the_template_page.url if num_page <= 1
|
15
|
+
format = site.config['paginate_path']
|
16
|
+
format = format.sub(':num', num_page.to_s)
|
17
|
+
path = ensure_leading_slash(format)
|
18
|
+
path
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.calc_paginate_path_with_lang(site, the_template_page, num_page)
|
22
|
+
path = self.calc_paginate_path(site, the_template_page, num_page)
|
23
|
+
return nil if path.nil?
|
24
|
+
lang_prefix = '/' + the_template_page.language
|
25
|
+
if !the_template_page.is_default_language && (path && path.index(lang_prefix) != 0)
|
26
|
+
path = '/' + the_template_page.language + path
|
27
|
+
end
|
28
|
+
path
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.pagination_candidate?(config, page)
|
32
|
+
page_dir = File.dirname(File.expand_path(remove_leading_slash(page.path), config['source']))
|
33
|
+
paginate_path = remove_leading_slash(config['paginate_path'])
|
34
|
+
paginate_path = File.expand_path(paginate_path, config['source'])
|
35
|
+
page.basename == 'index' &&
|
36
|
+
in_hierarchy(config['source'], page_dir, File.dirname(paginate_path))
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize(site, the_template_page, page, all_posts, num_pages = nil)
|
40
|
+
@page = page
|
41
|
+
@per_page = site.config['paginate'].to_i
|
42
|
+
@total_pages = num_pages || Pager.calculate_pages(all_posts, @per_page)
|
43
|
+
|
44
|
+
if @page > @total_pages
|
45
|
+
raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}"
|
46
|
+
end
|
47
|
+
|
48
|
+
init = (@page - 1) * @per_page
|
49
|
+
offset = (init + @per_page - 1) >= all_posts.size ? all_posts.size : (init + @per_page - 1)
|
50
|
+
|
51
|
+
@total_posts = all_posts.size
|
52
|
+
@posts = all_posts[init..offset]
|
53
|
+
@previous_page = @page != 1 ? @page - 1 : nil
|
54
|
+
@previous_page_path = Pager.calc_paginate_path_with_lang(site, the_template_page, @previous_page)
|
55
|
+
@next_page = @page != @total_pages ? @page + 1 : nil
|
56
|
+
@next_page_path = Pager.calc_paginate_path_with_lang(site, the_template_page, @next_page)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Paginate
|
3
|
+
|
4
|
+
# index.$lang.html / index.html
|
5
|
+
#
|
6
|
+
# => /$lang/... /...
|
7
|
+
#
|
8
|
+
class Pagination < Generator
|
9
|
+
def generate(site)
|
10
|
+
if Pager.pagination_enabled?(site)
|
11
|
+
pages = find_template_pages(site)
|
12
|
+
if pages && !pages.empty?
|
13
|
+
pages.each {|page| paginate_for_language(site, page)}
|
14
|
+
else
|
15
|
+
Jekyll.logger.warn "Pagination:", "Pagination is enabled, but I couldn't find " +
|
16
|
+
"an index.html page to use as the pagination template. Skipping pagination."
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def paginate_for_language(site, the_template_page)
|
22
|
+
lang = the_template_page.language
|
23
|
+
all_posts = site.posts_by_language[lang] || {}
|
24
|
+
all_posts = all_posts.values.sort { |a, b| b <=> a }
|
25
|
+
pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i)
|
26
|
+
(1..pages).each do |num_page|
|
27
|
+
pager = Pager.new(site, the_template_page, num_page, all_posts, pages)
|
28
|
+
if num_page > 1
|
29
|
+
newpage = Page.new(site, site.source, the_template_page.dir_source, the_template_page.name)
|
30
|
+
newpage.pager = pager
|
31
|
+
newpage.dir = Pager.calc_paginate_path(site, the_template_page, num_page)
|
32
|
+
site.pages << newpage
|
33
|
+
else
|
34
|
+
the_template_page.pager = pager
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Find all the cadidate pages
|
40
|
+
#
|
41
|
+
def find_template_pages(site)
|
42
|
+
site.pages.dup.select do |page|
|
43
|
+
Pager.pagination_candidate?(site.config, page)
|
44
|
+
end.sort do |one, two|
|
45
|
+
two.path.size <=> one.path.size
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-multiple-languages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Srain
|
@@ -17,6 +17,8 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/jekyll-multiple-languages.rb
|
20
|
+
- lib/jekyll-multiple-languages/pager.rb
|
21
|
+
- lib/jekyll-multiple-languages/pagination.rb
|
20
22
|
homepage: http://jekyll-langs.liaohuqiu.net/
|
21
23
|
licenses:
|
22
24
|
- MIT
|