jekyll-locales 0.1.4 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f624b6ce22236cefd09c7a87d223595565a4d54e16eb99af05f8a3e870a514f8
4
- data.tar.gz: 740a7f2e5efe294d6be4d3ae2b5bd01aaa2171d4130497ac46adcde76866095e
3
+ metadata.gz: 6b8cd80411bc24509a21502d5972966dd9cb990ec1716aacc19724855e8c957b
4
+ data.tar.gz: 557fdfd91a846aa99f180076b186ddf21fad118cc0b01de438e66e0a7303c2bd
5
5
  SHA512:
6
- metadata.gz: 3eca8c0b1d7ab98b58fd46a5f4445f66af25a0390a90d9501325a0b85d6c60244258b9e53f8117681fa97b30ff5acc980242ee00a0c3ab3de096deb1ad593dab
7
- data.tar.gz: 27f25f04d670cba30d79f7706c63b7fe9500affe6fd37098dc2c146bb260726c880891503820e8ddbb4e3cee3a8659136aba3e7af13cf3f06a10b1efdfd0df39
6
+ metadata.gz: 2d3826a63a1f0d581e4c9a0e516680fe012f99c88d6ad62a761e61140a3a25f1c71ca9ea08853155c7a817d3919f32715c0b20dd9d87c1383e052984c55832a5
7
+ data.tar.gz: 5471c147d18a8bd76445857b4251902c454d09f123e4e64e177fd7df02c0d4b1789b465c465e590ca8f590f9539af9fc35602623579137d8b8acabb161cb2b5f
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ Gemfile.lock
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.9
4
+
5
+ - Loading locales as collection makes Jekyll render them even when
6
+ they're not part of output. This version prevents that. A site with
7
+ three languages was taking 160 seconds before and 60 after patching!
8
+
9
+ ## 0.1.8
10
+
11
+ - Load other locales as collections to make them available in templates.
12
+ Compatible with
13
+ [jekyll-linked-posts](https://rubygems.org/gems/jekyll-linked-posts).
14
+
3
15
  ## 0.1.0
4
16
 
5
17
  - Localized Jekyll sites
data/README.md CHANGED
@@ -33,10 +33,13 @@ locales:
33
33
  - en
34
34
  - ahr
35
35
  - brasileiro
36
+ redirect: true
36
37
  ```
37
38
 
38
- **The first locale is going to be your default locale**. It doesn't do
39
- much, but still have it in mind.
39
+ **The first locale is going to be your default locale**. If you use
40
+ a redirector.html, it will be the locale it will redirector to. If you
41
+ don't use a redirector, the default locale will be at the root of the
42
+ site.
40
43
 
41
44
  ## Posts
42
45
 
@@ -35,6 +35,6 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_development_dependency 'bundler', '~> 2.0'
37
37
  spec.add_development_dependency 'minitest', '~> 5.0'
38
- spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'rake', '~> 12.0'
39
39
  spec.add_development_dependency 'rubocop', '~> 0.74'
40
40
  end
@@ -2,4 +2,6 @@
2
2
 
3
3
  require 'jekyll/site'
4
4
  require 'jekyll/locales/site'
5
+ require 'jekyll/locales/site_drop'
5
6
  require 'jekyll/locales/hooks/page_post_init'
7
+ require 'jekyll/locales/hooks/cleanup'
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # We keep a global variable with the site in it because we can't access
4
+ # it from the cleanup hook.
5
+ $site = nil
6
+
7
+ # Only run on the default locale since it's going to be in the root
8
+ # destination
9
+ Jekyll::Hooks.register :site, :post_render do |site|
10
+ next unless site.locales?
11
+ next unless site.default_locale?
12
+
13
+ $site = site
14
+ end
15
+
16
+ # Keep files in other locales since they're not generated by the default
17
+ # locale.
18
+ Jekyll::Hooks.register :clean, :on_obsolete do |obsolete|
19
+ next if $site.nil?
20
+
21
+ $site.locales.each do |locale|
22
+ next if locale == $site.locale
23
+
24
+ obsolete.delete_if do |x|
25
+ x.sub($site.dest + '/', '').start_with? locale
26
+ end
27
+ end
28
+ end
@@ -28,19 +28,53 @@ module Jekyll
28
28
 
29
29
  symlink
30
30
  process_single
31
+ # The default locale is placed at the root of the
32
+ # site and everything else is under a subdirectory, but we symlink
33
+ # root to default_locale for compatibility
34
+ self_symlink if default_locale? && !redirect?
31
35
  end
32
36
 
33
- return unless locales?
34
-
35
- copy_redirector
37
+ # XXX: Default is expected by Sutty so we always create it
36
38
  default_delete
37
39
  default_symlink
40
+
41
+ # If we enable the redirector, the root of the site will consist
42
+ # of an index.html that allows visitors to select their locale.
43
+ copy_redirector if redirect?
44
+ end
45
+
46
+ def locales?
47
+ locales.length > 1
48
+ end
49
+
50
+ # Get locales from configuration
51
+ def locales
52
+ @locales ||= config.fetch('locales', [])
53
+ end
54
+
55
+ def default_locale
56
+ @default_locale ||= locales.first
57
+ end
58
+
59
+ def default_locale?
60
+ default_locale == locale
38
61
  end
39
62
 
40
63
  private
41
64
 
42
- def locales?
43
- locales.size > 1
65
+ # Redefine #render_docs so it doesn't render the locale collections
66
+ # for each independent locale.
67
+ #
68
+ # XXX: Jekyll should render on demand instead of rendering and
69
+ # writing separately.
70
+ def render_docs(payload)
71
+ collections.each do |name, collection|
72
+ next if locales.include? name
73
+
74
+ collection.docs.each do |document|
75
+ render_regenerated(document, payload)
76
+ end
77
+ end
44
78
  end
45
79
 
46
80
  def locale_config
@@ -48,19 +82,32 @@ module Jekyll
48
82
  config['locale'] = config['lang'] = locale
49
83
  config['default_locale'] = default_locale
50
84
 
85
+ # Don't touch the config unless there's more than one locale or we
86
+ # aren't using a redirector
51
87
  return unless locales?
52
88
 
89
+ other_locales_as_collections
90
+ return if default_locale? && !redirect?
91
+
53
92
  @dest = config['destination'] = locale_destination
54
93
  config['baseurl'] = locale_baseurl
55
94
  end
56
95
 
57
- # Get locales from configuration
58
- def locales
59
- @locales ||= config.fetch('locales', [])
60
- end
61
-
62
- def default_locale
63
- locales.first
96
+ # Read the other locales as collections but don't render them, only
97
+ # make them available to templates.
98
+ #
99
+ # The URL will be the permalink with the language prepended.
100
+ #
101
+ # {https://rubygems.org/gems/jekyll-linked-posts}
102
+ def other_locales_as_collections
103
+ locales.each do |l|
104
+ next if l == locale
105
+
106
+ config['collections'][l] = {
107
+ 'output' => false,
108
+ 'permalink' => [nil, l, config['permalink']].join('/')
109
+ }
110
+ end
64
111
  end
65
112
 
66
113
  # Cache original destination
@@ -90,6 +137,10 @@ module Jekyll
90
137
  FileUtils.ln_s("_#{locale}", '_posts')
91
138
  end
92
139
 
140
+ def redirect?
141
+ config.fetch('redirect', false)
142
+ end
143
+
93
144
  # TODO: Make configurable
94
145
  def redirector
95
146
  @redirector ||= File.join(locale_destination, 'redirector.html')
@@ -120,5 +171,9 @@ module Jekyll
120
171
  def default_symlink
121
172
  FileUtils.ln_s(default_locale, default_destination)
122
173
  end
174
+
175
+ def self_symlink
176
+ FileUtils.ln_s('.', locale_destination)
177
+ end
123
178
  end
124
179
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/drops/site_drop'
4
+
5
+ module Jekyll
6
+ module Drops
7
+ # Make i18n available to Liquid as site.i18n
8
+ class SiteDrop
9
+ def i18n
10
+ @i18n ||= @obj.data[@obj.config['lang']]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Locales
5
- VERSION = '0.1.4'
5
+ VERSION = '0.1.10'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-locales
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-27 00:00:00.000000000 Z
11
+ date: 2020-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '12.0'
48
48
  type: :development
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: '10.0'
54
+ version: '12.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,6 @@ files:
80
80
  - ".travis.yml"
81
81
  - CHANGELOG.md
82
82
  - Gemfile
83
- - Gemfile.lock
84
83
  - LICENSE
85
84
  - README.md
86
85
  - Rakefile
@@ -90,8 +89,10 @@ files:
90
89
  - jekyll-locales.gemspec
91
90
  - lib/jekyll-locales.rb
92
91
  - lib/jekyll/locales.rb
92
+ - lib/jekyll/locales/hooks/cleanup.rb
93
93
  - lib/jekyll/locales/hooks/page_post_init.rb
94
94
  - lib/jekyll/locales/site.rb
95
+ - lib/jekyll/locales/site_drop.rb
95
96
  - lib/jekyll/locales/version.rb
96
97
  homepage: https://0xacab.org/sutty/jekyll/jekyll-locales
97
98
  licenses:
@@ -115,8 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  - !ruby/object:Gem::Version
116
117
  version: '0'
117
118
  requirements: []
118
- rubyforge_project:
119
- rubygems_version: 2.7.6.2
119
+ rubygems_version: 3.0.3
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: Jekyll plugin for localized sites
@@ -1,38 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- jekyll-locales (0.1.4)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- ast (2.4.0)
10
- jaro_winkler (1.5.3)
11
- minitest (5.11.3)
12
- parallel (1.17.0)
13
- parser (2.6.4.1)
14
- ast (~> 2.4.0)
15
- rainbow (3.0.0)
16
- rake (10.5.0)
17
- rubocop (0.74.0)
18
- jaro_winkler (~> 1.5.1)
19
- parallel (~> 1.10)
20
- parser (>= 2.6)
21
- rainbow (>= 2.2.2, < 4.0)
22
- ruby-progressbar (~> 1.7)
23
- unicode-display_width (>= 1.4.0, < 1.7)
24
- ruby-progressbar (1.10.1)
25
- unicode-display_width (1.6.0)
26
-
27
- PLATFORMS
28
- ruby
29
-
30
- DEPENDENCIES
31
- bundler (~> 2.0)
32
- jekyll-locales!
33
- minitest (~> 5.0)
34
- rake (~> 10.0)
35
- rubocop (~> 0.74)
36
-
37
- BUNDLED WITH
38
- 2.0.2