jekyll-locales 0.1.5 → 0.1.11

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: 5e1e9d8ecdf4cc772d076592e186830a038f6efde890bf3df4fc0fba88ccf840
4
- data.tar.gz: 7c0f9126b109040cbf0629209103651ee34974dd72f1bd47b9eac995b666c567
3
+ metadata.gz: 8064e214d9d871fab3a7d775064068f01acbf3194d8776601be47b245452b783
4
+ data.tar.gz: e00d19218061374a29e73baea210ad871535ff40c5bf3e775b5d1fa57ed04f5c
5
5
  SHA512:
6
- metadata.gz: db58ab601603d7fb0571e7932f092b62df6949d5956278f35554e72732351f6eeb9a03e80083debb5651faad30f39e8933e43f017ae19fae71196a539b06219b
7
- data.tar.gz: 265e7024461aa7001bece672057fcb899947b11c07c7a43102b1955fa55e2ddb375405ff01b6e07a98e93bbf445b54cddb3ffc51afad019e98a07e39aca8fffc
6
+ metadata.gz: 5b14589c075687b8f9c498b9b670339b37901690b4b51aebcd6b994d68d4b53d12ed47f42579df9abf8afd46a6585d7d3888eff420b22b79c742759b1325934e
7
+ data.tar.gz: 59d3a80ac8136b4b5e15343b4f25598c1468cde8797b6efae816f1303995d92c4559b9d26e73a460cea269965017e34dcf664d67eb2765b26534d385c043e612
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ Gemfile.lock
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.11
4
+
5
+ - Add alternate URLs to link between languages when using
6
+ jekyll-linked-posts
7
+
8
+ ## 0.1.10
9
+
10
+ - Prevent cleanup from removing other languages
11
+
12
+ ## 0.1.9
13
+
14
+ - Loading locales as collection makes Jekyll render them even when
15
+ they're not part of output. This version prevents that. A site with
16
+ three languages was taking 160 seconds before and 60 after patching!
17
+
18
+ ## 0.1.8
19
+
20
+ - Load other locales as collections to make them available in templates.
21
+ Compatible with
22
+ [jekyll-linked-posts](https://rubygems.org/gems/jekyll-linked-posts).
23
+
3
24
  ## 0.1.0
4
25
 
5
26
  - 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
 
@@ -61,6 +64,12 @@ locales:
61
64
 
62
65
  Then you can access them by using `page.locales` in your layout.
63
66
 
67
+ **Tip:** You can use
68
+ [jekyll-linked-posts](https://rubygems.org/gems/jekyll-linked-posts) to
69
+ make this process more resilient. It uses IDs instead of URLs and it
70
+ also allows you to access other data. From v0.1.11 it will also
71
+ generate alternate URLs so search engines can link between translations.
72
+
64
73
  ### Pages
65
74
 
66
75
  You can translate the front matter by adding locale-specific variables
@@ -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,7 @@
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/post_render'
8
+ 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
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ Jekyll::Hooks.register :site, :post_render do |site|
4
+ unless site.config['plugins'].include? 'jekyll-linked-posts'
5
+ Jekyll.logger.warn 'Enable jekyll-linked-posts to generate metadata about alternate pages'
6
+ next
7
+ end
8
+
9
+ # URLs can be relative but Google asks for fully qualified URLs
10
+ # @see {https://support.google.com/webmasters/answer/189077?hl=en}
11
+ url = site.config['url']&.sub(%r{/\z}, '')
12
+
13
+ unless url
14
+ Jekyll.logger.warn 'Provide a `url` value in configuration to create fully qualified URLs'
15
+ next
16
+ end
17
+
18
+ site.each_site_file do |doc|
19
+ next unless doc.is_a? Jekyll::Document
20
+ next if doc.output.nil?
21
+ next unless doc&.data&.dig 'locales'
22
+
23
+ alternate = doc.data['locales'].map do |translation|
24
+ locale = translation.collection.label
25
+ # TODO: Every doc should know how to build their own URL
26
+ doc_url = [url, locale, translation.url].join('/')
27
+
28
+ %(<link rel="alternate" hreflang="#{locale}" href="#{doc_url}" />)
29
+ end
30
+
31
+ next if alternate.empty?
32
+
33
+ doc.output.sub! '<head>', '<head>' + alternate.join
34
+ end
35
+ end
@@ -28,21 +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
- if locales?
34
- copy_redirector
35
- default_delete
36
- default_symlink
37
- else
38
- self_symlink
39
- end
37
+ # XXX: Default is expected by Sutty so we always create it
38
+ default_delete
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
40
61
  end
41
62
 
42
63
  private
43
64
 
44
- def locales?
45
- 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
46
78
  end
47
79
 
48
80
  def locale_config
@@ -50,19 +82,32 @@ module Jekyll
50
82
  config['locale'] = config['lang'] = locale
51
83
  config['default_locale'] = default_locale
52
84
 
85
+ # Don't touch the config unless there's more than one locale or we
86
+ # aren't using a redirector
53
87
  return unless locales?
54
88
 
89
+ other_locales_as_collections
90
+ return if default_locale? && !redirect?
91
+
55
92
  @dest = config['destination'] = locale_destination
56
93
  config['baseurl'] = locale_baseurl
57
94
  end
58
95
 
59
- # Get locales from configuration
60
- def locales
61
- @locales ||= config.fetch('locales', [])
62
- end
63
-
64
- def default_locale
65
- 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
66
111
  end
67
112
 
68
113
  # Cache original destination
@@ -92,6 +137,10 @@ module Jekyll
92
137
  FileUtils.ln_s("_#{locale}", '_posts')
93
138
  end
94
139
 
140
+ def redirect?
141
+ config.fetch('redirect', false)
142
+ end
143
+
95
144
  # TODO: Make configurable
96
145
  def redirector
97
146
  @redirector ||= File.join(locale_destination, 'redirector.html')
@@ -124,6 +173,7 @@ module Jekyll
124
173
  end
125
174
 
126
175
  def self_symlink
176
+ FileUtils.rm_f(locale_destination)
127
177
  FileUtils.ln_s('.', locale_destination)
128
178
  end
129
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.5'
5
+ VERSION = '0.1.11'
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.5
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-27 00:00:00.000000000 Z
11
+ date: 2020-07-26 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,11 @@ 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
+ - lib/jekyll/locales/hooks/post_render.rb
94
95
  - lib/jekyll/locales/site.rb
96
+ - lib/jekyll/locales/site_drop.rb
95
97
  - lib/jekyll/locales/version.rb
96
98
  homepage: https://0xacab.org/sutty/jekyll/jekyll-locales
97
99
  licenses:
@@ -100,7 +102,7 @@ metadata:
100
102
  homepage_uri: https://0xacab.org/sutty/jekyll/jekyll-locales
101
103
  source_code_uri: https://0xacab.org/sutty/jekyll/jekyll-locales
102
104
  changelog_uri: https://0xacab.org/sutty/jekyll/jekyll-locales/blob/master/CHANGELOG.md
103
- post_install_message:
105
+ post_install_message:
104
106
  rdoc_options: []
105
107
  require_paths:
106
108
  - lib
@@ -115,9 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
117
  - !ruby/object:Gem::Version
116
118
  version: '0'
117
119
  requirements: []
118
- rubyforge_project:
119
- rubygems_version: 2.7.6.2
120
- signing_key:
120
+ rubygems_version: 3.0.3
121
+ signing_key:
121
122
  specification_version: 4
122
123
  summary: Jekyll plugin for localized sites
123
124
  test_files: []
@@ -1,38 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- jekyll-locales (0.1.5)
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